Comments (4)
If you're still interested, could you give #294 a try?
I tested it and it works well, thanks!
from indexmap.
there could also be some method that could insert an item to a particular index, so the behavior of splice could be replicated.
That's #173 -- the core pieces are there with move_index
, at least. But it would be inefficient if you are inserting many items this way.
Currently, I do the following to replicate the behavior:
let end_part = inner_index.split_off(position); inner_index.extend(new_items.chain(end_part.into_iter().skip(n_removed)));
This is not bad, although we could avoid some extra hashing if we did this internally.
However, if new_items
and end_part
have any overlapping keys, the latter will replace its value. I would expect you actually want the keep the new_items
value -- or maybe you're just sure there's no overlap in your scenario.
let end_part = inner_index.split_off(position);
// this may overlap the beginning keys -- should they move?
inner_index.extend(new_items);
for (key, value) in end_part.into_iter().skip(n_removed) {
// This will avoid clobbering any new_items, but should they be
// in their old (shifted/relative) position or the new spliced position?
inner_index.entry(key).or_insert(value);
}
from indexmap.
or maybe you're just sure there's no overlap in your scenario.
Yep, in my use case, it is ensured that there are no duplicate keys.
In general, though, I would expect existing keys to stay where they are; only unique keys are put on the gap, and the non-unique ones are simply used to update existing values at both ends. But, the behavior may be unexpected and might not overlap with other use cases.
A better alternative, I think, is to insert only unique keys (i.e., keys that are not on the map) on the gap, and return the non-unique keys as an iterator, so the caller could choose to use them to update values on the map explicitly, simply ignore them, or use them to assert that all items are inserted on the gap.
from indexmap.
If you're still interested, could you give #294 a try?
from indexmap.
Related Issues (20)
- error[E0152]: duplicate lang item in crate `std` (which `indexmap` depends on): `panic_impl`. HOT 4
- ICE from indexmap or its dependency hashbrown HOT 4
- Using new seems impossible with FxBuildHasher HOT 2
- Exposing with_capacity with custom hasher? HOT 3
- Benchmark results HOT 1
- Ordered Serialization HOT 3
- `binary_search` and `partition_point` on `Slice` HOT 4
- Feature request: Add Index<usize> to Keys HOT 1
- Implement (behind a feature branch) the Merge Crate HOT 4
- IndexMap doesn't implement `Hash` HOT 1
- Compilation bug HOT 1
- Organization / repo home HOT 12
- Doc link on crates.io is dead. HOT 3
- Kaspersky detected the indexmap build-script exe as malware (false positive) HOT 1
- MutableKeys for IndexSet HOT 2
- implement get_many_mut HOT 1
- serde_json::to_string serializes (key, value) HOT 3
- Request: add example to README
- Thanks :)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from indexmap.