Conversation
|
@orlp this is missing critical functionality. see my MR. sure, I understand now allowing mutable slice to keys, that's fine. but there should still be both [ immutable keys slice, and mutable values slice] provided as output together. this is required by ets. current exposed API makes it impossible to satisfy borrow checker - need explicit disjoint borrow |
|
Hmm I see. I also just noticed that in my earlier discussion I wanted to add I think I'll add these two and probably remove the other |
|
@jagprog5 Fixed in 1.1.1. |
melody-rs
left a comment
There was a problem hiding this comment.
From what I can see this is missing a way to go from key -> value index?
@melody-rs not sure what you mean; the keys and values are in the same arbitrary order so key[i] goes to value[i] |
Sorry, could've explained better! use slotmap::*;
let mut sm = DenseSlotMap::new();
let key = sm.insert(0i32);
let values = sm.values_as_slice();
let value_index = /* get the index of the value in the slice */
let value = values[value_index];
assert_eq!(value, sm[key]);Being able to get the index is useful for copying a |
|
@melody-rs I don't think this is possible since the index isn't stable; it will re-order to compact to contiguous memory if elements are deleted. If you're using the dense slot map and only inserting, then you could use an incrementing counter? double check this. So first insertion is at slice index 0, next one at index 1, ... |
Supersedes #134.
Fixes #131.
Credit to @Swiiz for the examples.