skip-list

Crates.ioskip-list
lib.rsskip-list
version0.1.3
sourcesrc
created_at2022-04-25 16:11:55.411675
updated_at2022-04-27 04:14:21.864598
descriptionImplementing a skip list with rust
homepagehttps://github.com/ge-nie/skip-list
repositoryhttps://github.com/ge-nie/skip-list
max_upload_size
id573977
size18,624
ge.xiaonie (gexiaonie)

documentation

https://docs.rs/skip-list

README

skip-list

Implementing a skip list with rust

Examples

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);
Commit count: 10

cargo fmt