vector - What's the best choice for non-resizable dynamic length arrays in Rust? -


i'm re-implementing hashtable in rust. i'd make distributed , have quorums, it's hashtable on single system.

i want size of table passed in argument table should dynamically sized. don't want table grow because mess hash function works off modulo operation. see couple of options:

  1. arrays - cannot dynamically sized
  2. vectors - can grow
  3. slices - can dynamically sized & can't grow, views onto vecs , arrays, i'll need vec/array anyways?

in c++, have used dynamically sized array. what's best choice here?

a boxed slice dynamically sized, length cannot changed once created, , owns contained data:

let the_vec: vec<i32> = vec![1, 2, 3]; let the_boxed_slice: box<[i32]> = the_vec.into_boxed_slice(); 

the types aren't required here, present pedagogical reasons.


however, it's dubious whether performance benefit. vec 3 pointer sized values (data, size, capacity). box<[t]> two: data , size. overhead of having value minuscule in cases.

the main benefit statically guaranteed size won't change; won't statically know it's size. such guarantee might happen if type-level numbers ever happen.

see also:


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -