AnchorSupply

Struct AnchorSupply 

Source
pub struct AnchorSupply { /* private fields */ }
Expand description

Index-based anchor variable supply.

For chained variables, entities form chains rooted at anchors. This supply answers: “Given an entity index, what anchor index is at the chain root?”

Both entities and anchors are referenced by index into their respective collections.

§Example

use solverforge_core::domain::supply::AnchorSupply;

let mut supply = AnchorSupply::new();

// Entities 0, 1, 2 all belong to anchor 0
supply.set(0, 0);
supply.set(1, 0);
supply.set(2, 0);

// Entity 3 belongs to anchor 1
supply.set(3, 1);

assert_eq!(supply.get(0), Some(0));
assert_eq!(supply.get(1), Some(0));
assert_eq!(supply.get(3), Some(1));

Implementations§

Source§

impl AnchorSupply

Source

pub fn new() -> Self

Creates a new empty anchor supply.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new anchor supply with pre-allocated capacity.

Source

pub fn get(&self, entity_idx: usize) -> Option<usize>

Gets the anchor index for an entity index.

Returns None if the entity is not in any chain.

Source

pub fn set(&mut self, entity_idx: usize, anchor_idx: usize) -> Option<usize>

Sets the anchor index for an entity index.

Returns the previous anchor index if one existed.

Source

pub fn remove(&mut self, entity_idx: usize) -> Option<usize>

Removes the anchor mapping for an entity.

Returns the anchor index that was mapped, if any.

Source

pub fn cascade( &mut self, entity_indices: impl IntoIterator<Item = usize>, anchor_idx: usize, )

Updates anchors for multiple entities at once.

Use when re-rooting a chain segment to a new anchor.

Source

pub fn clear(&mut self)

Clears all mappings.

Source

pub fn len(&self) -> usize

Returns the number of tracked entities.

Source

pub fn is_empty(&self) -> bool

Returns true if no entities are tracked.

Source

pub fn iter(&self) -> impl Iterator<Item = (&usize, &usize)>

Returns an iterator over all (entity_idx, anchor_idx) pairs.

Source

pub fn entities_for_anchor(&self, anchor_idx: usize) -> Vec<usize>

Returns all entity indices that share the given anchor.

Trait Implementations§

Source§

impl Debug for AnchorSupply

Source§

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

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

impl Default for AnchorSupply

Source§

fn default() -> AnchorSupply

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

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> 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, 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.