Fix stupid condition when removing items
eacasanovaspedre opened this issue · comments
The if conditions are wrong. children is never empty, since it's the array of children when the node is a Branch, it's never empty and I ask if it's empty.
I have to ask if the newBitmap
is empty instead.
The same happens for the elif condition. It's length is never 1. I must ask whether the newBitmap
contains only one bit on.
| Branch (bitmap, children) ->
let bitIndex = childBitIndex prefix
if containsChild bitIndex bitmap then
let childArrayIndex = childArrayIndex bitIndex bitmap
match remove eqComparer targetKey targetHash (nextLayerPrefix prefix) (Array.item childArrayIndex children)
with
| NotFound -> NotFound
| Removed child -> Removed(Branch(bitmap, Array.put child childArrayIndex children))
| NothingLeft ->
let newBitmap = Bitmap.clearBit bitIndex bitmap
if Array.isEmpty children then
NothingLeft
elif Array.length children = 1 then
Removed(Array.head children)
else
Removed(Branch(newBitmap, Array.remove childArrayIndex children))
else
NotFound