diff --git a/src/lib/advice/index.hpp b/src/lib/advice/index.hpp index e0de1029b..437ce2760 100644 --- a/src/lib/advice/index.hpp +++ b/src/lib/advice/index.hpp @@ -108,22 +108,46 @@ namespace advice { template class Index { - typedef pair Entry; + + + struct Entry + : pair + { + Entry (POA& elm) + : pair (getMatcher(elm), &elm) + { } + + friend bool + operator== (Entry const& a, Entry const& b) + { + return a.second == b.second; + } + + friend bool + operator!= (Entry const& a, Entry const& b) + { + return a.second != b.second; + } + }; + typedef vector EntryList; + class Cluster { EntryList elms_; + public: void append (POA& elm) { - Entry entry (getMatcher(elm), &elm); + Entry entry (elm); REQUIRE (!contains (elms_, entry)); elms_.push_back(entry); } }; + struct RequestCluster : Cluster { @@ -158,7 +182,7 @@ namespace advice { addRequest (POA& entry) { HashVal key (hash_value(entry)); - requestEntries_[key].add (entry); + requestEntries_[key].append (entry); provisionEntries_[key].publish_latest_solution (entry); } diff --git a/tests/lib/advice/advice-index-test.cpp b/tests/lib/advice/advice-index-test.cpp index 8ea89047c..821ec2e82 100644 --- a/tests/lib/advice/advice-index-test.cpp +++ b/tests/lib/advice/advice-index-test.cpp @@ -79,6 +79,20 @@ namespace test { } + /* == Adapter interface for use within the Index == */ + + friend HashVal + hash_value (TestPOA const& entry) + { + return hash_value (entry.pattern_); + } + + friend const Binding::Matcher + getMatcher (TestPOA const& entry) + { + return entry.pattern_; + } + friend TestPOA* getSolution (TestPOA& entry) {