TagIndex

Struct TagIndex 

Source
pub struct TagIndex { /* private fields */ }

Implementations§

Source§

impl TagIndex

Source

pub fn add(&mut self, tag: TeloidTag, id: TeloidID)

Adds a TeloidID to the index for a given TeloidTag.

If the tag does not exist in the index, it will be added. If the ID already exists for the given tag, it will not be added again.

§Arguments
  • tag - The TeloidTag to associate with the ID.
  • id - The TeloidID to add.
§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};

let mut tag_index = TagIndex::new();
let tag = "test_tag";
let id = 1;
tag_index.add(tag, id);
tag_index.add(tag, id); // Duplicates are ignored
assert_eq!(tag_index.get(tag).unwrap().len(), 1);
Source

pub fn get(&self, tag: &str) -> Option<&HashSet<TeloidID>>

Retrieves a reference to the set of TeloidIDs associated with a given TeloidTag.

§Arguments
  • tag - The TeloidTag to look up.
§Returns

An Option containing a reference to the HashSet of TeloidIDs if the tag exists, otherwise None.

§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};
use std::collections::HashSet;

let mut tag_index = TagIndex::new();
let tag = "test_tag";
let id = 1;
tag_index.add(tag, id);

let mut expected = HashSet::new();
expected.insert(1);

let ids = tag_index.get(tag);
assert_eq!(ids, Some(&expected));
Source

pub fn remove(&mut self, tag: &str, id: TeloidID)

Removes a TeloidID from the index for a given TeloidTag.

If the tag or ID does not exist, the index remains unchanged.

§Arguments
  • tag - The TeloidTag from which to remove the ID.
  • id - The TeloidID to remove.
§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};

let mut tag_index = TagIndex::new();
let tag = "test_tag";
let id = 1;
tag_index.add(tag, id);
tag_index.remove(tag, id);
assert!(tag_index.get(tag).is_none() || tag_index.get(tag).unwrap().is_empty());
Source

pub fn update(&mut self, tag: &str, id: TeloidID)

Adds a TeloidID to an existing entry for a given TeloidTag.

This is similar to add, but it will not create a new entry if the tag doesn’t exist.

§Arguments
  • tag - The TeloidTag to update.
  • id - The TeloidID to add.
§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};

let mut tag_index = TagIndex::new();
let tag = "test_tag";
let id1 = 1;
let id2 = 2;
tag_index.add(tag, id1);
tag_index.update(tag, id2);
assert_eq!(tag_index.get(tag).unwrap().len(), 2);
Source

pub fn contains_key(&self, tag: &str) -> bool

Checks if a TeloidTag exists in the index.

§Arguments
  • tag - The TeloidTag to check.
§Returns

true if the tag exists, otherwise false.

§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};

let mut tag_index = TagIndex::new();
let tag = "test_tag";
tag_index.add(tag, 1);

assert!(tag_index.contains_key(tag));
Source

pub fn len(&self) -> usize

Returns the number of tags in the index.

§Returns

The number of unique tags in the index.

§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};

let mut tag_index = TagIndex::new();
tag_index.add("test_tag", 1);
assert_eq!(tag_index.len(), 1);
Source

pub fn is_empty(&self) -> bool

Returns true if the index contains no elements.

§Returns

true if the index is empty, false otherwise.

§Examples
use deep_causality_ethos::TagIndex;

let mut tag_index = TagIndex::new();
assert!(tag_index.is_empty());
tag_index.add("test_tag", 1);
assert!(!tag_index.is_empty());
Source

pub fn clear(&mut self)

Clears the index, removing all tags and IDs.

§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};

let mut tag_index = TagIndex::new();
tag_index.add("test_tag", 1);
tag_index.clear();
assert_eq!(tag_index.len(), 0);
Source§

impl TagIndex

Source

pub fn new() -> Self

Creates a new, empty TagIndex.

§Returns

A new TagIndex instance.

§Examples
use deep_causality_ethos::TagIndex;
let tag_index = TagIndex::new();
Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new TagIndex with a specified capacity.

§Arguments
  • capacity - The initial capacity of the index.
§Returns

A new TagIndex instance with the given capacity.

§Examples
use deep_causality_ethos::TagIndex;
let tag_index = TagIndex::with_capacity(10);

Trait Implementations§

Source§

impl Clone for TagIndex

Source§

fn clone(&self) -> TagIndex

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 Debug for TagIndex

Source§

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

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

impl Default for TagIndex

Source§

fn default() -> TagIndex

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

impl Display for TagIndex

Source§

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

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

impl PartialEq for TagIndex

Source§

fn eq(&self, other: &TagIndex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TagIndex

Source§

impl StructuralPartialEq for TagIndex

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.