pub struct FloatPool { /* private fields */ }Expand description
Structure for interning similar floats based on approximate equality.
§Examples
use approx_collections::FloatPool;
let mut pool = FloatPool::default();
let very_small_delta = 0.0000000001;
assert_eq!(pool.intern(4.0), 4.0);
assert_eq!(pool.intern(4.0 + very_small_delta), 4.0);
assert_eq!(pool.intern(4.0 - very_small_delta), 4.0);
assert_eq!(pool.intern(3.0 - very_small_delta), 3.0 - very_small_delta);
assert_eq!(pool.intern(3.0), 3.0 - very_small_delta);Implementations§
Source§impl FloatPool
impl FloatPool
Sourcepub fn intern<V: ApproxInternable>(&mut self, value: V) -> V
pub fn intern<V: ApproxInternable>(&mut self, value: V) -> V
Replaces all floats in value with interned ones that are approximately
equal, returning a mutated copy of value.
If any floats in value are have not already been interned, they are
added to the pool and unmodified.
Sourcepub fn intern_in_place<V: ApproxInternable>(&mut self, value: &mut V)
pub fn intern_in_place<V: ApproxInternable>(&mut self, value: &mut V)
Replaces all floats in value with interned ones that are approximately
equal.
If any floats in value are have not already been interned, they are
added to the pool and unmodified.
Sourcepub fn try_intern<V: ApproxInternable>(&self, value: V) -> Option<V>
pub fn try_intern<V: ApproxInternable>(&self, value: V) -> Option<V>
Replaces all floats in value with interned ones that are approximately
equal, returning a mutated copy of value. Returns None if any floats
in value are not already in the pool.
Sourcepub fn bucket_count(&self) -> usize
pub fn bucket_count(&self) -> usize
Returns the number of occupied buckets in the pool.
Trait Implementations§
Source§impl Default for FloatPool
impl Default for FloatPool
Source§fn default() -> Self
fn default() -> Self
Constructs a float interner using Precision::default().
Source§impl<'a> IntoIterator for &'a FloatPool
impl<'a> IntoIterator for &'a FloatPool
Auto Trait Implementations§
impl Freeze for FloatPool
impl RefUnwindSafe for FloatPool
impl Send for FloatPool
impl Sync for FloatPool
impl Unpin for FloatPool
impl UnsafeUnpin for FloatPool
impl UnwindSafe for FloatPool
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