pub struct InverseSupply<V>{ /* private fields */ }Expand description
Index-based inverse variable supply.
For a chained variable where entity.previous = value, this supply answers:
“Given value, which entity index has entities[idx].previous == value?”
Returns entity indices - caller accesses actual entity via solution.entities[idx].
§Example
use solverforge_core::domain::supply::InverseSupply;
let mut supply: InverseSupply<i32> = InverseSupply::new();
// Entity at index 0 points to value 42
supply.insert(42, 0);
// Entity at index 1 points to value 99
supply.insert(99, 1);
assert_eq!(supply.get(&42), Some(0));
assert_eq!(supply.get(&99), Some(1));
assert_eq!(supply.get(&100), None);Implementations§
Source§impl<V> InverseSupply<V>
impl<V> InverseSupply<V>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new inverse supply with pre-allocated capacity.
Sourcepub fn get(&self, value: &V) -> Option<usize>
pub fn get(&self, value: &V) -> Option<usize>
Gets the entity index that points to the given value.
Returns None if no entity currently points to this value.
Sourcepub fn insert(&mut self, value: V, entity_idx: usize) -> Option<usize>
pub fn insert(&mut self, value: V, entity_idx: usize) -> Option<usize>
Registers that an entity index now points to a value.
Returns the previous entity index if this value was already mapped.
Sourcepub fn remove(&mut self, value: &V) -> Option<usize>
pub fn remove(&mut self, value: &V) -> Option<usize>
Removes the mapping for a value.
Returns the entity index that was mapped, if any.
Trait Implementations§
Source§impl<V> Debug for InverseSupply<V>
impl<V> Debug for InverseSupply<V>
Auto Trait Implementations§
impl<V> Freeze for InverseSupply<V>
impl<V> RefUnwindSafe for InverseSupply<V>where
V: RefUnwindSafe,
impl<V> Send for InverseSupply<V>where
V: Send,
impl<V> Sync for InverseSupply<V>where
V: Sync,
impl<V> Unpin for InverseSupply<V>where
V: Unpin,
impl<V> UnwindSafe for InverseSupply<V>where
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more