// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "unique_store_hash_dictionary_read_snapshot.h" namespace vespalib::datastore { template UniqueStoreHashDictionaryReadSnapshot::UniqueStoreHashDictionaryReadSnapshot(const HashDictionaryType &hash) : _hash(hash), _refs() { } template void UniqueStoreHashDictionaryReadSnapshot::fill() { _hash.foreach_key([this](EntryRef ref) { _refs.push_back(ref); }); } template void UniqueStoreHashDictionaryReadSnapshot::sort() { auto& comp = _hash.get_default_comparator(); std::sort(_refs.begin(), _refs.end(), [&comp](EntryRef lhs, EntryRef rhs) { return comp.less(lhs, rhs); }); } template size_t UniqueStoreHashDictionaryReadSnapshot::count(const EntryComparator& comp) const { auto result = _hash.find(comp, EntryRef()); return ((result != nullptr) ? 1u : 0u); } template size_t UniqueStoreHashDictionaryReadSnapshot::count_in_range(const EntryComparator&, const EntryComparator&) const { return 1u; } template void UniqueStoreHashDictionaryReadSnapshot::foreach_key(std::function callback) const { for (auto ref : _refs) { callback(AtomicEntryRef(ref)); } } }