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

SortedSet remove at index does not work #441

Open
2 tasks done
pnewell opened this issue Dec 22, 2024 · 1 comment
Open
2 tasks done

SortedSet remove at index does not work #441

pnewell opened this issue Dec 22, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@pnewell
Copy link

pnewell commented Dec 22, 2024

Removing items from a SortedSet by index does remove the item, but does not update the count correctly.

Information

  • Package version: main
  • Platform version: macOS 15.3
  • Swift version: 6.0.3

Checklist

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

Steps to Reproduce

let set = Set(0 ..< 40)
var sorted = SortedSet(set)
print(sorted.count)
print(sorted.remove(at: sorted.startIndex))
print(sorted)
print(sorted.count)

Expected behavior

40
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]
0
39

Actual behavior

40
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]
0
40

@pnewell pnewell added the bug Something isn't working label Dec 22, 2024
@pnewell
Copy link
Author

pnewell commented Dec 23, 2024

Been playing around with this more, it ultimately leads to a runtime error the next time it checks its count. An easy way to see that is to convert to an array after the remove.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant