fix ordered set equality (#6791)
This commit is contained in:
parent
f6a8cba7b5
commit
42666a5d6d
1 changed files with 21 additions and 5 deletions
|
|
@ -46,7 +46,7 @@ template default[T](t: typedesc[T]): T =
|
||||||
var v: T
|
var v: T
|
||||||
v
|
v
|
||||||
|
|
||||||
proc clear*[A](s: var HashSet[A]) =
|
proc clear*[A](s: var HashSet[A]) =
|
||||||
## Clears the HashSet back to an empty state, without shrinking
|
## Clears the HashSet back to an empty state, without shrinking
|
||||||
## any of the existing storage. O(n) where n is the size of the hash bucket.
|
## any of the existing storage. O(n) where n is the size of the hash bucket.
|
||||||
s.counter = 0
|
s.counter = 0
|
||||||
|
|
@ -610,7 +610,7 @@ type
|
||||||
|
|
||||||
{.deprecated: [TOrderedSet: OrderedSet].}
|
{.deprecated: [TOrderedSet: OrderedSet].}
|
||||||
|
|
||||||
proc clear*[A](s: var OrderedSet[A]) =
|
proc clear*[A](s: var OrderedSet[A]) =
|
||||||
## Clears the OrderedSet back to an empty state, without shrinking
|
## Clears the OrderedSet back to an empty state, without shrinking
|
||||||
## any of the existing storage. O(n) where n is the size of the hash bucket.
|
## any of the existing storage. O(n) where n is the size of the hash bucket.
|
||||||
s.counter = 0
|
s.counter = 0
|
||||||
|
|
@ -911,13 +911,13 @@ proc `==`*[A](s, t: OrderedSet[A]): bool =
|
||||||
## Equality for ordered sets.
|
## Equality for ordered sets.
|
||||||
if s.counter != t.counter: return false
|
if s.counter != t.counter: return false
|
||||||
var h = s.first
|
var h = s.first
|
||||||
var g = s.first
|
var g = t.first
|
||||||
var compared = 0
|
var compared = 0
|
||||||
while h >= 0 and g >= 0:
|
while h >= 0 and g >= 0:
|
||||||
var nxh = s.data[h].next
|
var nxh = s.data[h].next
|
||||||
var nxg = t.data[g].next
|
var nxg = t.data[g].next
|
||||||
if isFilled(s.data[h].hcode) and isFilled(s.data[g].hcode):
|
if isFilled(s.data[h].hcode) and isFilled(t.data[g].hcode):
|
||||||
if s.data[h].key == s.data[g].key:
|
if s.data[h].key == t.data[g].key:
|
||||||
inc compared
|
inc compared
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
@ -1120,6 +1120,22 @@ when isMainModule and not defined(release):
|
||||||
assert s.missingOrExcl(4) == true
|
assert s.missingOrExcl(4) == true
|
||||||
assert s.missingOrExcl(6) == false
|
assert s.missingOrExcl(6) == false
|
||||||
|
|
||||||
|
block orderedSetEquality:
|
||||||
|
type pair = tuple[a, b: int]
|
||||||
|
|
||||||
|
var aa = initOrderedSet[pair]()
|
||||||
|
var bb = initOrderedSet[pair]()
|
||||||
|
|
||||||
|
var x = (a:1,b:2)
|
||||||
|
var y = (a:3,b:4)
|
||||||
|
|
||||||
|
aa.incl(x)
|
||||||
|
aa.incl(y)
|
||||||
|
|
||||||
|
bb.incl(x)
|
||||||
|
bb.incl(y)
|
||||||
|
assert aa == bb
|
||||||
|
|
||||||
when not defined(testing):
|
when not defined(testing):
|
||||||
echo "Micro tests run successfully."
|
echo "Micro tests run successfully."
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue