pub struct SkipList<K, V> { /* private fields */ }

Implementations

Create a skip list with max level

Example
use skip_list::SkipList;
let mut skiplist: SkipList<i32, i32> = SkipList::new(12);

Returns a reference to the value of the key in skip list or None if not exist.

Example
use skip_list::SkipList;
 
let mut skip_list = SkipList::default();
 
skip_list.insert(1, "a");
 
assert_eq!(skip_list.get(&1), Some(&"a"));

Insert a key-value pair into skip list. If the key already exists, updates key’s value and return old value. Otherwise, None is returned.

Example
use skip_list::SkipList;
 
let mut skip_list = SkipList::default();
 
assert_eq!(skip_list.insert(1, "a"), None);
assert_eq!(skip_list.get(&1), Some(&"a"));
assert_eq!(skip_list.insert(1, "aa"), Some("a"));
assert_eq!(skip_list.get(&1), Some(&"aa"));
 

Deletes and returns the key’s value from skip list or None if not exist.

Example
use skip_list::SkipList;
 
let mut skip_list = SkipList::default();
 
assert_eq!(skip_list.insert(1, "a"), None);
assert_eq!(skip_list.get(&1), Some(&"a"));
assert_eq!(skip_list.delete(&1), Some("a"));
assert_eq!(skip_list.get(&1), None);

Visit all key-value pairs in the order of keys The Iterator element type is (&K, &V).

Example
use skip_list::SkipList;
 
let mut skip_list = SkipList::default();
assert_eq!(skip_list.insert(3, "c"), None);
assert_eq!(skip_list.insert(4, "d"), None);
assert_eq!(skip_list.insert(2, "b"), None);
assert_eq!(skip_list.insert(5, "e"), None);
assert_eq!(skip_list.insert(1, "a"), None);
 
// visit all key-value paris in the order of keys
let mut keys = vec![];
let mut values = vec![];
for (k, v) in skip_list.iter() {
    keys.push(k);
    values.push(v);
}
 
// check key sorted
assert_eq!(keys, vec![&1, &2, &3, &4, &5]);
assert_eq!(values, vec![&"a", &"b", &"c", &"d", &"e"]);

Visit all key-value pairs in the order of keys The Iterator element type is (&K, &mut V). The value is mut, can be update;

Example
use skip_list::SkipList;
 
let mut skip_list = SkipList::default();
assert_eq!(skip_list.insert(3, 3), None);
assert_eq!(skip_list.insert(4, 4), None);
assert_eq!(skip_list.insert(2, 2), None);
assert_eq!(skip_list.insert(5, 5), None);
assert_eq!(skip_list.insert(1, 1), None);
 
for (k, v) in skip_list.iter_mut() {
    *v = k * 10;
}
// visit all key-value paris in the order of keys
let mut keys = vec![];
let mut values = vec![];
for (k, v) in skip_list.iter() {
    keys.push(k);
    values.push(v);
}
 
// check key sorted
assert_eq!(keys, vec![&1, &2, &3, &4, &5]);
assert_eq!(values, vec![&10, &20, &30, &40, &50]);

Trait Implementations

Create a skip list with max level(12)

Example
use skip_list::SkipList;
let mut skiplist: SkipList<i32, i32> = SkipList::default();

Executes the destructor for this type. Read more

Visit all key-value pairs in the order of keys The Iterator element type is (K, V).

Example
use skip_list::SkipList;
 
let mut skip_list = SkipList::default();
assert_eq!(skip_list.insert(3, "c"), None);
assert_eq!(skip_list.insert(4, "d"), None);
assert_eq!(skip_list.insert(2, "b"), None);
assert_eq!(skip_list.insert(5, "e"), None);
assert_eq!(skip_list.insert(1, "a"), None);
 
// visit all key-value paris in the order of keys
let mut keys = vec![];
let mut values = vec![];
for (k, v) in skip_list.into_iter() {
    keys.push(k);
    values.push(v);
}
 
// check key sorted
assert_eq!(keys, vec![1, 2, 3, 4, 5]);
assert_eq!(values, vec!["a", "b", "c", "d", "e"]);

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.