critbits: don't rely on terminating zero
This commit is contained in:
parent
b899713832
commit
c8b2e65dbb
1 changed files with 4 additions and 3 deletions
|
|
@ -74,8 +74,9 @@ proc rawInsert[T](c: var CritBitTree[T], key: string): Node[T] =
|
||||||
var newByte = 0
|
var newByte = 0
|
||||||
block blockX:
|
block blockX:
|
||||||
while newbyte < key.len:
|
while newbyte < key.len:
|
||||||
if newbyte >= it.key.len or it.key[newbyte] != key[newbyte]:
|
let ch = if newbyte < it.key.len: it.key[newbyte] else: '\0'
|
||||||
newotherbits = it.key[newbyte].ord xor key[newbyte].ord
|
if ch != key[newbyte]:
|
||||||
|
newotherbits = ch.ord xor key[newbyte].ord
|
||||||
break blockX
|
break blockX
|
||||||
inc newbyte
|
inc newbyte
|
||||||
if newbyte < it.key.len:
|
if newbyte < it.key.len:
|
||||||
|
|
@ -85,7 +86,7 @@ proc rawInsert[T](c: var CritBitTree[T], key: string): Node[T] =
|
||||||
while (newOtherBits and (newOtherBits-1)) != 0:
|
while (newOtherBits and (newOtherBits-1)) != 0:
|
||||||
newOtherBits = newOtherBits and (newOtherBits-1)
|
newOtherBits = newOtherBits and (newOtherBits-1)
|
||||||
newOtherBits = newOtherBits xor 255
|
newOtherBits = newOtherBits xor 255
|
||||||
let ch = it.key[newByte]
|
let ch = if newByte < it.key.len: it.key[newByte] else: '\0'
|
||||||
let dir = (1 + (ord(ch) or newOtherBits)) shr 8
|
let dir = (1 + (ord(ch) or newOtherBits)) shr 8
|
||||||
|
|
||||||
var inner: Node[T]
|
var inner: Node[T]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue