5#ifndef BITCOIN_SHORTIDPROCESSOR_H
6#define BITCOIN_SHORTIDPROCESSOR_H
11#include <unordered_map>
15template <
typename PrefilledItemType,
typename Adapter,
typename ItemCompare>
17 using ItemType =
typename std::remove_reference<
18 decltype(std::declval<Adapter &>().getItem(
19 std::declval<PrefilledItemType &>()))>::type;
55 const std::vector<uint64_t> &shortids,
56 size_t maxShortIdPerBucket)
58 haveItem(prefilledItems.size() + shortids.size()),
60 for (
const auto &prefilledItem : prefilledItems) {
61 addItem(Adapter::getIndex(prefilledItem),
62 Adapter::getItem(prefilledItem));
65 uint32_t index_offset = 0;
66 for (
size_t i = 0; i < shortids.size(); i++) {
77 shortids[i])) > maxShortIdPerBucket) {
114 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