gen-vec 0.3.0

Vector indexed with generational indices
Documentation
  • Coverage
  • 94.44%
    34 out of 36 items documented24 out of 32 items with examples
  • Size
  • Source code size: 52.41 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 8.26 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Mnenmenth/gen-vec-rs
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Mnenmenth

gen-vec Build Status

Vector of reusable, generational indices that owns its values

Inspired by Catherine West's closing keynote at RustConf 2018

Closed vs. Exposed index allocation implementations

ClosedGenVec uses a non user-accessible index allocator to manage indices

ExposedGenVec relies on an external IndexAllocator

As such, an IndexAllocator must be created and used to allocate/deallocate indices manually. This is useful for using the same Index across multiple ExposedGenerationalVec instances

Note: IndexAllocator cannot be used with ClosedGenerationalVec since it has its own internal IndexAllocator

Explanation of Generational Indices

Index structs are used to access the vector's contents. An Index contains an index for the vector and a generation (which is 0 initially).

Deallocated/removed Indexs go into a list of free Indexs that can be reused

Every time an Index is reused, the internal generation is incremented. This ensures that a deallocated Index handle can't access data that it no longer validly points to

Usage

Add gen-vec to your Cargo.toml

[dependencies]

gen-vec = "0.2.0"

Using the self-allocating ClosedGenVec

use gen_vec::Index;
use gen_vec::closed::ClosedGenVec;

let mut vec: ClosedGenVec<i32> = ClosedGenVec::new();

let index: Index = vec.insert(42);
assert!(vec.contains(index));

let value: Option<&i32> = vec.get(index);
assert_eq!(value, Some(&42));

vec.remove(index);
assert!(!vec.contains(index));

Using ExposedGenVec with IndexAllocator

use gen_vec::Index;
use gen_vec::exposed::{IndexAllocator, ExposedGenVec};

let mut allocator: IndexAllocator = IndexAllocator::new();

let index: Index = allocator.allocate();

let mut vec: ExposedGenVec<i32> = ExposedGenVec::new();
vec.set(index, 5);
assert!(vec.contains(index));

let value: Option<&i32> = vec.get(index);
assert_eq!(value, Some(&5));