diff options
author | Araq <rumpf_a@web.de> | 2012-08-22 22:46:02 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-22 22:46:02 +0200 |
commit | f8931798899647b65ebb7d7dcf28d6976da599ce (patch) | |
tree | 0fdbd7f0b5516279458d21bf99a698cb2cb89e37 /lib/pure/collections/sets.nim | |
parent | a95e958046447d0ef88d93337171d4b8339348a4 (diff) | |
download | Nim-f8931798899647b65ebb7d7dcf28d6976da599ce.tar.gz |
documented hygienic templates; made tests green; fixed system.clamp
Diffstat (limited to 'lib/pure/collections/sets.nim')
-rwxr-xr-x | lib/pure/collections/sets.nim | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index f65239b83..ff2ffec0e 100755 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -16,6 +16,8 @@ import os, hashes, math {.pragma: myShallow.} +when not defined(nimhygiene): + {.pragma: dirty.} type TSlotEnum = enum seEmpty, seFilled, seDeleted @@ -48,7 +50,7 @@ proc mustRehash(length, counter: int): bool {.inline.} = proc nextTry(h, maxHash: THash): THash {.inline.} = result = ((5 * h) + 1) and maxHash -template rawGetImpl() = +template rawGetImpl() {.dirty.} = var h: THash = hash(key) and high(s.data) # start with real hash value while s.data[h].slot != seEmpty: if s.data[h].key == key and s.data[h].slot == seFilled: @@ -56,7 +58,7 @@ template rawGetImpl() = h = nextTry(h, high(s.data)) result = -1 -template rawInsertImpl() = +template rawInsertImpl() {.dirty.} = var h: THash = hash(key) and high(data) while data[h].slot == seFilled: h = nextTry(h, high(data)) @@ -81,14 +83,14 @@ proc Enlarge[A](s: var TSet[A]) = if s.data[i].slot == seFilled: RawInsert(s, n, s.data[i].key) swap(s.data, n) -template inclImpl() = +template inclImpl() {.dirty.} = var index = RawGet(s, key) if index < 0: if mustRehash(len(s.data), s.counter): Enlarge(s) RawInsert(s, s.data, key) inc(s.counter) -template containsOrInclImpl() = +template containsOrInclImpl() {.dirty.} = var index = RawGet(s, key) if index >= 0: result = true @@ -125,7 +127,7 @@ proc toSet*[A](keys: openarray[A]): TSet[A] = result = initSet[A](nextPowerOfTwo(keys.len+10)) for key in items(keys): result.incl(key) -template dollarImpl(): stmt = +template dollarImpl(): stmt {.dirty.} = result = "{" for key in items(s): if result.len > 1: result.add(", ") @@ -155,7 +157,7 @@ proc card*[A](s: TOrderedSet[A]): int {.inline.} = ## alias for `len`. result = s.counter -template forAllOrderedPairs(yieldStmt: stmt) = +template forAllOrderedPairs(yieldStmt: stmt) {.dirty.} = var h = s.first while h >= 0: var nxt = s.data[h].next |