Overrides =copy for PackedSets (#21417)
This commit is contained in:
parent
89a60939f8
commit
6fea221d65
1 changed files with 14 additions and 15 deletions
|
|
@ -12,11 +12,6 @@
|
||||||
##
|
##
|
||||||
## Supports any Ordinal type.
|
## Supports any Ordinal type.
|
||||||
##
|
##
|
||||||
## .. note:: Currently the assignment operator `=` for `PackedSet[A]`
|
|
||||||
## performs some rather meaningless shallow copy. Since Nim currently does
|
|
||||||
## not allow the assignment operator to be overloaded, use the `assign proc
|
|
||||||
## <#assign,PackedSet[A],PackedSet[A]>`_ to get a deep copy.
|
|
||||||
##
|
|
||||||
## See also
|
## See also
|
||||||
## ========
|
## ========
|
||||||
## * `sets module <sets.html>`_ for more general hash sets
|
## * `sets module <sets.html>`_ for more general hash sets
|
||||||
|
|
@ -412,18 +407,9 @@ proc isNil*[A](x: PackedSet[A]): bool {.inline.} =
|
||||||
|
|
||||||
x.head.isNil and x.elems == 0
|
x.head.isNil and x.elems == 0
|
||||||
|
|
||||||
proc assign*[A](dest: var PackedSet[A], src: PackedSet[A]) =
|
proc `=copy`*[A](dest: var PackedSet[A], src: PackedSet[A]) =
|
||||||
## Copies `src` to `dest`.
|
## Copies `src` to `dest`.
|
||||||
## `dest` does not need to be initialized by the `initPackedSet proc <#initPackedSet>`_.
|
## `dest` does not need to be initialized by the `initPackedSet proc <#initPackedSet>`_.
|
||||||
runnableExamples:
|
|
||||||
var
|
|
||||||
a = initPackedSet[int]()
|
|
||||||
b = initPackedSet[int]()
|
|
||||||
b.incl(5)
|
|
||||||
b.incl(7)
|
|
||||||
a.assign(b)
|
|
||||||
assert len(a) == 2
|
|
||||||
|
|
||||||
if src.elems <= src.a.len:
|
if src.elems <= src.a.len:
|
||||||
dest.data = @[]
|
dest.data = @[]
|
||||||
dest.max = 0
|
dest.max = 0
|
||||||
|
|
@ -452,6 +438,19 @@ proc assign*[A](dest: var PackedSet[A], src: PackedSet[A]) =
|
||||||
dest.data[h] = n
|
dest.data[h] = n
|
||||||
it = it.next
|
it = it.next
|
||||||
|
|
||||||
|
proc assign*[A](dest: var PackedSet[A], src: PackedSet[A]) {.inline, deprecated.} =
|
||||||
|
## Copies `src` to `dest`.
|
||||||
|
## `dest` does not need to be initialized by the `initPackedSet proc <#initPackedSet>`_.
|
||||||
|
runnableExamples:
|
||||||
|
var
|
||||||
|
a = initPackedSet[int]()
|
||||||
|
b = initPackedSet[int]()
|
||||||
|
b.incl(5)
|
||||||
|
b.incl(7)
|
||||||
|
a.assign(b)
|
||||||
|
assert len(a) == 2
|
||||||
|
`=copy`(dest, src)
|
||||||
|
|
||||||
proc union*[A](s1, s2: PackedSet[A]): PackedSet[A] =
|
proc union*[A](s1, s2: PackedSet[A]): PackedSet[A] =
|
||||||
## Returns the union of the sets `s1` and `s2`.
|
## Returns the union of the sets `s1` and `s2`.
|
||||||
##
|
##
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue