MatchBin.hpp
A container that supports flexible tag-based lookup. .
-
template<typename Val, typename Tag, typename Regulator>
struct MatchBinState - #include <MatchBin.hpp>
Internal state packet for MatchBin.
-
struct entry
- #include <MatchBin.hpp>
-
struct entry
-
template<typename Val, typename Query, typename Tag, typename Regulator>
class BaseMatchBin - #include <MatchBin.hpp>
Abstract base class for MatchBin.
Public Functions
-
inline virtual ~BaseMatchBin()
-
virtual void Clear() = 0
-
virtual void ClearCache() = 0
-
virtual bool ActivateCaching() = 0
-
virtual void DeactivateCaching() = 0
-
virtual size_t Size() const = 0
-
virtual void DecayRegulators(const int steps = 1) = 0
-
virtual void ImprintRegulators(const BaseMatchBin &target) = 0
-
virtual void ImprintRegulators(const BaseMatchBin::state_t &target) = 0
-
inline virtual ~BaseMatchBin()
-
template<typename Val, typename Metric, typename Selector, typename Regulator>
class MatchBin : public BaseMatchBin<Val, Metric::query_t, Metric::tag_t, Regulator> - #include <MatchBin.hpp>
A data container that allows lookup by tag similarity. It can be templated on different tag types and is configurable on construction for (1) the distance metric used to compute similarity between tags and (2) the selector that is used to select which matches to return. Regulation functionality is also provided, allowing dynamically adjustment of match strength to a particular item (i.e., making all matches stronger/weaker). A unique identifier is generated upon tag/item placement in the container. This unique identifier can be used to view or edit the stored items and their corresponding tags. Tag-based lookups return a list of matched unique identifiers.
Public Types
Public Functions
-
MatchBin() = default
-
inline vector<uid_t> Match(const query_t &query, size_t n = std::numeric_limits<size_t>::max()) override
Compare a query tag to all stored tags using the distance metric function and return a vector of unique IDs chosen by the selector function. Calling with n = std::numeric_limits<size_t>::max() means delegate choice for how many values to return to the Selector.
-
inline vector<uid_t> MatchRaw(const query_t &query, size_t n = std::numeric_limits<size_t>::max()) override
Compare a query tag to all stored tags using the distance metric function and return a vector of unique IDs chosen by the selector function. Ignore regulators. Calling with n = std::numeric_limits<size_t>::max() means delegate choice for how many values to return to the Selector.
-
inline uid_t Put(const Val &v, const tag_t &t) override
Put an item and associated tag in the container. Returns the uid for that entry.
-
inline uid_t Set(const Val &v, const tag_t &t, const uid_t uid) override
Put with a manually-chosen UID. (Caller is responsible for ensuring UID is unique or calling Delete beforehand.)
-
inline virtual void Clear() override
Clear all items and tags.
-
inline virtual void ClearCache() override
Reset the Selector caches.
-
inline virtual bool ActivateCaching() override
Attempt to activate result caching.
- Returns:
true if caching activated
-
inline virtual void DeactivateCaching() override
-
inline virtual Val &GetVal(const uid_t uid) override
Access a reference single stored value by uid.
-
inline virtual const tag_t &GetTag(const uid_t uid) const override
Access a const reference to a single stored tag by uid.
-
inline void SetTag(const uid_t uid, const tag_t tag) override
Change the tag at a given uid and clear the cache.
-
inline virtual vector<Val> GetVals(const vector<uid_t> &uids) override
Generate a vector of values corresponding to a vector of uids.
-
inline virtual vector<tag_t> GetTags(const vector<uid_t> &uids) override
Generate a vector of tags corresponding to a vector of uids.
-
inline virtual size_t Size() const override
Get the number of items stored in the container.
-
inline virtual void AdjRegulator(const uid_t uid, const typename Regulator::adj_t &amt) override
Adjust an item’s regulator value.
-
inline virtual void SetRegulator(const uid_t uid, const typename Regulator::set_t &set) override
Set an item’s regulator value.
-
inline virtual void SetRegulator(const uid_t uid, const Regulator &set) override
Set an item’s regulator value.
-
inline virtual const Regulator::view_t &ViewRegulator(const uid_t uid) const override
View an item’s regulator value.
-
inline virtual void DecayRegulator(const uid_t uid, const int steps) override
Apply decay to a regulator.
-
inline virtual void DecayRegulators(const int steps = 1) override
Apply decay to all regulators.
-
inline virtual void ImprintRegulators(const BaseMatchBin<Val, query_t, tag_t, Regulator> &target) override
Set up regulators to match target MatchBin
- Parameters:
target – MatchBin to match
-
inline virtual void ImprintRegulators(const state_t &target) override
Set up regulators to match target state
- Parameters:
target – State to match
-
inline size_t GetRegulatedCacheSize()
Returns size of regulated cache.
-
inline size_t GetRawCacheSize()
Returns size of raw cache.
-
MatchBin() = default
-
namespace cereal