Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into friday_night
Browse files Browse the repository at this point in the history
  • Loading branch information
tli2 authored Jun 15, 2018
2 parents 30fddc2 + 308a669 commit 21253c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/codegen/util/hash_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ char *HashTable::Insert(uint64_t hash) {
}

void HashTable::BuildLazy() {
// Early exit if no elements have been added (hash table is still valid)
if (num_elems_ == 0) return;

// Grab entry head
Entry *head = directory_[0];

Expand Down
27 changes: 27 additions & 0 deletions test/codegen/hash_table_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ TEST_F(HashTableTest, CanInsertUniqueKeys) {
}
}

TEST_F(HashTableTest, BuildEmptyHashTable) {
codegen::util::HashTable table{GetMemPool(), sizeof(Key), sizeof(Value)};

std::vector<Key> keys;

// Insert keys
for (uint32_t i = 0; i < 10; i++) {
Key k{1, i};
// do NOT insert into hash table

keys.emplace_back(k);
}

EXPECT_EQ(0, table.NumElements());

// Build lazy
table.BuildLazy();

// Lookups should succeed
for (const auto &key : keys) {
std::function<void(const Value &v)> f =
[](UNUSED_ATTRIBUTE const Value &v) {};
auto ret = table.TypedProbe(key.Hash(), key, f);
EXPECT_EQ(false, ret);
}
}

TEST_F(HashTableTest, CanInsertDuplicateKeys) {
codegen::util::HashTable table{GetMemPool(), sizeof(Key), sizeof(Value)};

Expand Down

0 comments on commit 21253c4

Please sign in to comment.