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