Crates.io | skip-list |
lib.rs | skip-list |
version | 0.1.3 |
source | src |
created_at | 2022-04-25 16:11:55.411675 |
updated_at | 2022-04-27 04:14:21.864598 |
description | Implementing a skip list with rust |
homepage | https://github.com/ge-nie/skip-list |
repository | https://github.com/ge-nie/skip-list |
max_upload_size | |
id | 573977 |
size | 18,624 |
Implementing a skip list with rust
let mut skip_list = SkipList::default();
// insert
assert_eq!(skip_list.insert(1, 10), None); // there is no value with key with 1
assert_eq!(skip_list.insert(2, 20), None);
assert_eq!(skip_list.insert(3, 30), None);
// get
assert_eq!(skip_list.get(&1), Some(&10));
assert_eq!(skip_list.get(&2), Some(&20));
assert_eq!(skip_list.get(&3), Some(&30));
// update
assert_eq!(skip_list.insert(1, 100), Some(10)); // return old data
assert_eq!(skip_list.insert(2, 200), Some(20));
assert_eq!(skip_list.insert(3, 300), Some(30));
// iterator
for (k, v) in skip_list.iter() {
let value = k * 100;
assert_eq!(*v, value);
}
// delete
assert_eq!(skip_list.delete(&1), Some(100));
assert_eq!(skip_list.delete(&10), None);
assert_eq!(skip_list.get(&1), None);