Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect calculating offset for _BTree.findAnyIndex(forKey: Key) #366

Open
1 of 2 tasks
vsviridov123 opened this issue Mar 13, 2024 · 0 comments
Open
1 of 2 tasks
Labels
bug Something isn't working SortedCollections

Comments

@vsviridov123
Copy link

Incorrect calculating offset for _BTree.findAnyIndex(forKey: Key) (347 line)

Hi, i use SortedDictionary for my project and I may found an error. In function _Btree.findAnyIndex.
If there is a slot equal to key, offset does not take into account children’s depth for slots before founded slot.

let keySlot = handle.startSlot(forKey: key)
offset += keySlot

if keySlot < handle.elementCount && handle[keyAt: keySlot] == key {
    return Index(
        node: .passUnretained(storage),
        slot: keySlot,
        childSlots: childSlots,
        offset: offset, 
       forTree: self
    )
} 

Information

  • Package version: main branch
  • Platform version: 17.0
  • Swift version: 5.9

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • I've searched for existing GitHub issues.

Expected behavior

Offset calculates with children’s depth for slots before founded slot.

@vsviridov123 vsviridov123 added the bug Something isn't working label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SortedCollections
Projects
None yet
Development

No branches or pull requests

2 participants