Skip to content

Commit

Permalink
ordsets bump since to 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
landerlo committed Oct 19, 2020
1 parent d85d00a commit 4b81ab3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 1 addition & 9 deletions lib/pure/collections/intsets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@
# distribution, for details about the copyright.
#

## Deprecated by the generic `OrdSet` for ordinal sparse sets.
## Deprecated by the generic `OrdSet` for ordinal sparse set
## **See also:**
## * `ordinal sets module <ordsets.html>`_ for more general int sets

import std/private/since
import std/ordsets
export ordsets

type
IntSet* = OrdSet[int]

proc toIntSet*(x: openArray[int]): IntSet {.since: (1, 3), inline.} = toOrdSet[int](x)

proc initIntSet*(): IntSet {.inline.} = initOrdSet[int]()

16 changes: 14 additions & 2 deletions lib/std/ordsets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ iterator items*[A](s: OrdSet[A]): A {.inline.} =
inc(i)
r = r.next

proc initOrdSet*[A]: OrdSet[A] =
proc initOrdSet*[A]: OrdSet[A] {.since: (1, 5).} =
## Returns an empty OrdSet[A].
## A must be an ordinal equivalent type: int | enum | distinct int
##
Expand Down Expand Up @@ -268,7 +268,7 @@ proc incl*[A](s: var OrdSet[A], other: OrdSet[A]) =

for item in other: incl(s, item)

proc toOrdSet*[A](x: openArray[A]): OrdSet[A] {.since: (1, 3).} =
proc toOrdSet*[A](x: openArray[A]): OrdSet[A] {.since: (1, 5).} =
## Creates a new OrdSet[A] that contains the elements of `x`.
##
## Duplicates are removed.
Expand Down Expand Up @@ -607,6 +607,18 @@ proc `$`*[A](s: OrdSet[A]): string =
## Converts the set `s` to a string, mostly for logging and printing purposes.
dollarImpl()

# For backward compatibility with intsets ( before version 1.5 )
# we provide concrete methods for intset
type IntSet* = OrdSet[int]
proc toIntSet*(x: openArray[int]): IntSet {.since: (1, 3), inline.} = toOrdSet[int](x)
proc initIntSet*(): IntSet =
# This is initOrdSet[int]() but would require since 1.5 to pass tests
result = IntSet(
elems: 0,
counter: 0,
max: 0,
head: nil,
data: when defined(nimNoNilSeqs): @[] else: nil)


when isMainModule:
Expand Down

0 comments on commit 4b81ab3

Please sign in to comment.