mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
@@ -164,6 +164,27 @@ proc contains*[A](s: HashSet[A], key: A): bool =
|
||||
var index = rawGet(s, key, hc)
|
||||
result = index >= 0
|
||||
|
||||
proc len*[A](s: HashSet[A]): int =
|
||||
## Returns the number of elements in `s`.
|
||||
##
|
||||
## Due to an implementation detail you can call this proc on variables which
|
||||
## have not been initialized yet. The proc will return zero as the length
|
||||
## then.
|
||||
runnableExamples:
|
||||
var a: HashSet[string]
|
||||
assert len(a) == 0
|
||||
let s = toHashSet([3, 5, 7])
|
||||
assert len(s) == 3
|
||||
|
||||
result = s.counter
|
||||
|
||||
proc card*[A](s: HashSet[A]): int =
|
||||
## Alias for `len() <#len,HashSet[A]>`_.
|
||||
##
|
||||
## Card stands for the `cardinality
|
||||
## <http://en.wikipedia.org/wiki/Cardinality>`_ of a set.
|
||||
result = s.counter
|
||||
|
||||
proc incl*[A](s: var HashSet[A], key: A) =
|
||||
## Includes an element `key` in `s`.
|
||||
##
|
||||
@@ -357,27 +378,6 @@ proc clear*[A](s: var HashSet[A]) =
|
||||
s.data[i].hcode = 0
|
||||
s.data[i].key = default(typeof(s.data[i].key))
|
||||
|
||||
proc len*[A](s: HashSet[A]): int =
|
||||
## Returns the number of elements in `s`.
|
||||
##
|
||||
## Due to an implementation detail you can call this proc on variables which
|
||||
## have not been initialized yet. The proc will return zero as the length
|
||||
## then.
|
||||
runnableExamples:
|
||||
var a: HashSet[string]
|
||||
assert len(a) == 0
|
||||
let s = toHashSet([3, 5, 7])
|
||||
assert len(s) == 3
|
||||
|
||||
result = s.counter
|
||||
|
||||
proc card*[A](s: HashSet[A]): int =
|
||||
## Alias for `len() <#len,HashSet[A]>`_.
|
||||
##
|
||||
## Card stands for the `cardinality
|
||||
## <http://en.wikipedia.org/wiki/Cardinality>`_ of a set.
|
||||
result = s.counter
|
||||
|
||||
|
||||
proc union*[A](s1, s2: HashSet[A]): HashSet[A] =
|
||||
## Returns the union of the sets `s1` and `s2`.
|
||||
|
||||
11
tests/sets/m17385.nim
Normal file
11
tests/sets/m17385.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
import std/sets
|
||||
|
||||
type
|
||||
Diff*[T] = object
|
||||
data: T
|
||||
|
||||
proc test*[T](diff: Diff[T]) =
|
||||
var bPopular = initHashSet[T]()
|
||||
for element in bPopular.items():
|
||||
echo element
|
||||
|
||||
4
tests/sets/t17385.nim
Normal file
4
tests/sets/t17385.nim
Normal file
@@ -0,0 +1,4 @@
|
||||
import m17385
|
||||
|
||||
let a = Diff[int]()
|
||||
a.test()
|
||||
Reference in New Issue
Block a user