summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-08-22 12:49:21 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-08-22 12:49:21 +0000
commit573e34dc1ff2f9be5b76c8505fcda6c1b98a2da1 (patch)
tree409231606053fc92c3bd542da1ab16410a56c8e0 /vespalib
parent63513d5f76fd005f18a72ea9a458b46581ee42f6 (diff)
Change unique store dictionary to take btree dictionary type as template argument.
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.h11
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp (renamed from vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.cpp)60
4 files changed, 57 insertions, 31 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..c6c73b09259 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 DictionaryType>
class UniqueStoreDictionary : public UniqueStoreDictionaryBase
{
public:
- using DictionaryTraits = btree::BTreeTraits<32, 32, 7, true>;
- using Dictionary = btree::BTree<EntryRef, btree::BTreeNoLeafData,
- btree::NoAggregated,
- EntryComparatorWrapper,
- DictionaryTraits>;
+ using Dictionary = DictionaryType;
private:
- Dictionary _dict;
+ 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..b73c245956e 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 DictionaryType>
+UniqueStoreDictionary<DictionaryType>::UniqueStoreDictionary()
: UniqueStoreDictionaryBase(),
_dict()
{
}
-UniqueStoreDictionary::~UniqueStoreDictionary() = default;
+template <typename DictionaryType>
+UniqueStoreDictionary<DictionaryType>::~UniqueStoreDictionary() = default;
+template <typename DictionaryType>
void
-UniqueStoreDictionary::freeze()
+UniqueStoreDictionary<DictionaryType>::freeze()
{
_dict.getAllocator().freeze();
}
+template <typename DictionaryType>
void
-UniqueStoreDictionary::transfer_hold_lists(generation_t generation)
+UniqueStoreDictionary<DictionaryType>::transfer_hold_lists(generation_t generation)
{
_dict.getAllocator().transferHoldLists(generation);
}
-
+
+template <typename DictionaryType>
void
-UniqueStoreDictionary::trim_hold_lists(generation_t firstUsed)
+UniqueStoreDictionary<DictionaryType>::trim_hold_lists(generation_t firstUsed)
{
_dict.getAllocator().trimHoldLists(firstUsed);
}
+template <typename DictionaryType>
UniqueStoreAddResult
-UniqueStoreDictionary::add(const EntryComparator &comp,
- std::function<EntryRef(void)> insertEntry)
+UniqueStoreDictionary<DictionaryType>::add(const EntryComparator &comp,
+ std::function<EntryRef(void)> insertEntry)
{
auto itr = _dict.lowerBound(EntryRef(), comp);
if (itr.valid() && !comp(EntryRef(), itr.getKey())) {
@@ -55,8 +63,9 @@ UniqueStoreDictionary::add(const EntryComparator &comp,
}
}
+template <typename DictionaryType>
EntryRef
-UniqueStoreDictionary::find(const EntryComparator &comp)
+UniqueStoreDictionary<DictionaryType>::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 DictionaryType>
void
-UniqueStoreDictionary::remove(const EntryComparator &comp, EntryRef ref)
+UniqueStoreDictionary<DictionaryType>::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 DictionaryType>
void
-UniqueStoreDictionary::move_entries(ICompactable &compactable)
+UniqueStoreDictionary<DictionaryType>::move_entries(ICompactable &compactable)
{
auto itr = _dict.begin();
while (itr.valid()) {
@@ -90,20 +101,25 @@ UniqueStoreDictionary::move_entries(ICompactable &compactable)
}
}
+template <typename DictionaryType>
uint32_t
-UniqueStoreDictionary::get_num_uniques() const
+UniqueStoreDictionary<DictionaryType>::get_num_uniques() const
{
return _dict.getFrozenView().size();
}
+template <typename DictionaryType>
vespalib::MemoryUsage
-UniqueStoreDictionary::get_memory_usage() const
+UniqueStoreDictionary<DictionaryType>::get_memory_usage() const
{
return _dict.getMemoryUsage();
}
+template <typename DictionaryType>
void
-UniqueStoreDictionary::build(const std::vector<EntryRef> &refs, const std::vector<uint32_t> &ref_counts, std::function<void(EntryRef)> hold)
+UniqueStoreDictionary<DictionaryType>::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());
@@ -118,14 +134,16 @@ UniqueStoreDictionary::build(const std::vector<EntryRef> &refs, const std::vecto
_dict.assign(builder);
}
+template <typename DictionaryType>
EntryRef
-UniqueStoreDictionary::get_frozen_root() const
+UniqueStoreDictionary<DictionaryType>::get_frozen_root() const
{
return _dict.getFrozenView().getRoot();
}
+template <typename DictionaryType>
void
-UniqueStoreDictionary::foreach_key(EntryRef root, std::function<void(EntryRef)> callback) const
+UniqueStoreDictionary<DictionaryType>::foreach_key(EntryRef root, std::function<void(EntryRef)> callback) const
{
_dict.getAllocator().getNodeStore().foreach_key(root, callback);