2024-09-26 15:49:08 +00:00
|
|
|
# stew
|
|
|
|
# Copyright 2019-2024 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
#
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
#
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
{.push raises: [].}
|
2019-07-16 10:17:32 +00:00
|
|
|
|
2024-09-26 15:49:08 +00:00
|
|
|
import std/sets, ../objects, ../templateutils
|
2019-07-16 10:17:32 +00:00
|
|
|
|
|
|
|
template init*[T](_: type HashSet[T]): auto = initHashSet[T]()
|
|
|
|
template init*[T](_: type HashSet[T], defaultSize: int): auto = initHashSet[T](defaultSize)
|
|
|
|
|
|
|
|
# TODO: This should work, but Nim can't handle it
|
|
|
|
# template init*[T](_: type HashSet[T], args: varargs[untyped]): auto = initHashSet[T](args)
|
|
|
|
|
|
|
|
template init*[T](_: type OrderedSet[T]): auto = initOrderedSet[T]()
|
|
|
|
template init*[T](_: type OrderedSet[T], initialSize: int): auto = initOrderedSet[T](initialSize)
|
|
|
|
# template init*[T](_: type OrderedSet[T], args: varargs[untyped]): auto = initOrderedSet[T](args)
|
|
|
|
|
|
|
|
template init*[T](_: type set[T]): auto =
|
|
|
|
var x: set[T]
|
|
|
|
x
|
|
|
|
|
2021-12-02 16:31:59 +00:00
|
|
|
template keepItIf*[T](setParam: var HashSet[T], itPredicate: untyped) =
|
|
|
|
bind evalTemplateParamOnce
|
|
|
|
evalTemplateParamOnce(setParam, s):
|
|
|
|
var itemsToDelete: seq[T]
|
|
|
|
|
|
|
|
for it {.inject.} in s:
|
|
|
|
if not itPredicate:
|
|
|
|
itemsToDelete.add(it)
|
2019-07-16 10:17:32 +00:00
|
|
|
|
2021-12-02 16:31:59 +00:00
|
|
|
for item in itemsToDelete:
|
|
|
|
s.excl item
|
|
|
|
|
|
|
|
export sets, objects
|