diff options
author | Geir Storli <geirst@oath.com> | 2017-09-05 13:09:24 +0000 |
---|---|---|
committer | Geir Storli <geirst@oath.com> | 2017-09-06 15:45:25 +0000 |
commit | e65e07a491c8ac14d2a951158b9d446339b1ad49 (patch) | |
tree | 44cb913185cd24db64ff1e724c0a7cfce7df2079 /searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h | |
parent | b24b63018c3862a393a6e69530bafad855ae5fdd (diff) |
Implement simple bitvector search cache for use in imported attribute vector.
Diffstat (limited to 'searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h')
-rw-r--r-- | searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h b/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h new file mode 100644 index 00000000000..4b6589459ca --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h @@ -0,0 +1,42 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <vespa/vespalib/stllike/hash_map.h> +#include <vespa/vespalib/stllike/string.h> +#include <memory> +#include <mutex> + +namespace search { + +class BitVector; + +namespace attribute { + +/** + * Class that caches posting lists (as bit vectors) for a set of search terms. + * + * Lifetime of cached bit vectors is controlled by calling clear() at regular intervals. + */ +class BitVectorSearchCache { +public: + using BitVectorSP = std::shared_ptr<BitVector>; + +private: + using LockGuard = std::lock_guard<std::mutex>; + using Cache = vespalib::hash_map<vespalib::string, BitVectorSP>; + + mutable std::mutex _mutex; + Cache _cache; + +public: + BitVectorSearchCache(); + ~BitVectorSearchCache(); + void insert(const vespalib::string &term, BitVectorSP bitVector); + BitVectorSP find(const vespalib::string &term) const; + size_t size() const; + void clear(); +}; + +} +} |