Remove old hash iteration methods
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/fa3b08b8 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/fa3b08b8 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/fa3b08b8 Branch: refs/heads/master Commit: fa3b08b80064ddd7464ff53d99641dde446b146c Parents: bccbff9 Author: Nick Wellnhofer <[email protected]> Authored: Thu Apr 16 21:59:00 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Thu Apr 16 22:04:25 2015 +0200 ---------------------------------------------------------------------- runtime/core/Clownfish/Hash.c | 40 -------------------- runtime/core/Clownfish/Hash.cfh | 17 --------- runtime/core/Clownfish/Test/TestHash.c | 21 ++-------- .../perl/buildlib/Clownfish/Build/Binding.pm | 22 ----------- 4 files changed, 3 insertions(+), 97 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/fa3b08b8/runtime/core/Clownfish/Hash.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Hash.c b/runtime/core/Clownfish/Hash.c index e05a299..d0553a7 100644 --- a/runtime/core/Clownfish/Hash.c +++ b/runtime/core/Clownfish/Hash.c @@ -40,10 +40,6 @@ typedef struct HashEntry { int32_t hash_sum; } HashEntry; -// Reset the iterator. Hash_Iterate must be called to restart iteration. -static CFISH_INLINE void -SI_kill_iter(Hash *self); - // Return the entry associated with the key, if any. static CFISH_INLINE HashEntry* SI_fetch_entry(Hash *self, String *key, int32_t hash_sum); @@ -78,7 +74,6 @@ Hash_init(Hash *self, uint32_t capacity) { // Init. self->size = 0; - self->iter_tick = -1; // Derive. self->capacity = capacity; @@ -227,40 +222,6 @@ Hash_Delete_Utf8_IMP(Hash *self, const char *key, size_t key_len) { return Hash_Delete_IMP(self, (String*)key_buf); } -uint32_t -Hash_Iterate_IMP(Hash *self) { - SI_kill_iter(self); - return self->size; -} - -static CFISH_INLINE void -SI_kill_iter(Hash *self) { - self->iter_tick = -1; -} - -bool -Hash_Next_IMP(Hash *self, String **key, Obj **value) { - while (1) { - if (++self->iter_tick >= (int32_t)self->capacity) { - // Bail since we've completed the iteration. - --self->iter_tick; - *key = NULL; - *value = NULL; - return false; - } - else { - HashEntry *const entry - = (HashEntry*)self->entries + self->iter_tick; - if (entry->key && entry->key != TOMBSTONE) { - // Success! - *key = entry->key; - *value = entry->value; - return true; - } - } - } -} - String* Hash_Find_Key_IMP(Hash *self, String *key, int32_t hash_sum) { HashEntry *entry = SI_fetch_entry(self, key, hash_sum); @@ -341,7 +302,6 @@ SI_rebuild_hash(Hash *self) { HashEntry *entry = old_entries; HashEntry *limit = old_entries + self->capacity; - SI_kill_iter(self); self->capacity *= 2; self->threshold = (self->capacity / 3) * 2; self->entries = (HashEntry*)CALLOCATE(self->capacity, sizeof(HashEntry)); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/fa3b08b8/runtime/core/Clownfish/Hash.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Hash.cfh b/runtime/core/Clownfish/Hash.cfh index 32cfb97..e93b7ba 100644 --- a/runtime/core/Clownfish/Hash.cfh +++ b/runtime/core/Clownfish/Hash.cfh @@ -27,7 +27,6 @@ class Clownfish::Hash inherits Clownfish::Obj { uint32_t capacity; uint32_t size; uint32_t threshold; /* rehashing trigger point */ - int32_t iter_tick; /* used when iterating */ inert void init_class(); @@ -80,22 +79,6 @@ class Clownfish::Hash inherits Clownfish::Obj { incremented nullable Obj* Delete_Utf8(Hash *self, const char *key, size_t key_ley); - /** Prepare to iterate over all the key-value pairs in the hash. - * - * @return the number of pairs which will be iterated over. - */ - uint32_t - Iterate(Hash *self); - - /** Retrieve the next key-value pair from the hash, setting the supplied - * pointers to point at them. - * - * @return true while iterating, false when the iterator has been - * exhausted. - */ - bool - Next(Hash *self, String **key, Obj **value); - /** Search for a key which Equals the key supplied, and return the key * rather than its value. */ http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/fa3b08b8/runtime/core/Clownfish/Test/TestHash.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestHash.c b/runtime/core/Clownfish/Test/TestHash.c index 1bb7682..bc006d9 100644 --- a/runtime/core/Clownfish/Test/TestHash.c +++ b/runtime/core/Clownfish/Test/TestHash.c @@ -129,7 +129,7 @@ test_Store_and_Fetch(TestBatchRunner *runner) { } static void -test_Keys_Values_Iter(TestBatchRunner *runner) { +test_Keys_Values(TestBatchRunner *runner) { Hash *hash = Hash_new(0); // trigger multiple rebuilds. VArray *expected = VA_new(100); VArray *keys; @@ -153,21 +153,6 @@ test_Keys_Values_Iter(TestBatchRunner *runner) { VA_Clear(values); { - String *key; - Obj *value; - Hash_Iterate(hash); - while (Hash_Next(hash, &key, &value)) { - VA_Push(keys, INCREF(key)); - VA_Push(values, INCREF(value)); - } - } - - VA_Sort(keys, NULL, NULL); - VA_Sort(values, NULL, NULL); - TEST_TRUE(runner, VA_Equals(keys, (Obj*)expected), "Keys from Iter"); - TEST_TRUE(runner, VA_Equals(values, (Obj*)expected), "Values from Iter"); - - { StackString *forty = SSTR_WRAP_UTF8("40", 2); StackString *nope = SSTR_WRAP_UTF8("nope", 4); String *key = Hash_Find_Key(hash, (String*)forty, SStr_Hash_Sum(forty)); @@ -254,11 +239,11 @@ test_store_skips_tombstone(TestBatchRunner *runner) { void TestHash_Run_IMP(TestHash *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 28); + TestBatchRunner_Plan(runner, (TestBatch*)self, 26); srand((unsigned int)time((time_t*)NULL)); test_Equals(runner); test_Store_and_Fetch(runner); - test_Keys_Values_Iter(runner); + test_Keys_Values(runner); test_stress(runner); test_store_skips_tombstone(runner); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/fa3b08b8/runtime/perl/buildlib/Clownfish/Build/Binding.pm ---------------------------------------------------------------------- diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm index 0b682f3..9b2325a 100644 --- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm +++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm @@ -266,7 +266,6 @@ END_XS_CODE sub bind_hash { my @hand_rolled = qw( Store - Next ); my $xs_code = <<'END_XS_CODE'; @@ -289,27 +288,6 @@ PPCODE: if (value) { CFISH_INCREF(value); } CFISH_Hash_Store_IMP(self, key, value); } - -void -next(self) - cfish_Hash *self; -PPCODE: -{ - cfish_String *key; - cfish_Obj *val; - - if (CFISH_Hash_Next(self, &key, &val)) { - SV *key_sv = (SV*)CFISH_Str_To_Host(key); - SV *val_sv = (SV*)CFISH_Obj_To_Host(val); - - XPUSHs(sv_2mortal(key_sv)); - XPUSHs(sv_2mortal(val_sv)); - XSRETURN(2); - } - else { - XSRETURN_EMPTY; - } -} END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new(
