diff options
-rw-r--r-- | changelog.md | 9 | ||||
-rw-r--r-- | lib/pure/collections/critbits.nim | 38 |
2 files changed, 19 insertions, 28 deletions
diff --git a/changelog.md b/changelog.md index 0705d0090..285977488 100644 --- a/changelog.md +++ b/changelog.md @@ -46,8 +46,8 @@ - Added `asyncdispatch.activeDescriptors` that returns the number of currently active async event handles/file descriptors. -- ``--gc:orc`` is now 10% faster than previously for common workloads. If - you have trouble with its changed behavior, compile with ``-d:nimOldOrc``. +- `--gc:orc` is now 10% faster than previously for common workloads. If + you have trouble with its changed behavior, compile with `-d:nimOldOrc`. - `os.FileInfo` (returned by `getFileInfo`) now contains `blockSize`, @@ -96,11 +96,10 @@ with other backends. see #9125. Use `-d:nimLegacyJsRound` for previous behavior. - Added `socketstream` module that wraps sockets in the stream interface - - - - Added `math.signbit`. +- Removed the optional `longestMatch` parameter of the `critbits._WithPrefix` iterators (it never worked reliably) + ## Language changes - `nimscript` now handles `except Exception as e`. diff --git a/lib/pure/collections/critbits.nim b/lib/pure/collections/critbits.nim index 113939567..000ea5080 100644 --- a/lib/pure/collections/critbits.nim +++ b/lib/pure/collections/critbits.nim @@ -390,8 +390,7 @@ iterator mpairs*[T](c: var CritBitTree[T]): tuple[key: string, val: var T] = ## * `pairs iterator <#pairs.i,CritBitTree[T]>`_ for x in leaves(c.root): yield (x.key, x.val) -proc allprefixedAux[T](c: CritBitTree[T], key: string; - longestMatch: bool): Node[T] = +proc allprefixedAux[T](c: CritBitTree[T], key: string): Node[T] = var p = c.root var top = p if p != nil: @@ -401,13 +400,11 @@ proc allprefixedAux[T](c: CritBitTree[T], key: string; let dir = (1 + (ch.ord or p.otherBits.ord)) shr 8 p = p.child[dir] if q.byte < key.len: top = p - if not longestMatch: - for i in 0 ..< key.len: - if i >= p.key.len or p.key[i] != key[i]: return + for i in 0 ..< key.len: + if i >= p.key.len or p.key[i] != key[i]: return result = top -iterator keysWithPrefix*[T](c: CritBitTree[T], prefix: string; - longestMatch = false): string = +iterator keysWithPrefix*[T](c: CritBitTree[T], prefix: string): string = ## Yields all keys starting with `prefix`. runnableExamples: from sequtils import toSeq @@ -415,11 +412,10 @@ iterator keysWithPrefix*[T](c: CritBitTree[T], prefix: string; let c = {"key1": 42, "key2": 43}.toCritBitTree doAssert toSeq(c.keysWithPrefix("key")) == @["key1", "key2"] - let top = allprefixedAux(c, prefix, longestMatch) + let top = allprefixedAux(c, prefix) for x in leaves(top): yield x.key -iterator valuesWithPrefix*[T](c: CritBitTree[T], prefix: string; - longestMatch = false): T = +iterator valuesWithPrefix*[T](c: CritBitTree[T], prefix: string): T = ## Yields all values of `c` starting with `prefix` of the ## corresponding keys. ## @@ -431,28 +427,25 @@ iterator valuesWithPrefix*[T](c: CritBitTree[T], prefix: string; let c = {"key1": 42, "key2": 43}.toCritBitTree doAssert toSeq(c.valuesWithPrefix("key")) == @[42, 43] - let top = allprefixedAux(c, prefix, longestMatch) + let top = allprefixedAux(c, prefix) for x in leaves(top): yield x.val -iterator mvaluesWithPrefix*[T](c: var CritBitTree[T], prefix: string; - longestMatch = false): var T = +iterator mvaluesWithPrefix*[T](c: var CritBitTree[T], prefix: string): var T = ## Yields all values of `c` starting with `prefix` of the ## corresponding keys. The values can be modified. ## ## **See also:** ## * `valuesWithPrefix iterator <#valuesWithPrefix.i,CritBitTree[T],string>`_ - let top = allprefixedAux(c, prefix, longestMatch) + let top = allprefixedAux(c, prefix) for x in leaves(top): yield x.val -iterator itemsWithPrefix*[T](c: CritBitTree[T], prefix: string; - longestMatch = false): string = +iterator itemsWithPrefix*[T](c: CritBitTree[T], prefix: string): string = ## Alias for `keysWithPrefix <#keysWithPrefix.i,CritBitTree[T],string>`_. - let top = allprefixedAux(c, prefix, longestMatch) + let top = allprefixedAux(c, prefix) for x in leaves(top): yield x.key iterator pairsWithPrefix*[T](c: CritBitTree[T], - prefix: string; - longestMatch = false): tuple[key: string, val: T] = + prefix: string): tuple[key: string, val: T] = ## Yields all (key, value)-pairs of `c` starting with `prefix`. ## ## **See also:** @@ -463,18 +456,17 @@ iterator pairsWithPrefix*[T](c: CritBitTree[T], let c = {"key1": 42, "key2": 43}.toCritBitTree doAssert toSeq(c.pairsWithPrefix("key")) == @[(key: "key1", val: 42), (key: "key2", val: 43)] - let top = allprefixedAux(c, prefix, longestMatch) + let top = allprefixedAux(c, prefix) for x in leaves(top): yield (x.key, x.val) iterator mpairsWithPrefix*[T](c: var CritBitTree[T], - prefix: string; - longestMatch = false): tuple[key: string, val: var T] = + prefix: string): tuple[key: string, val: var T] = ## Yields all (key, value)-pairs of `c` starting with `prefix`. ## The yielded values can be modified. ## ## **See also:** ## * `pairsWithPrefix iterator <#pairsWithPrefix.i,CritBitTree[T],string>`_ - let top = allprefixedAux(c, prefix, longestMatch) + let top = allprefixedAux(c, prefix) for x in leaves(top): yield (x.key, x.val) func `$`*[T](c: CritBitTree[T]): string = |