jonhoo / left-right

A lock-free, read-optimized, concurrency primitive.
Apache License 2.0
1.95k stars 94 forks source link

Sorting underlying values vector? #28

Closed serzhiio closed 4 years ago

serzhiio commented 5 years ago

Guys, is it possible to sort values vector without replacing whole array? I mean just make vector.sort() or like that to save new values order?

jonhoo commented 5 years ago

Sadly I think this will be hard to implement in evmap the way it's currently structured. This is a result of a deeper design choice where a single enum is used for all of evmap's operations, regardless of the constraints on V (in this case V: Ord). There isn't a way in Rust to say "this variant exists only if V: Ord", so we can't actually add a sort-like method without always requiring V: Ord.

That said, this may be possible to implement entirely in user code with @novacrazy's #13, though I'm not sure. We'd have to figure out how to let the user modify the vector without giving mutable access to the underlying values. Maybe we could expose an fn sort() where V: Ord that calls remove and then update somehow?

serzhiio commented 5 years ago

@jonhoo it would be nice to have ability to process vector items by index and make insertions/deletings.

serzhiio commented 5 years ago

As i see it now to update vector with few new elements i should .empty() it first and then .insert() all elements onw by one including new one. It looks not efficient!

jonhoo commented 4 years ago

Now that the values are not even necessarily stored in a vector, this is pretty much impossible. We could use a BTreeBag for the values instead of a HashBag, and then require that V: Ord, but that seems like a big change for relatively little gain at the moment.