Skip to content

feat: Add SortedVecMap and SortedVecSet#67

Open
extremeandy wants to merge 1 commit into
martinohmann:mainfrom
extremeandy:add-sorted-vec-map
Open

feat: Add SortedVecMap and SortedVecSet#67
extremeandy wants to merge 1 commit into
martinohmann:mainfrom
extremeandy:add-sorted-vec-map

Conversation

@extremeandy
Copy link
Copy Markdown

Introduces BTreeMap/BTreeSet-style counterparts to VecMap/VecSet that keep entries sorted by key. Lookups and inserts use binary search; iteration follows sort order.

  • New SortedKeyedVecSet backing type in src/sorted_keyed/ (sibling of keyed/), reusing the Keyed trait.
  • SortedVecMap in src/sorted_map/ with Entry API (VacantEntry remembers the binary-search insertion index to avoid a second search), Range and RangeMut iterators, BTreeMap-style first_key_value/last_key_value/ pop_first/pop_last, binary_search_* and partition_point helpers.
  • SortedVecSet in src/sorted_set/ with a Range iterator and the usual union/intersection/difference/symmetric_difference.
  • Bounds: K: Ord for key-dependent operations; borrowed-lookup queries use Q: Ord + ?Sized.
  • No insert_at, swap_remove*, swap_indices, reverse, sort_*, or MutableKeys since these would fight the sort invariant.

Introduces BTreeMap/BTreeSet-style counterparts to VecMap/VecSet that keep
entries sorted by key. Lookups and inserts use binary search; iteration
follows sort order.

- New SortedKeyedVecSet backing type in src/sorted_keyed/ (sibling of
  keyed/), reusing the Keyed trait.
- SortedVecMap in src/sorted_map/ with Entry API (VacantEntry remembers
  the binary-search insertion index to avoid a second search), Range and
  RangeMut iterators, BTreeMap-style first_key_value/last_key_value/
  pop_first/pop_last, binary_search_* and partition_point helpers.
- SortedVecSet in src/sorted_set/ with a Range iterator and the usual
  union/intersection/difference/symmetric_difference.
- Bounds: K: Ord for key-dependent operations; borrowed-lookup queries
  use Q: Ord + ?Sized.
- No insert_at, swap_remove*, swap_indices, reverse, sort_*, or
  MutableKeys since these would fight the sort invariant.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant