Skip to content

Add SortedLinearMap#658

Open
extremeandy wants to merge 1 commit intorust-embedded:mainfrom
extremeandy:sorted-linear-map
Open

Add SortedLinearMap#658
extremeandy wants to merge 1 commit intorust-embedded:mainfrom
extremeandy:sorted-linear-map

Conversation

@extremeandy
Copy link
Copy Markdown

@extremeandy extremeandy commented Apr 23, 2026

A fixed-capacity map that keeps entries sorted by key and performs lookups via binary search - the BTreeMap analogue of LinearMap.

There might be a better name for this - I don't really like SortedLinearMap but couldn't decide what else to call it.

This is slower for inserts (O(n)) but faster for lookups (O(log(n)) than LinearMap. Works well for data with low frequency writes and high frequency reads.

Includes BTreeMap-style APIs: first_key_value/last_key_value, pop_first/pop_last, range/range_mut, plus the usual entry API, retain, Serialize/Deserialize, and Zeroize support.

This was the prompt I used to kick off the work:

i want to add a SortedLinearMap which is the BTreeMap equivalent that HashMap is to LinearMap.
inserts and reads should use a binary search to find the entry. the API should otherwise be quite similar to LinearMap.

I reviewed changes, made some minor tweaks, and had Claude review it as well.

A fixed-capacity map that keeps entries sorted by key and performs
lookups via binary search - the BTreeMap analogue of LinearMap.

Includes BTreeMap-style APIs: first_key_value/last_key_value,
pop_first/pop_last, range/range_mut, plus the usual entry API,
retain, Serialize/Deserialize, and Zeroize support.

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