diff options
author | Araq <rumpf_a@web.de> | 2011-06-15 17:52:04 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-06-15 17:52:04 +0200 |
commit | 9a8b39c85b22518a9c353dcf5d693e701ac272b7 (patch) | |
tree | 34dc2b4e7d7a4fcfc4be0f0f68de63f3022c44f9 /tests/accept/compile | |
parent | f7884717c107ab3fc6f13492eaa5309379f4cb41 (diff) | |
download | Nim-9a8b39c85b22518a9c353dcf5d693e701ac272b7.tar.gz |
rebuilt csources; bootstrap should work again
Diffstat (limited to 'tests/accept/compile')
-rw-r--r-- | tests/accept/compile/titer2.nim | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/accept/compile/titer2.nim b/tests/accept/compile/titer2.nim new file mode 100644 index 000000000..878ddf5e3 --- /dev/null +++ b/tests/accept/compile/titer2.nim @@ -0,0 +1,40 @@ +discard """ + output: '''true''' + cmd: "nimrod cc --gc:none --hints:on $# $#" +""" + +import hashes + +type + TSlotEnum = enum seEmpty, seFilled, seDeleted + TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B] + TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]] + TTable* {.final.}[A, B] = object + data: TKeyValuePairSeq[A, B] + counter: int + +proc len*[A, B](t: TTable[A, B]): int = + result = t.counter + +iterator pairs*[A, B](t: TTable[A, B]): tuple[key: A, val: B] = + ## iterates over any (key, value) pair in the table `t`. + for h in 0..high(t.data): + if t.data[h].slot == seFilled: yield (t.data[h].key, t.data[h].val) + +proc initTable*[A, B](initialSize=64): TTable[A, B] = + ## creates a new hash table that is empty. `initialSize` needs to be + ## a power of two. + result.counter = 0 + newSeq(result.data, initialSize) + +block Test1: + # generic cache does not instantiate the same iterator[types] twice. This + # means we have only one instantiation of 'h'. However, this is the same for + # a non-generic iterator! + + var t = initTable[int, string]() + for k, v in t.pairs: nil + for k, v in t.pairs: nil + +echo "true" + |