A simple map based on a vector for small integer keys. Space requirements are O(highest integer key).
SmallIntMap
SmallIntSet
- A set implemented on top of the SmallIntMap typeof Container for SmallIntMap<V> where <V>
of Mutable for SmallIntMap<V> where <V>
of Map<uint, V> for SmallIntMap<V> where <V>
for SmallIntMap<V> where <V>
for SmallIntMap<V> where <V: Copy>
of Container for SmallIntSet
of Mutable for SmallIntSet
of Set<uint> for SmallIntSet
for SmallIntSet
SmallIntMap
pub struct SmallIntMap<T> {
priv v: ~[Option<T>],
}
SmallIntSet
pub struct SmallIntSet {
priv map: SmallIntMap<()>,
}
A set implemented on top of the SmallIntMap type. This set is always a set of integers, and the space requirements are on the order of the highest valued integer in the set.
Container
for SmallIntMap<V>
where <V>
len
fn len(&self) -> uint
Return the number of elements in the map
is_empty
fn is_empty(&self) -> bool
Return true if the map contains no elements
Mutable
for SmallIntMap<V>
where <V>
clear
fn clear(&mut self)
Clear the map, removing all key-value pairs.
Map<uint, V>
for SmallIntMap<V>
where <V>
contains_key
fn contains_key(&self, key: &uint) -> bool
Return true if the map contains a value for the specified key
find
fn find<'a>(&'a self, key: &uint) -> Option<&'a V>
Return a reference to the value corresponding to the key
find_mut
fn find_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut V>
Return a mutable reference to the value corresponding to the key
insert
fn insert(&mut self, key: uint, value: V) -> bool
Insert a key-value pair into the map. An existing value for a key is replaced by the new value. Return true if the key did not already exist in the map.
remove
fn remove(&mut self, key: &uint) -> bool
Remove a key-value pair from the map. Return true if the key was present in the map, otherwise false.
swap
fn swap(&mut self, key: uint, value: V) -> Option<V>
Insert a key-value pair from the map. If the key already had a value present in the map, that value is returned. Otherwise None is returned.
pop
fn pop(&mut self, key: &uint) -> Option<V>
Removes a key from the map, returning the value at the key if the key was previously in the map.
SmallIntMap<V>
where <V>
new
fn new() -> SmallIntMap<V>
Create an empty SmallIntMap
each
fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool
Visit all key-value pairs in order
each_key
fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool
Visit all keys in order
each_value
fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool
Visit all values in order
mutate_values
fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool
Iterate over the map and mutate the contained values
each_reverse
fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool
Visit all key-value pairs in reverse order
get
fn get<'a>(&'a self, key: &uint) -> &'a V
SmallIntMap<V>
where <V: Copy>
update_with_key
fn update_with_key(&mut self, key: uint, val: V, ff: &fn(uint, V, V) -> V) ->
bool
update
fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V) -> bool
Container
for SmallIntSet
len
fn len(&self) -> uint
Return the number of elements in the map
is_empty
fn is_empty(&self) -> bool
Return true if the map contains no elements
Mutable
for SmallIntSet
clear
fn clear(&mut self)
Clear the map, removing all key-value pairs.
Set<uint>
for SmallIntSet
contains
fn contains(&self, value: &uint) -> bool
Return true if the set contains a value
insert
fn insert(&mut self, value: uint) -> bool
Add a value to the set. Return true if the value was not already present in the set.
remove
fn remove(&mut self, value: &uint) -> bool
Remove a value from the set. Return true if the value was present in the set.
is_disjoint
fn is_disjoint(&self, other: &SmallIntSet) -> bool
Return true if the set has no elements in common with other
. This is equivalent to checking for an empty uintersection.
is_subset
fn is_subset(&self, other: &SmallIntSet) -> bool
Return true if the set is a subset of another
is_superset
fn is_superset(&self, other: &SmallIntSet) -> bool
Return true if the set is a superset of another
difference
fn difference(&self, other: &SmallIntSet, f: &fn(&uint) -> bool) -> bool
Visit the values representing the difference
symmetric_difference
fn symmetric_difference(&self, other: &SmallIntSet, f: &fn(&uint) -> bool) ->
bool
Visit the values representing the symmetric difference
intersection
fn intersection(&self, other: &SmallIntSet, f: &fn(&uint) -> bool) -> bool
Visit the values representing the uintersection
union
fn union(&self, other: &SmallIntSet, f: &fn(&uint) -> bool) -> bool
Visit the values representing the union
SmallIntSet
new
fn new() -> SmallIntSet
Create an empty SmallIntSet
each
fn each(&self, f: &fn(&uint) -> bool) -> bool
Visit all values in order