diff options
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/vespa/vespalib/datastore/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/datastore/unique_store.hpp | 16 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h | 17 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp (renamed from vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.cpp) | 67 |
4 files changed, 63 insertions, 38 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt b/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt index 6f647a78a39..b8c9dae7174 100644 --- a/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt +++ b/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt @@ -7,7 +7,6 @@ vespa_add_library(vespalib_vespalib_datastore OBJECT datastore.cpp datastorebase.cpp entryref.cpp - unique_store_dictionary.cpp unique_store_string_allocator.cpp DEPENDS ) diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp index e149f470bdf..ae7f82a6e52 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp +++ b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp @@ -5,20 +5,32 @@ #include "unique_store.h" #include "unique_store_dictionary.h" #include "datastore.hpp" -#include <vespa/vespalib/util/bufferwriter.h> #include "unique_store_allocator.hpp" #include "unique_store_builder.hpp" +#include "unique_store_dictionary.hpp" #include "unique_store_saver.hpp" +#include <vespa/vespalib/util/bufferwriter.h> #include <atomic> #include <algorithm> namespace search::datastore { +namespace uniquestore { + +using DefaultDictionaryTraits = btree::BTreeTraits<32, 32, 7, true>; +using DefaultDictionary = btree::BTree<EntryRef, btree::BTreeNoLeafData, + btree::NoAggregated, + EntryComparatorWrapper, + DefaultDictionaryTraits>; +using DefaultUniqueStoreDictionary = UniqueStoreDictionary<DefaultDictionary>; + +} + template <typename EntryT, typename RefT, typename Compare, typename Allocator> UniqueStore<EntryT, RefT, Compare, Allocator>::UniqueStore() : _allocator(), _store(_allocator.get_data_store()), - _dict(std::make_unique<UniqueStoreDictionary>()) + _dict(std::make_unique<uniquestore::DefaultUniqueStoreDictionary>()) { } diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h index a870d759ce3..4191b5d26a6 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h +++ b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h @@ -9,20 +9,17 @@ namespace search::datastore { class EntryComparatorWrapper; -/* +/** * A dictionary for unique store. Mostly accessed via base class. */ +template <typename DictionaryT> class UniqueStoreDictionary : public UniqueStoreDictionaryBase { -public: - using DictionaryTraits = btree::BTreeTraits<32, 32, 7, true>; - using Dictionary = btree::BTree<EntryRef, btree::BTreeNoLeafData, - btree::NoAggregated, - EntryComparatorWrapper, - DictionaryTraits>; - -private: - Dictionary _dict; +protected: + using DictionaryType = DictionaryT; + using DataType = typename DictionaryType::DataType; + + DictionaryType _dict; public: UniqueStoreDictionary(); diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.cpp b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp index be28f8f7358..51968f0042b 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.cpp +++ b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp @@ -1,48 +1,56 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "unique_store_dictionary.h" -#include "unique_store_add_result.h" +#pragma once + +#include "datastore.hpp" #include "entry_comparator_wrapper.h" #include "i_compactable.h" -#include "datastore.hpp" +#include "unique_store_add_result.h" +#include "unique_store_dictionary.h" #include <vespa/vespalib/btree/btree.hpp> #include <vespa/vespalib/btree/btreebuilder.hpp> -#include <vespa/vespalib/btree/btreeroot.hpp> -#include <vespa/vespalib/btree/btreenodeallocator.hpp> #include <vespa/vespalib/btree/btreeiterator.hpp> #include <vespa/vespalib/btree/btreenode.hpp> +#include <vespa/vespalib/btree/btreenodeallocator.hpp> +#include <vespa/vespalib/btree/btreeroot.hpp> namespace search::datastore { -UniqueStoreDictionary::UniqueStoreDictionary() +template <typename DictionaryT> +UniqueStoreDictionary<DictionaryT>::UniqueStoreDictionary() : UniqueStoreDictionaryBase(), _dict() { } -UniqueStoreDictionary::~UniqueStoreDictionary() = default; +template <typename DictionaryT> +UniqueStoreDictionary<DictionaryT>::~UniqueStoreDictionary() = default; +template <typename DictionaryT> void -UniqueStoreDictionary::freeze() +UniqueStoreDictionary<DictionaryT>::freeze() { _dict.getAllocator().freeze(); } +template <typename DictionaryT> void -UniqueStoreDictionary::transfer_hold_lists(generation_t generation) +UniqueStoreDictionary<DictionaryT>::transfer_hold_lists(generation_t generation) { _dict.getAllocator().transferHoldLists(generation); } - + +template <typename DictionaryT> void -UniqueStoreDictionary::trim_hold_lists(generation_t firstUsed) +UniqueStoreDictionary<DictionaryT>::trim_hold_lists(generation_t firstUsed) { _dict.getAllocator().trimHoldLists(firstUsed); } +template <typename DictionaryT> UniqueStoreAddResult -UniqueStoreDictionary::add(const EntryComparator &comp, - std::function<EntryRef(void)> insertEntry) +UniqueStoreDictionary<DictionaryT>::add(const EntryComparator &comp, + std::function<EntryRef(void)> insertEntry) { auto itr = _dict.lowerBound(EntryRef(), comp); if (itr.valid() && !comp(EntryRef(), itr.getKey())) { @@ -50,13 +58,14 @@ UniqueStoreDictionary::add(const EntryComparator &comp, } else { EntryRef newRef = insertEntry(); - _dict.insert(itr, newRef, btree::BTreeNoLeafData()); + _dict.insert(itr, newRef, DataType()); return UniqueStoreAddResult(newRef, true); } } +template <typename DictionaryT> EntryRef -UniqueStoreDictionary::find(const EntryComparator &comp) +UniqueStoreDictionary<DictionaryT>::find(const EntryComparator &comp) { auto itr = _dict.lowerBound(EntryRef(), comp); if (itr.valid() && !comp(EntryRef(), itr.getKey())) { @@ -66,8 +75,9 @@ UniqueStoreDictionary::find(const EntryComparator &comp) } } +template <typename DictionaryT> void -UniqueStoreDictionary::remove(const EntryComparator &comp, EntryRef ref) +UniqueStoreDictionary<DictionaryT>::remove(const EntryComparator &comp, EntryRef ref) { assert(ref.valid()); auto itr = _dict.lowerBound(ref, comp); @@ -75,8 +85,9 @@ UniqueStoreDictionary::remove(const EntryComparator &comp, EntryRef ref) _dict.remove(itr); } +template <typename DictionaryT> void -UniqueStoreDictionary::move_entries(ICompactable &compactable) +UniqueStoreDictionary<DictionaryT>::move_entries(ICompactable &compactable) { auto itr = _dict.begin(); while (itr.valid()) { @@ -90,27 +101,32 @@ UniqueStoreDictionary::move_entries(ICompactable &compactable) } } +template <typename DictionaryT> uint32_t -UniqueStoreDictionary::get_num_uniques() const +UniqueStoreDictionary<DictionaryT>::get_num_uniques() const { return _dict.getFrozenView().size(); } +template <typename DictionaryT> vespalib::MemoryUsage -UniqueStoreDictionary::get_memory_usage() const +UniqueStoreDictionary<DictionaryT>::get_memory_usage() const { return _dict.getMemoryUsage(); } +template <typename DictionaryT> void -UniqueStoreDictionary::build(const std::vector<EntryRef> &refs, const std::vector<uint32_t> &ref_counts, std::function<void(EntryRef)> hold) +UniqueStoreDictionary<DictionaryT>::build(const std::vector<EntryRef> &refs, + const std::vector<uint32_t> &ref_counts, + std::function<void(EntryRef)> hold) { assert(refs.size() == ref_counts.size()); assert(!refs.empty()); - typename Dictionary::Builder builder(_dict.getAllocator()); + typename DictionaryType::Builder builder(_dict.getAllocator()); for (size_t i = 1; i < refs.size(); ++i) { if (ref_counts[i] != 0u) { - builder.insert(refs[i], btree::BTreeNoLeafData()); + builder.insert(refs[i], DataType()); } else { hold(refs[i]); } @@ -118,16 +134,17 @@ UniqueStoreDictionary::build(const std::vector<EntryRef> &refs, const std::vecto _dict.assign(builder); } +template <typename DictionaryT> EntryRef -UniqueStoreDictionary::get_frozen_root() const +UniqueStoreDictionary<DictionaryT>::get_frozen_root() const { return _dict.getFrozenView().getRoot(); } +template <typename DictionaryT> void -UniqueStoreDictionary::foreach_key(EntryRef root, std::function<void(EntryRef)> callback) const +UniqueStoreDictionary<DictionaryT>::foreach_key(EntryRef root, std::function<void(EntryRef)> callback) const { - _dict.getAllocator().getNodeStore().foreach_key(root, callback); } |