-
Notifications
You must be signed in to change notification settings - Fork 185
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
Impl Extend for LiteMap and avoid quadratic behavior in from_iter and deserialize #6132
base: main
Are you sure you want to change the base?
Impl Extend for LiteMap and avoid quadratic behavior in from_iter and deserialize #6132
Conversation
82433f8
to
1f7e87a
Compare
1f7e87a
to
8bd4d3e
Compare
// Note: this effectively selection sorts the map, | ||
// which isn't efficient for large maps | ||
map.insert(key, value); | ||
out_of_order.push((key, value)); |
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 considered making this based on StoreMut::lm_push
and Store::lm_into_iter
by adding the StoreIntoIterator
bound to R, but that would be a breaking change.
@@ -43,7 +44,7 @@ criterion = { workspace = true } | |||
default = ["alloc"] | |||
alloc = [] | |||
databake = ["dep:databake"] | |||
serde = ["dep:serde"] | |||
serde = ["dep:serde", "alloc"] |
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.
Note for reviewers: The addition of alloc was theoretically a breaking change for people using "no default features" so we may want to bump litemap to 0.8.
@@ -133,6 +133,24 @@ pub trait StoreMut<K, V>: Store<K, V> { | |||
} | |||
} | |||
} | |||
|
|||
/// Extends this store with items from an iterator. | |||
fn lm_extend<I>(&mut self, other: I) |
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.
issue: having the quadratic algorithm in the default implementation is a footgun. same for lm_retain
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.
To clarify, are you suggesting that the default impl for lm_extend and lm_retain* should be removed?
*
not part of the PR
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.
yes
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.
(if we're happy to make breaking changes)
d239648
to
78edff4
Compare
Adds
lm_extend
to theStoreMut
trait. The Vec implementation is optimized to have O(N) performance on sorted inputs and an asymptotic worst case of O(NLog(N)), effectively avoiding quadratic worst cases.This PR takes advantage of the new
extend
optimization and changes theFromIterator
andDeserialize
implementations to also avoid quadratic worst-case.Before
After
This is a followup of #6068