summary refs log tree commit diff stats
path: root/lib/pure/collections
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-02-07 18:21:25 +0100
committerAraq <rumpf_a@web.de>2014-02-07 18:21:25 +0100
commitd07d83d8fcca8394f2cf00aa78e357c736ed2534 (patch)
tree3156c19f6c7988d6759915154bd8d5ff61b18df7 /lib/pure/collections
parenta087f6057e70e8b7c57ec9a20ac7f7815afe9327 (diff)
parent5498415f3b44048739c9b7116638824713d9c1df (diff)
downloadNim-d07d83d8fcca8394f2cf00aa78e357c736ed2534.tar.gz
Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
Diffstat (limited to 'lib/pure/collections')
-rw-r--r--lib/pure/collections/tables.nim10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index 73da274b9..40ae57b5a 100644
--- a/lib/pure/collections/tables.nim
+++ b/lib/pure/collections/tables.nim
@@ -189,6 +189,16 @@ template dollarImpl(): stmt {.dirty.} =
 proc `$`*[A, B](t: TTable[A, B]): string =
   ## The `$` operator for hash tables.
   dollarImpl()
+  
+proc `==`*[A, B](s, t: TTable[A, B]): bool =
+  s.counter == t.counter and s.data == t.data
+  
+proc indexBy*[A, B, C](collection: A, index: proc(x: B): C): TTable[C, B] =
+  ## Index the collection with the proc provided.
+  # TODO: As soon as supported, change collection: A to collection: A[B]
+  result = initTable[C, B]()
+  for item in collection:
+    result[index(item)] = item
 
 # ------------------------------ ordered table ------------------------------