From 00dbb224f7b1c2f976222825ac6918152fdd2350 Mon Sep 17 00:00:00 2001 From: Eugene Wissner Date: Mon, 30 Apr 2018 12:51:06 +0200 Subject: [PATCH] Move length tracking to HashArray --- source/tanya/container/hashtable.d | 33 +++++------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/source/tanya/container/hashtable.d b/source/tanya/container/hashtable.d index f0e8707..50e817a 100644 --- a/source/tanya/container/hashtable.d +++ b/source/tanya/container/hashtable.d @@ -113,7 +113,6 @@ if (is(typeof(hasher(Key.init)) == size_t)) alias ConstRange = .Range!(const HashTable);*/ private HashArray!(hasher, Key, Value) data; - private size_t length_; private alias Buckets = typeof(this.data).Buckets; @@ -154,7 +153,7 @@ if (is(typeof(hasher(Key.init)) == size_t)) */ @property size_t length() const { - return this.length_; + return this.data.length; } /** @@ -164,7 +163,7 @@ if (is(typeof(hasher(Key.init)) == size_t)) */ @property bool empty() const { - return this.length_ == 0; + return length == 0; } /** @@ -172,8 +171,7 @@ if (is(typeof(hasher(Key.init)) == size_t)) */ void clear() { - this.data.array.clear(); - this.length_ = 0; + this.data.clear(); } /** @@ -224,7 +222,6 @@ if (is(typeof(hasher(Key.init)) == size_t)) if (e.status != BucketStatus.used) { e.key = key; - ++this.length_; } e.value = value; return e.value; @@ -269,18 +266,7 @@ if (is(typeof(hasher(Key.init)) == size_t)) */ size_t remove(Key key) { - const code = this.data.locateBucket(key); - - for (auto range = this.data.array[code .. $]; !range.empty; range.popFront()) - { - if (key == range.front.key) - { - range.front.status = BucketStatus.deleted; - --this.length_; - return 1; - } - } - return 0; + return this.data.remove(key); } /** @@ -294,16 +280,7 @@ if (is(typeof(hasher(Key.init)) == size_t)) */ bool opBinaryRight(string op : "in")(Key key) { - const code = this.data.locateBucket(key); - - foreach (ref const e; this.data.array[code .. $]) - { - if (key == e.key) - { - return true; - } - } - return false; + return this.data.find(key); } /**