Changeset View
Changeset View
Standalone View
Standalone View
src/index/blockfilterindex.cpp
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
} | } | ||||
READWRITE(hash); | READWRITE(hash); | ||||
} | } | ||||
}; | }; | ||||
}; // namespace | }; // namespace | ||||
static std::map<BlockFilterType, BlockFilterIndex> g_filter_indexes; | |||||
BlockFilterIndex::BlockFilterIndex(BlockFilterType filter_type, | BlockFilterIndex::BlockFilterIndex(BlockFilterType filter_type, | ||||
size_t n_cache_size, bool f_memory, | size_t n_cache_size, bool f_memory, | ||||
bool f_wipe) | bool f_wipe) | ||||
: m_filter_type(filter_type) { | : m_filter_type(filter_type) { | ||||
const std::string &filter_name = BlockFilterTypeName(filter_type); | const std::string &filter_name = BlockFilterTypeName(filter_type); | ||||
if (filter_name.empty()) { | if (filter_name.empty()) { | ||||
throw std::invalid_argument("unknown filter_type"); | throw std::invalid_argument("unknown filter_type"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 347 Lines • ▼ Show 20 Lines | bool BlockFilterIndex::LookupFilterHashRange( | ||||
hashes_out.clear(); | hashes_out.clear(); | ||||
hashes_out.reserve(entries.size()); | hashes_out.reserve(entries.size()); | ||||
for (const auto &entry : entries) { | for (const auto &entry : entries) { | ||||
hashes_out.push_back(entry.hash); | hashes_out.push_back(entry.hash); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
BlockFilterIndex *GetBlockFilterIndex(BlockFilterType filter_type) { | |||||
auto it = g_filter_indexes.find(filter_type); | |||||
return it != g_filter_indexes.end() ? &it->second : nullptr; | |||||
} | |||||
void ForEachBlockFilterIndex(std::function<void(BlockFilterIndex &)> fn) { | |||||
for (auto &entry : g_filter_indexes) { | |||||
fn(entry.second); | |||||
} | |||||
} | |||||
bool InitBlockFilterIndex(BlockFilterType filter_type, size_t n_cache_size, | |||||
bool f_memory, bool f_wipe) { | |||||
auto result = g_filter_indexes.emplace( | |||||
std::piecewise_construct, std::forward_as_tuple(filter_type), | |||||
std::forward_as_tuple(filter_type, n_cache_size, f_memory, f_wipe)); | |||||
return result.second; | |||||
} | |||||
bool DestroyBlockFilterIndex(BlockFilterType filter_type) { | |||||
return g_filter_indexes.erase(filter_type); | |||||
} | |||||
void DestroyAllBlockFilterIndexes() { | |||||
g_filter_indexes.clear(); | |||||
} |