diff options
-rw-r--r-- | src/trie.h | 13 | ||||
-rw-r--r-- | test.cc | 8 |
2 files changed, 21 insertions, 0 deletions
@@ -51,6 +51,19 @@ class Trie { } } + inline bool set(key_list path, Value value) { + std::pair<bool, Trie*> tmp(this->resolve(path)); + + if ( tmp.first ) { + tmp.second->value_.first = true; + tmp.second->value_.second = value; + + return true; + } else { + return false; + } + } + private: std::pair<bool, Value> value_; std::map<Key, Trie> children_; @@ -61,6 +61,14 @@ TEST_F(TrieTest, Value) { EXPECT_EQ(trie.get({1, 2}).first, false); EXPECT_EQ(trie.get({1, 2}).second, nullptr); + + trie.set({1, 2}, 42); + trie.set({1, 1, 1, 1}, 255); + + EXPECT_EQ(trie.get({1, 2}).first, true); + EXPECT_EQ(*trie.get({1, 2}).second, 42); + EXPECT_EQ(trie.get({1, 1, 1, 1}).first, true); + EXPECT_EQ(*trie.get({1, 1, 1, 1}).second, 255); } int main(int argc, char **argv) { |