Struct cpp_map::LinkedList[][src]

pub struct LinkedList<K, V> where
    K: Debug,
    V: Debug
{ /* fields omitted */ }
Expand description

A double linked min list. The head (top/front) of the list is the first item. Sorted Order::Less than other items. The tail (bottom/back) is the last item of the list. Sorted Order::Greater than other items.

Implementations

Constructs a new, empty LinkedList<K,V> with the specified capacity. The LinkedList will be able to hold exactly capacity elements without reallocating. If capacity is 0, the list will not allocate.

Returns the number of inserted elements

Returns the capacity or the vectors

Returns true if the list is empty

Clears the list. Warning: any Pointer object referring to this list will be corrupted.

Returns the next free index. This value will be invalid if any insert or remove operation is performed on the list.

Returns the item key at index

Returns the item value at index

Returns the item key and value at index

Examples

let mut ll = LinkedList::<i8, i8>::default();
ll.ordered_insert(1,1);
assert!(ll.get(ll.head()).is_ok());
assert_eq!(ll.get(ll.head()).unwrap(), (&1,&1));
ll.ordered_insert(0,0);
assert!(ll.get(ll.head()).is_ok());
assert_eq!(ll.get(ll.head()).unwrap(), (&0,&0));
assert!(ll.get(ll.tail()).is_ok());
assert_eq!(ll.get(ll.tail()).unwrap(), (&1,&1));

Returns the previous key item of item at index

Insert item at position defined by Order (lesser first) This is the same as ‘ordered_insert_pos()’ with self.head_ as position hint Insert item by Order (lesser first) with a position hint.

Note that insert(key, value) is a NOP if the key already exists, not even the new value will be used.

Examples

let mut ll = LinkedList::<i8, i8>::default();
ll.ordered_insert(1,1);
assert!(ll.get(ll.head()).is_ok());
assert_eq!(ll.get(ll.head()).unwrap(), (&1,&1));
ll.ordered_insert(0,0);
assert!(ll.get(ll.head()).is_ok());
assert_eq!(ll.get(ll.head()).unwrap(), (&0,&0));
ll.ordered_insert(0,100); // <- this is a NOP
assert!(ll.get(ll.head()).is_ok());
assert_eq!(ll.get(ll.head()).unwrap(), (&0,&0));

Insert item by Order (lesser first) with a position hint. Note that insert(key, value) is a NOP if the key already exists, not even the new value will be used.

Examples

let mut ll = LinkedList::<i8, i8>::default();
ll.ordered_insert(1,1);
ll.ordered_insert_pos(2,2,0);
assert!(ll.get(ll.head()).is_ok());
assert_eq!(ll.get(ll.head()).unwrap(), (&1,&1));
assert!(ll.get(ll.tail()).is_ok());
assert_eq!(ll.get(ll.tail()).unwrap(), (&2,&2));

Returns the first element in the container whose key is not considered to go before position (i.e., either it is equivalent or goes after). If ‘search_from_head’ is true the search will be performed from the head otherwise from the tail. Returns None if no data is found

Examples

let mut ll = LinkedList::<i8, i8>::default();
ll.ordered_insert(1,1);
ll.ordered_insert(2,2);
ll.ordered_insert(3,3);
let lb = ll.get(ll.lower_bound(2).unwrap().unwrap()).unwrap();
assert_eq!(lb, (&2,&2));
let lb = ll.get(ll.lower_bound(0).unwrap().unwrap()).unwrap();
assert_eq!(lb, (&1,&1));
let lb = ll.get(ll.lower_bound(1).unwrap().unwrap()).unwrap();
assert_eq!(lb, (&1,&1));
let lb = ll.get(ll.lower_bound(3).unwrap().unwrap()).unwrap();
assert_eq!(lb, (&3,&3));
assert!( ll.lower_bound(4).unwrap().is_none());

Pop the head item

Examples

let mut ll = LinkedList::<i8, i8>::default();
let _ = ll.ordered_insert(1, 0); // 0
let _ = ll.ordered_insert(2, 1); // 1
assert_eq!(ll.pop_front().unwrap().unwrap(), (1_i8,0_i8));
assert_eq!(ll.pop_front().unwrap().unwrap(), (2_i8,1_i8));

Pop the tail item

Examples

let mut ll = LinkedList::<i8, i8>::default();
let _ = ll.ordered_insert(1, 0); // 0
let _ = ll.ordered_insert(2, 1); // 1
assert_eq!(ll.pop_back().unwrap().unwrap(), (2_i8,1_i8));
assert_eq!(ll.pop_back().unwrap().unwrap(), (1_i8,0_i8));

Peek the head key

Examples

let mut ll = LinkedList::<i8, i8>::default();
let _ = ll.ordered_insert(1, 0); // 0
let _ = ll.ordered_insert(2, 1); // 1
assert_eq!(ll.peek_front_k().unwrap(), &1_i8);

Peek the tail key

Examples

let mut ll = LinkedList::<i8, i8>::default();
let _ = ll.ordered_insert(1, 0); // 0
let _ = ll.ordered_insert(2, 1); // 1
assert_eq!(ll.peek_back_k().unwrap(), &2_i8);

Return the tail index

Return the head index

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.