diff options
Diffstat (limited to 'lib/pure/collections/tableimpl.nim')
-rw-r--r-- | lib/pure/collections/tableimpl.nim | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/pure/collections/tableimpl.nim b/lib/pure/collections/tableimpl.nim index 5900864fb..beafe1109 100644 --- a/lib/pure/collections/tableimpl.nim +++ b/lib/pure/collections/tableimpl.nim @@ -11,10 +11,10 @@ # hcode for real keys cannot be zero. hcode==0 signifies an empty slot. These # two procs retain clarity of that encoding without the space cost of an enum. -proc isEmpty(hcode: THash): bool {.inline.} = +proc isEmpty(hcode: Hash): bool {.inline.} = result = hcode == 0 -proc isFilled(hcode: THash): bool {.inline.} = +proc isFilled(hcode: Hash): bool {.inline.} = result = hcode != 0 const @@ -24,15 +24,15 @@ proc mustRehash(length, counter: int): bool {.inline.} = assert(length > counter) result = (length * 2 < counter * 3) or (length - counter < 4) -proc nextTry(h, maxHash: THash): THash {.inline.} = +proc nextTry(h, maxHash: Hash): Hash {.inline.} = result = (h + 1) and maxHash template rawGetKnownHCImpl() {.dirty.} = - var h: THash = hc and maxHash(t) # start with real hash value + var h: Hash = hc and maxHash(t) # start with real hash value while isFilled(t.data[h].hcode): # Compare hc THEN key with boolean short circuit. This makes the common case # zero ==key's for missing (e.g.inserts) and exactly one ==key for present. - # It does slow down succeeding lookups by one extra THash cmp&and..usually + # It does slow down succeeding lookups by one extra Hash cmp&and..usually # just a few clock cycles, generally worth it for any non-integer-like A. if t.data[h].hcode == hc and t.data[h].key == key: return h @@ -49,7 +49,7 @@ template rawGetDeepImpl() {.dirty.} = # Search algo for unconditional add hc = hash(key) if hc == 0: hc = 314159265 - var h: THash = hc and maxHash(t) + var h: Hash = hc and maxHash(t) while isFilled(t.data[h].hcode): h = nextTry(h, maxHash(t)) result = h @@ -59,22 +59,22 @@ template rawInsertImpl() {.dirty.} = data[h].val = val data[h].hcode = hc -proc rawGetKnownHC[X, A](t: X, key: A, hc: THash): int {.inline.} = +proc rawGetKnownHC[X, A](t: X, key: A, hc: Hash): int {.inline.} = rawGetKnownHCImpl() -proc rawGetDeep[X, A](t: X, key: A, hc: var THash): int {.inline.} = +proc rawGetDeep[X, A](t: X, key: A, hc: var Hash): int {.inline.} = rawGetDeepImpl() -proc rawGet[X, A](t: X, key: A, hc: var THash): int {.inline.} = +proc rawGet[X, A](t: X, key: A, hc: var Hash): int {.inline.} = rawGetImpl() proc rawInsert[X, A, B](t: var X, data: var KeyValuePairSeq[A, B], - key: A, val: B, hc: THash, h: THash) = + key: A, val: B, hc: Hash, h: Hash) = rawInsertImpl() template addImpl(enlarge) {.dirty, immediate.} = if mustRehash(t.dataLen, t.counter): enlarge(t) - var hc: THash + var hc: Hash var j = rawGetDeep(t, key, hc) rawInsert(t, t.data, key, val, hc, j) inc(t.counter) @@ -88,13 +88,13 @@ template maybeRehashPutImpl(enlarge) {.dirty, immediate.} = inc(t.counter) template putImpl(enlarge) {.dirty, immediate.} = - var hc: THash + var hc: Hash var index = rawGet(t, key, hc) if index >= 0: t.data[index].val = val else: maybeRehashPutImpl(enlarge) template mgetOrPutImpl(enlarge) {.dirty, immediate.} = - var hc: THash + var hc: Hash var index = rawGet(t, key, hc) if index < 0: # not present: insert (flipping index) @@ -103,7 +103,7 @@ template mgetOrPutImpl(enlarge) {.dirty, immediate.} = result = t.data[index].val template hasKeyOrPutImpl(enlarge) {.dirty, immediate.} = - var hc: THash + var hc: Hash var index = rawGet(t, key, hc) if index < 0: result = false @@ -111,7 +111,7 @@ template hasKeyOrPutImpl(enlarge) {.dirty, immediate.} = else: result = true template delImpl() {.dirty, immediate.} = - var hc: THash + var hc: Hash var i = rawGet(t, key, hc) let msk = maxHash(t) if i >= 0: |