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
impl AnchorSupply
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new anchor supply with pre-allocated capacity.
Sourcepub fn get(&self, entity_idx: usize) -> Option<usize>
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.
Sourcepub fn set(&mut self, entity_idx: usize, anchor_idx: usize) -> Option<usize>
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.
Sourcepub fn remove(&mut self, entity_idx: usize) -> Option<usize>
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.
Sourcepub fn cascade(
&mut self,
entity_indices: impl IntoIterator<Item = usize>,
anchor_idx: usize,
)
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.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&usize, &usize)>
pub fn iter(&self) -> impl Iterator<Item = (&usize, &usize)>
Returns an iterator over all (entity_idx, anchor_idx) pairs.
Sourcepub fn entities_for_anchor(&self, anchor_idx: usize) -> Vec<usize>
pub fn entities_for_anchor(&self, anchor_idx: usize) -> Vec<usize>
Returns all entity indices that share the given anchor.