Struct boa::builtins::map::ordered_map::OrderedMap
source · [−]pub struct OrderedMap<V, S = RandomState> { /* private fields */ }
Expand description
A newtype wrapping indexmap::IndexMap
Implementations
sourceimpl<V> OrderedMap<V>
impl<V> OrderedMap<V>
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
sourcepub fn full_len(&self) -> usize
pub fn full_len(&self) -> usize
Return the number of key-value pairs in the map, including empty values.
Computes in O(1) time.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Gets the number of key-value pairs in the map, not including empty values.
Computes in O(1) time.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
Computes in O(1) time.
sourcepub fn insert(&mut self, key: JsValue, value: V) -> Option<V>
pub fn insert(&mut self, key: JsValue, value: V) -> Option<V>
Insert a key-value pair in the map.
If an equivalent key already exists in the map: the key remains and
retains in its place in the order, its corresponding value is updated
with value
and the older value is returned inside Some(_)
.
If no equivalent key existed in the map: the new key-value pair is
inserted, last in order, and None
is returned.
Computes in O(1) time (amortized average).
sourcepub fn remove(&mut self, key: &JsValue) -> Option<V>
pub fn remove(&mut self, key: &JsValue) -> Option<V>
Remove the key-value pair equivalent to key
and return
its value.
Like Vec::remove
, the pair is removed by shifting all of the
elements that follow it, preserving their relative order.
This perturbs the index of all of those elements!
Return None
if key
is not in map.
Computes in O(n) time (average).
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all elements from the map and resets the counter of empty entries.
sourcepub fn get(&self, key: &JsValue) -> Option<&V>
pub fn get(&self, key: &JsValue) -> Option<&V>
Return a reference to the value stored for key
, if it is present,
else None
.
Computes in O(1) time (average).
sourcepub fn get_index(&self, index: usize) -> Option<(&JsValue, &V)>
pub fn get_index(&self, index: usize) -> Option<(&JsValue, &V)>
Get a key-value pair by index.
Valid indices are 0 <= index < self.full_len().
Computes in O(1) time.
sourcepub fn iter(&self) -> impl Iterator<Item = (&JsValue, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&JsValue, &V)>
Return an iterator over the key-value pairs of the map, in their order
sourcepub fn contains_key(&self, key: &JsValue) -> bool
pub fn contains_key(&self, key: &JsValue) -> bool
Return true
if an equivalent to key
exists in the map.
Computes in O(1) time (average).
Trait Implementations
sourceimpl<V: Clone, S: Clone> Clone for OrderedMap<V, S>
impl<V: Clone, S: Clone> Clone for OrderedMap<V, S>
sourcefn clone(&self) -> OrderedMap<V, S>
fn clone(&self) -> OrderedMap<V, S>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more