Skip to content

Commit

Permalink
Fix problem with hat trie exists()
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvasz committed Jan 1, 2012
1 parent 562636e commit 038d056
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
14 changes: 9 additions & 5 deletions src/hat_trie.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,21 @@ class hat_trie {
* @return true iff @a s is in the trie
*/
bool exists(const key_type &word) const {
using namespace std; // TODO
// Locate s in the trie's structure.
const char *ps = word.c_str();
_node_pointer n = _locate(ps);
//cout << "_locate gave node: " << n.p->ch() << endl;

if (*ps == '\0') {
// The string was found in the trie's structure
return n.p->word();
}
if (n.type == CONTAINER_POINTER) {
//cout << "container pointer" << endl;
return ((_container *) n.p)->exists(ps);
// Determine whether the remainder of the string is inside
// a container or not
_container *c = (_container * )n.p;
return c->_store.find(ps) != c->_store.end();
}
return n.p->word();
return false;
}

/**
Expand Down
25 changes: 11 additions & 14 deletions test/hat_set_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,21 @@ TEST(testConstructor)
BOOST_CHECK(h.empty());
}

/*
TEST(testExists)
{
set<string> inserted;
hat_set<string> hs;
foreach (const string& str, data) {
// keep track of what has been inserted already
hs.insert(str);
inserted.insert(str);
hat_trie_traits traits;
traits.burst_threshold = 2;
hat_set<string> h(traits);
h.insert("abcde");
h.insert("abcd");
h.insert("abc");
h.insert("b");
h.print();

// make sure the inserted data is the only data that appears
// in the array hash
foreach (const string& s, data) {
BOOST_CHECK_EQUAL(inserted.find(s) != inserted.end(), hs.exists(s));
}
}
BOOST_CHECK(h.exists("a") == false);
BOOST_CHECK(h.exists("abcde"));
BOOST_CHECK(h.exists("ag") == false);
}
*/

TEST(testFind)
{
Expand Down

0 comments on commit 038d056

Please sign in to comment.