载入中...
搜索中...
未找到
WatchIndex.cpp
浏览该文件的文档.
2
3#include <algorithm>
4
5namespace eve::emergence {
6
7void WatchIndex::clear() { index_.clear(); }
8
9void WatchIndex::addRule(std::uint32_t ruleIndex, const std::vector<std::string>& keys) {
10 for (const auto& key : keys) {
11 if (key.empty()) continue;
12 auto& list = index_[key];
13 const auto it = std::lower_bound(list.begin(), list.end(), ruleIndex);
14 if (it == list.end() || *it != ruleIndex) list.insert(it, ruleIndex);
15 }
16}
17
18std::size_t WatchIndex::collect(std::string_view key, std::vector<std::uint32_t>& out) const {
19 auto it = index_.find(std::string(key));
20 if (it == index_.end()) return 0;
21 out.insert(out.end(), it->second.begin(), it->second.end());
22 return it->second.size();
23}
24
25} // namespace eve::emergence
std::uint32_t key
Inverted index from fact keys to interested rule ids.
void addRule(std::uint32_t ruleIndex, const std::vector< std::string > &keys)
Index one rule under each of its watch keys.
Definition WatchIndex.cpp:9
std::size_t collect(std::string_view key, std::vector< std::uint32_t > &out) const
Collect unique rule indexes that watch a key into out.
void clear()
Remove every subscription.
Definition WatchIndex.cpp:7