pub trait BinarySearchTree<K, V, Ix = DefaultIndexType>{
// Required methods
fn insert_pos(&self, key: K) -> Option<(NodeIndex, Ordering)>;
fn insert(&mut self, key: K, value: V) -> Option<V>;
fn remove(&mut self, key: K) -> Option<V>;
fn contains_key(&self, key: K) -> bool;
fn get(&self, key: K) -> Option<&V>;
fn get_mut(&mut self, key: K) -> Option<&mut V>;
fn index(&self, key: K) -> Option<NodeIndex<Ix>>;
fn key(&self, node: NodeIndex<Ix>) -> Option<&K>;
}
Expand description
This trait defines the fundamental operations of a binary search tree.
Required Methods§
Sourcefn insert_pos(&self, key: K) -> Option<(NodeIndex, Ordering)>
fn insert_pos(&self, key: K) -> Option<(NodeIndex, Ordering)>
Returns the insertion point for a given key
. None
is returned, if the tree is empty,
otherwise an index to a node is returned together with the result of the comparison
against its key.
Sourcefn insert(&mut self, key: K, value: V) -> Option<V>
fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair into the tree. If the tree did not have this key
present, None
is returned. If the tree did have this key
present, the value is updated, and the old
value is returned. Note that in this situation, the key is left unchanged.
Sourcefn remove(&mut self, key: K) -> Option<V>
fn remove(&mut self, key: K) -> Option<V>
Removes a key
from the tree if present, in this case returning the associated value.
Sourcefn contains_key(&self, key: K) -> bool
fn contains_key(&self, key: K) -> bool
Returns true
if the map contains a value for the specified key
.
Sourcefn get(&self, key: K) -> Option<&V>
fn get(&self, key: K) -> Option<&V>
Returns an immutable reference to the associated value of the specified key
.
Sourcefn get_mut(&mut self, key: K) -> Option<&mut V>
fn get_mut(&mut self, key: K) -> Option<&mut V>
Returns a mutable reference to the associated value of the specified key
.