-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.rs
30 lines (24 loc) · 831 Bytes
/
example.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use generational_vector::GenerationalVector;
fn main() {
let mut v = GenerationalVector::default();
// Adding elements.
let a = v.push("first");
let b = v.push("second");
assert_eq!(v.get(&a).unwrap(), &"first");
assert_eq!(v.get(&b).unwrap(), &"second");
// Removing elements.
v.remove(&b);
assert!(v.get(&b).is_none());
// Overwriting a previously freed slot.
let c = v.push("third");
assert_eq!(v.get(&c).unwrap(), &"third");
// The previous index 'b' internally points to the
// same address as c. It uses an older generation however,
// so is considered "not found":
assert_eq!(v.get(&b), None);
// Values can be enumerated.
// Note that the ordering depends on insertions and deletions.
for value in v {
println!("{}", value);
}
}