mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 00:41:28 +00:00
Merge pull request #1361 from def-/setdiff
Add missing difference and to sets module
This commit is contained in:
@@ -167,6 +167,13 @@ proc intersection*[A](s1, s2: TSet[A]): TSet[A] =
|
||||
for item in s1:
|
||||
if item in s2: incl(result, item)
|
||||
|
||||
proc difference*[A](s1, s2: TSet[A]): TSet[A] =
|
||||
## returns a new set of all items that are contained in `s1`, but not in `s2`
|
||||
result = initSet[A]()
|
||||
for item in s1:
|
||||
if not contains(s2, item):
|
||||
incl(result, item)
|
||||
|
||||
proc symmetricDifference*[A](s1, s2: TSet[A]): TSet[A] =
|
||||
## returns a new set of all items that are contained in either
|
||||
## `s1` or `s2`, but not both
|
||||
@@ -182,6 +189,10 @@ proc `*`*[A](s1, s2: TSet[A]): TSet[A] {.inline.} =
|
||||
## alias for `intersection`
|
||||
result = intersection(s1, s2)
|
||||
|
||||
proc `-`*[A](s1, s2: TSet[A]): TSet[A] {.inline.} =
|
||||
## alias for `difference`
|
||||
result = difference(s1, s2)
|
||||
|
||||
proc `-+-`*[A](s1, s2: TSet[A]): TSet[A] {.inline.} =
|
||||
## alias for `symmetricDifference`
|
||||
result = symmetricDifference(s1, s2)
|
||||
|
||||
Reference in New Issue
Block a user