diff options
-rw-r--r-- | lib/pure/collections/sets.nim | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index ad3fe7218..bc249ed63 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -68,6 +68,15 @@ template rawInsertImpl() {.dirty.} = proc rawGet[A](s: TSet[A], key: A): int = rawGetImpl() +proc mget*[A](s: var TSet[A], key: A): var A = + ## returns the element that is actually stored in 's' which has the same + ## value as 'key' or raises the ``EInvalidKey`` exception. This is useful + ## when one overloaded 'hash' and '==' but still needs reference semantics + ## for sharing. + var index = rawGet(s, key) + if index >= 0: result = t.data[index].key + else: raise newException(EInvalidKey, "key not found: " & $key) + proc contains*[A](s: TSet[A], key: A): bool = ## returns true iff `key` is in `s`. var index = rawGet(s, key) |