vector-growing

Crates.iovector-growing
lib.rsvector-growing
version0.1.0
sourcesrc
created_at2024-09-30 14:44:07.108291
updated_at2024-09-30 14:44:07.108291
descriptionThe growing vector with free indexes.
homepagehttps://github.com/MayorDi/vector-growing
repositoryhttps://github.com/MayorDi/vector-growing
max_upload_size
id1391792
size21,627
Dmitriy Mayorov (MayorDi)

documentation

README

VecGrow

It is similar to a regular Vec, with one exception - the size is not reduced. VecGrow can constantly grow, but not decrease, and when objects are deleted, their place remains for the new object as a free index, which eases the memory power in the case of permanent deletion and creation of objects.

Examples

use vector_growing::*;

let mut vg = VecGrow::new();
vg.push(1);
vg.push(2);

assert_eq!(vg[0], Some(1));
assert_eq!(vg[1], Some(2));

vg.remove(0);

assert_eq!(vg[0], None);

vg.push(1);

assert_eq!(vg[0], Some(1));

Initializing VecGrow using a macro:

use vector_growing::*;

let vg_empty: VecGrow<u8> = vec_grow![];
let vg_num = vec_grow![1, 2, 3];
let vg_zero = vec_grow![0; 100];

assert!(vg_empty.is_empty());
assert_eq!(vg_num[1], Some(2));
assert_eq!(vg_zero[99], Some(0));
Commit count: 2

cargo fmt