IndexTreeSet

Struct IndexTreeSet 

Source
pub struct IndexTreeSet<K> {
    pub map: IndexTreeMap<K, ()>,
}
Expand description

The ‘Set’ IndexTree data structure

Fields§

§map: IndexTreeMap<K, ()>

Implementations§

Source§

impl<K: Default> IndexTreeSet<K>

Source

pub fn new() -> IndexTreeSet<K>

Makes a new, empty IndexTreeSet.

Does not allocate anything on its own.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut map = IndexTreeSet::new();

map.insert(1);
Source§

impl<K: Default> IndexTreeSet<K>

Source

pub fn clear(&mut self)

Clears the map, removing all elements.

Does not allocate anything on its own.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut map = IndexTreeSet::new();

map.insert(1);
map.clear();
assert!(map.is_empty());
Source§

impl<K> IndexTreeSet<K>

Source

pub fn len(&self) -> usize

Clears the map, removing all elements.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut map = IndexTreeSet::new();

map.insert(1);
assert_eq!(map.len(), 1);
Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut map = IndexTreeSet::new();
assert!(map.is_empty());
map.insert(1);
assert!(!map.is_empty());
Source§

impl<K: Ord> IndexTreeSet<K>

Source

pub fn contains_key(&self, key: &K) -> bool

Returns true if the set contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.contains_key(&1), true);
assert_eq!(tree.contains_key(&2), false);
Source§

impl<K> IndexTreeSet<K>

Source

pub fn contains_index(&self, index: usize) -> bool

Returns true if the set contains an item in the index position.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.contains_index(0), true);
assert_eq!(tree.contains_index(1), false);
Source§

impl<K: Ord> IndexTreeSet<K>

Source

pub fn get(&self, key: &K) -> Option<&K>

Returns the index of the corresponding key.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.get(&1), Some(&1));
assert_eq!(tree.get(&2), None);
Source

pub fn get_from_index(&self, index: usize) -> Option<&K>

Returns the index of the corresponding key.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.get_key_from_index(0), Some(&1));
assert_eq!(tree.get_key_from_index(1), None);
Source§

impl<K: Ord> IndexTreeSet<K>

Source

pub fn get_index_from_key(&self, key: &K) -> Option<usize>

Returns the index of the corresponding key.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.get_index_from_key(&1), Some(0));
assert_eq!(tree.get_index_from_key(&2), None);
Source

pub fn get_key_from_index(&self, id: usize) -> Option<&K>

Returns a reference to the key corresponding to the index.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.get_key_from_index(0), Some(&1));
assert_eq!(tree.get_key_from_index(1), None);
Source

pub fn get_first(&self) -> Option<&K>

Returns a reference to the first key in the map.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.get_first(), Some(&1));
Source

pub fn get_last(&self) -> Option<&K>

Returns a reference to the last key in the map.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
tree.insert(2);
assert_eq!(tree.get_last(), Some(&2));
Source§

impl<K: Default + Ord + Clone + Debug> IndexTreeSet<K>

Source

pub fn insert(&mut self, key: K)

Inserts a key into the set.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert!(!tree.is_empty());
Source§

impl<K> IndexTreeSet<K>

Source

pub fn iter(&self) -> IndexTreeSetIterator<'_, K>

Gets an iterator over the entries of the set, sorted by key.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut map = IndexTreeSet::new();
map.insert(10);
map.insert(1);

let first_key = map.iter().next().unwrap();
assert_eq!(first_key, &1);
Source§

impl<K: Default + Ord + Clone> IndexTreeSet<K>

Source

pub fn remove(&mut self, key: &K) -> Option<K>

Removes an item from the map from its corresponding key, returning the key-value pair that was previously in the map.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.remove(&1), Some(1));
assert_eq!(tree.remove(&2), None);
Source§

impl<K: Default + Ord + Clone> IndexTreeSet<K>

Source

pub fn remove_from_index(&mut self, index: usize) -> Option<K>

Removes an item from the map from its corresponding index, returning the key-value pair that was previously in the map.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut tree = IndexTreeSet::new();
tree.insert(1);
assert_eq!(tree.remove_from_index(0), Some(1));
assert_eq!(tree.remove_from_index(1), None);
Source§

impl<K: Default + Ord + Clone> IndexTreeSet<K>

Source

pub fn split_off(&mut self, key: &K) -> IndexTreeSet<K>

Splits the map into two at the given key. Returns everything after the given key, including the key.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut a = IndexTreeSet::new();
a.insert(1);
a.insert(2);
a.insert(13);
a.insert(17);
a.insert(41);

let b = a.split_off(&13);

assert_eq!(a.len(), 2);
assert_eq!(b.len(), 3);
Source

pub fn split_off_from_index(&mut self, index: usize) -> IndexTreeSet<K>

Splits the map into two at the given index. Returns everything after the given key, including the key.

§Example

Basic usage:

use indextreemap::IndexTreeSet;

let mut a = IndexTreeSet::new();
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(17);
a.insert(41);

let b = a.split_off_from_index(2);

assert_eq!(a.len(), 2);
assert_eq!(b.len(), 3);

Trait Implementations§

Source§

impl<K: Clone> Clone for IndexTreeSet<K>

Source§

fn clone(&self) -> IndexTreeSet<K>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug> Debug for IndexTreeSet<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: Default> Default for IndexTreeSet<K>

Source§

fn default() -> IndexTreeSet<K>

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

impl<'de, K> Deserialize<'de> for IndexTreeSet<K>
where K: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K> Serialize for IndexTreeSet<K>
where K: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<K> Freeze for IndexTreeSet<K>

§

impl<K> RefUnwindSafe for IndexTreeSet<K>
where K: RefUnwindSafe,

§

impl<K> Send for IndexTreeSet<K>
where K: Send,

§

impl<K> Sync for IndexTreeSet<K>
where K: Sync,

§

impl<K> Unpin for IndexTreeSet<K>

§

impl<K> UnwindSafe for IndexTreeSet<K>
where K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,