allocvec 1.1.0

A vector type that preserves the index of every inserted element
Documentation
  • Coverage
  • 95.45%
    21 out of 22 items documented0 out of 21 items with examples
  • Size
  • Source code size: 17.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.38 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • bohdloss/allocvec
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bohdloss

AllocVec

Crates IO AllocVec

A vector where each element pushed is guaranteed to keep its index until it is removed.

Internally, a normal Vec is used along with a linked list for fast allocation and de-allocation.

Example

use allocvec::AllocVec;

let mut vec = AllocVec::new();
let idx1 = vec.alloc(4);
let idx2 = vec.alloc(8);
let idx3 = vec.alloc(15);

vec.dealloc(idx1);
vec.dealloc(idx3);

assert_eq!(Some(8), vec.get(idx2));

Speed

Though I haven't benchmarked the efficiency of the implementation, allocation, deallocation and indexing are O(1) operations, while calculating the length of the vector is O(n).

Iterators need to filter unallocated slots in the vector, so that will most likely be bad for branch prediction.