Repository: lucy-clownfish Updated Branches: refs/heads/master 8655f1881 -> 5343ab61c
Replace Hash's `Find_Key` with `Has_Key`. Hash needs some way to indicate whether a key is present but mapped to NULL -- hence, `Has_Key`. `Find_Key` was used for a specific purpose in Lucy but is now obsolete. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/2c02650c Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/2c02650c Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/2c02650c Branch: refs/heads/master Commit: 2c02650ca7292e47390f4802e8b3454192cc6a6b Parents: 1fc8c00 Author: Marvin Humphrey <[email protected]> Authored: Tue Aug 4 17:35:27 2015 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Tue Aug 4 17:35:27 2015 -0700 ---------------------------------------------------------------------- runtime/core/Clownfish/Hash.c | 8 ++++---- runtime/core/Clownfish/Hash.cfh | 7 +++---- runtime/core/Clownfish/Test/TestHash.c | 8 +++----- 3 files changed, 10 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2c02650c/runtime/core/Clownfish/Hash.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Hash.c b/runtime/core/Clownfish/Hash.c index 54a4c26..e0e5d80 100644 --- a/runtime/core/Clownfish/Hash.c +++ b/runtime/core/Clownfish/Hash.c @@ -221,10 +221,10 @@ Hash_Delete_Utf8_IMP(Hash *self, const char *key, size_t key_len) { return Hash_Delete_IMP(self, key_buf); } -String* -Hash_Find_Key_IMP(Hash *self, String *key, size_t hash_sum) { - HashEntry *entry = SI_fetch_entry(self, key, hash_sum); - return entry ? entry->key : NULL; +bool +Hash_Has_Key_IMP(Hash *self, String *key) { + HashEntry *entry = SI_fetch_entry(self, key, Str_Hash_Sum(key)); + return entry ? true : false; } Vector* http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2c02650c/runtime/core/Clownfish/Hash.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Hash.cfh b/runtime/core/Clownfish/Hash.cfh index 95f4779..b2e1973 100644 --- a/runtime/core/Clownfish/Hash.cfh +++ b/runtime/core/Clownfish/Hash.cfh @@ -82,11 +82,10 @@ public final class Clownfish::Hash inherits Clownfish::Obj { public incremented nullable Obj* Delete_Utf8(Hash *self, const char *key, size_t key_len); - /** Search for a key which Equals the key supplied, and return the key - * rather than its value. + /** Indicate whether the supplied `key` is present. */ - nullable String* - Find_Key(Hash *self, String *key, size_t hash_sum); + public bool + Has_Key(Hash *self, String *key); /** Return an Vector of pointers to the hash's keys. */ http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2c02650c/runtime/core/Clownfish/Test/TestHash.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestHash.c b/runtime/core/Clownfish/Test/TestHash.c index 2fe1be3..6487df2 100644 --- a/runtime/core/Clownfish/Test/TestHash.c +++ b/runtime/core/Clownfish/Test/TestHash.c @@ -155,11 +155,9 @@ test_Keys_Values(TestBatchRunner *runner) { { String *forty = SSTR_WRAP_UTF8("40", 2); String *nope = SSTR_WRAP_UTF8("nope", 4); - String *key = Hash_Find_Key(hash, forty, Str_Hash_Sum(forty)); - TEST_TRUE(runner, Str_Equals(key, (Obj*)forty), "Find_Key"); - key = Hash_Find_Key(hash, nope, Str_Hash_Sum(nope)), - TEST_TRUE(runner, key == NULL, - "Find_Key returns NULL for non-existent key"); + TEST_TRUE(runner, Hash_Has_Key(hash, forty), "Has_Key"); + TEST_FALSE(runner, Hash_Has_Key(hash, nope), + "Has_Key returns false for non-existent key"); } DECREF(hash);
