summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Wissner <belka@caraus.de>2018-04-30 12:51:06 +0200
committerEugen Wissner <belka@caraus.de>2018-05-14 19:23:22 +0200
commit00dbb224f7b1c2f976222825ac6918152fdd2350 (patch)
tree43cd7ca13867f6f635a9a804ff8b3cde44f10fc4
parent9cf1b6f491c7c304446fee49564ebe5a1fddd6d7 (diff)
downloadtanya-00dbb224f7b1c2f976222825ac6918152fdd2350.tar.gz
Move length tracking to HashArray
-rw-r--r--source/tanya/container/hashtable.d33
1 files 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);
}
/**