-
Notifications
You must be signed in to change notification settings - Fork 176
Add insert_sorted_by{,_key}
methods for map/set
#402
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
base: main
Are you sure you want to change the base?
Conversation
/// | ||
/// This is equivalent to finding the position with | ||
/// [`binary_search_by`][Self::binary_search_by], then calling | ||
/// [`insert_before`][Self::insert_before] for a new key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The insertion call is not just for new keys.
/// [`insert_before`][Self::insert_before] for a new key. | |
/// [`insert_before`][Self::insert_before] with the given key and value. |
/// | ||
/// This is equivalent to finding the position with | ||
/// [`binary_search_by_key`][Self::binary_search_by_key] with `cmp(key)`, then | ||
/// calling [`insert_before`][Self::insert_before] for a new key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// calling [`insert_before`][Self::insert_before] for a new key. | |
/// calling [`insert_before`][Self::insert_before] with the given key and value. |
/// | ||
/// If the sorted item is found in the set, it returns the index of that | ||
/// existing item and `false`. Otherwise, it inserts the new item and | ||
/// returns its sorted index and `true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph needs adjustment because existing items also move -- or maybe just leave it out like you did with the map method.
/// | ||
/// If the sorted item is found in the set, it returns the index of that | ||
/// existing item and `false`. Otherwise, it inserts the new item and | ||
/// returns its sorted index and `true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, either update or remove this paragraph.
let values: Vec<_> = map.iter().map(|(k,v)|(*k,*v)).collect(); | ||
map.sort_by_cached_key(|key, _| key.abs()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better for this to sort the original values
as a more independent check.
Resolves #401.