Crates.io | vector-growing |
lib.rs | vector-growing |
version | 0.1.0 |
source | src |
created_at | 2024-09-30 14:44:07.108291 |
updated_at | 2024-09-30 14:44:07.108291 |
description | The growing vector with free indexes. |
homepage | https://github.com/MayorDi/vector-growing |
repository | https://github.com/MayorDi/vector-growing |
max_upload_size | |
id | 1391792 |
size | 21,627 |
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.
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));