5#ifndef BITCOIN_SHORTIDPROCESSOR_H
6#define BITCOIN_SHORTIDPROCESSOR_H
12#include <unordered_map>
16template <
typename PrefilledItemType,
typename Adapter,
typename ItemCompare>
18 using ItemType =
typename std::remove_reference<
19 decltype(std::declval<Adapter &>().getItem(
20 std::declval<PrefilledItemType &>()))>::type;
56 const std::vector<uint64_t> &shortids,
57 size_t maxShortIdPerBucket)
59 haveItem(prefilledItems.size() + shortids.size()),
61 for (
const auto &prefilledItem : prefilledItems) {
62 addItem(Adapter::getIndex(prefilledItem),
63 Adapter::getItem(prefilledItem));
66 uint32_t index_offset = 0;
67 for (
size_t i = 0; i < shortids.size(); i++) {
78 shortids[i])) > maxShortIdPerBucket) {
115 return addItem(idit->second, item);
int addItem(uint32_t index, const ItemType &item)
const ItemType & getItem(size_t index) const
bool isEvenlyDistributed() const
Status accessors.
typename std::remove_reference< decltype(std::declval< Adapter & >().getItem(std::declval< PrefilledItemType & >()))>::type ItemType
size_t getItemCount() const
Total item count.
int matchKnownItem(uint64_t shortid, const ItemType &item)
Attempts to add a known item by matching its shortid with the supplied ones.
std::unordered_map< uint64_t, uint32_t > shortIdIndexMap
ShortIdProcessor(const std::vector< PrefilledItemType > &prefilledItems, const std::vector< uint64_t > &shortids, size_t maxShortIdPerBucket)
size_t getShortIdCount() const
Unique shortid count.
std::vector< ItemType > itemsAvailable
bool hasShortIdCollision() const
std::vector< bool > haveItem
bool hasOutOfBoundIndex() const