diff options
author | Araq <rumpf_a@web.de> | 2014-08-13 02:34:08 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-08-13 02:34:08 +0200 |
commit | abc844733157441ed5a1aee23476e55c2fcd8a83 (patch) | |
tree | 5b65c4a4147ea30a9b7b70dc3c3aefad8859667c /lib/pure/collections/sets.nim | |
parent | 9d5d3c9fa149c8bfef6169884510d4027a1e0b6e (diff) | |
download | Nim-abc844733157441ed5a1aee23476e55c2fcd8a83.tar.gz |
fixes #1413
Diffstat (limited to 'lib/pure/collections/sets.nim')
-rw-r--r-- | lib/pure/collections/sets.nim | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index 42cdc682f..22eff9c55 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -713,6 +713,24 @@ proc `$`*[A](s: TOrderedSet[A]): string = assert s.isValid, "The set needs to be initialized." dollarImpl() +proc `==`*[A](s, t: TOrderedSet[A]): bool = + ## Equality for ordered sets. + if s.counter != t.counter: return false + var h = s.first + var g = s.first + var compared = 0 + while h >= 0 and g >= 0: + var nxh = s.data[h].next + var nxg = t.data[g].next + if s.data[h].slot == seFilled and s.data[g].slot == seFilled: + if s.data[h].key == s.data[g].key: + inc compared + else: + return false + h = nxh + g = nxg + result = compared == s.counter + proc testModule() = ## Internal micro test to validate docstrings and such. block isValidTest: @@ -858,7 +876,7 @@ proc testModule() = var b = initOrderedSet[int]() for x in [2, 4, 5]: b.incl(x) assert($a == $b) - # assert(a == b) # https://github.com/Araq/Nimrod/issues/1413 + assert(a == b) # https://github.com/Araq/Nimrod/issues/1413 block initBlocks: var a: TOrderedSet[int] |