summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-08-23 09:47:11 +0200
committerGitHub <noreply@github.com>2019-08-23 09:47:11 +0200
commitdd23f1ddffe01833350b84eb1a4905870a4c4a62 (patch)
treebcc4cf15d02abd9b804bc461934a3a55c3218865 /vespalib
parent09f2622a7097602ff5bc02e061b85ab3bf99b0fb (diff)
parent32a1d842d2aaf08ea996c9b142ef89aca1b7b3f0 (diff)
Merge pull request #10384 from vespa-engine/geirst/rewrite-enum-store-dictionary
Geirst/rewrite enum store dictionary
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/datastore/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store.hpp16
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h17
-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);
}