Skip to content

Commit

Permalink
All tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvasz committed Jan 3, 2012
1 parent a995b2a commit 0f98a7b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 40 deletions.
10 changes: 0 additions & 10 deletions src/array_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
#include <utility>
#include <iterator>

/// TODO
#include <iostream>
using namespace std;

namespace stx {

/**
Expand Down Expand Up @@ -160,8 +156,6 @@ class array_hash<std::string>
_traits(traits)
{
_init();
//cout << endl;
//cout << "constructor called. data = " << _data << " size = " << _size << endl;
}

/**
Expand Down Expand Up @@ -306,12 +300,10 @@ class array_hash<std::string>
*/
bool insert(const char *str)
{
//cout << "top of ahinsert: " << _data << " " << _size << endl;
length_type length;
int slot = _hash(str, length);
char *p = _data[slot];
if (p) {
//cout << " found a slot" << endl;
size_type occupied;
if (_search(str, p, length, occupied) != NULL) {
// str is already in the table. Nothing needs to be done.
Expand All @@ -329,7 +321,6 @@ class array_hash<std::string>
p = _data[slot] + occupied - sizeof(length_type);

} else {
//cout << " new slot required" << endl;
// Make a new slot for this string.
size_type required = sizeof(size_type) + 2 * sizeof(length_type)
+ length;
Expand All @@ -342,7 +333,6 @@ class array_hash<std::string>
// Write str into the slot.
_append_string(str, p, length);
++_size;
//cout << "bottom of ahinsert: " << _size << endl;
return true;
}

Expand Down
22 changes: 0 additions & 22 deletions src/hat_trie.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@

#include "array_hash.h"

/// TODO
#include <iostream>
using namespace std;

namespace stx {

/// number of distinct characters a hat trie can store
Expand Down Expand Up @@ -404,11 +400,9 @@ class hat_trie<std::string> {
* was already in the trie
*/
bool insert(const char *word) {
//cout << "inserting " << word << endl;
const char *pos = word;
htnode_ptr n = _locate(pos);
if (*pos == '\0') {
//cout << " found" << endl;
// word was found in the trie's structure. Mark its location
// as the end of a word.
if (n.word() == false) {
Expand All @@ -421,34 +415,26 @@ class hat_trie<std::string> {
return false;

} else {
//cout << " not found" << endl;
// word was not found in the trie's structure. Either make a
// new bucket for it or insert it into an already
// existing bucket
ahnode *at = NULL;
if (n.type == NODE_POINTER) {
//cout << " making a new one" << endl;
// Make a new bucket for word
htnode *p = n.ptr.node;
int index = *pos;

at = new ahnode();
at->table = new bucket(_ah_traits);
//cout << " made a new one at " << at << endl;
at->ch = index;
at->word = false;

// Insert the new bucket into the trie's structure
//cout << " size: " << at->size() << endl;
//cout << " parent: " << at->parent << endl;
at->parent = p;
//cout << " size: " << (void *)at->size() << endl;
//cout << " parent: " << at->parent << " " << p << endl;
p->_children[index].bucket = at;
p->_types[index] = BUCKET_POINTER;
++pos;
} else if (n.type == BUCKET_POINTER) {
//cout << " found one already" << endl;
// The container for s already exists.
at = n.ptr.bucket;
}
Expand Down Expand Up @@ -637,17 +623,13 @@ class hat_trie<std::string> {
const char *ps = word.c_str();
htnode_ptr n = _locate(ps);

//cout << "located " << n.ch() << endl;
iterator result;
if (*ps == '\0') {
//cout << "at node returned by locate" << endl;
// The word is in the trie at the node returned by _locate
if (n.word()) {
//cout << "word is true" << endl;
result = n;
result._cached_word = std::string(word.c_str());
} else {
//cout << "word is false" << endl;
// The word is not a word in the trie
result = end();
}
Expand Down Expand Up @@ -965,15 +947,12 @@ class hat_trie<std::string> {
* otherwise
*/
bool _insert(ahnode *htc, const char *s) {
//cout << "top of _insert. size: " << htc->size() << endl;
// Try to insert s into the container.
bool result;
if (*s == '\0') {
//cout << " no more" << endl;
result = !htc->word;
htc->word = true;
} else {
//cout << " more" << endl;
result = htc->table->insert(s);
}

Expand All @@ -982,7 +961,6 @@ class hat_trie<std::string> {
if (_traits.burst_threshold > 0 &&
htc->table->size() > _traits.burst_threshold) {
// burst the bucket into nodes
//cout << "BURSTING: " << htc->size() << " > " << _traits.burst_threshold << endl;
_burst(htc);
}
return true;
Expand Down
8 changes: 0 additions & 8 deletions test/hat_set_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ TEST(testFind)
BOOST_CHECK(h.find("abcdefg") == h.end());
}

/*
TEST(testInsert)
{
cout << 1 << endl;
hat_set<string> h;

// Test c string insert
Expand All @@ -121,15 +119,13 @@ TEST(testInsert)

TEST(testForwardIteration)
{
cout << 2 << endl;
hat_set<string> h(data.begin(), data.end());
set<string> s(h.begin(), h.end());
check_equal(s, data);
}

TEST(testSwap)
{
cout << 3 << endl;
hat_set<string> control(data.begin(), data.end());
hat_set<string> a(data.begin(), data.end());
hat_set<string> b;
Expand All @@ -141,7 +137,6 @@ TEST(testSwap)

TEST(testCount)
{
cout << 4 << endl;
hat_set<string> h;
h.insert("hello");
BOOST_CHECK(h.count("hello") == 1);
Expand All @@ -150,7 +145,6 @@ TEST(testCount)

TEST(testClear)
{
cout << 5 << endl;
hat_set<string> h;
h.insert("hello");
h.clear();
Expand All @@ -159,7 +153,6 @@ TEST(testClear)

TEST(testEquals)
{
cout << 6 << endl;
hat_set<string> a(data.begin(), data.end());
hat_set<string> b(data.begin(), data.end());
hat_set<string> c;
Expand All @@ -168,7 +161,6 @@ TEST(testEquals)
BOOST_CHECK(a != c);
BOOST_CHECK(b != c);
}
*/

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 0f98a7b

Please sign in to comment.