Struct libbgs::numbers::FactorTrie
source · pub struct FactorTrie<S, const L: usize, C, T> {
pub data: T,
/* private fields */
}
Expand description
A trie of prime factors in increasing order; that is, a none with word $p$ will have only children with word $q \geq p$.
Fields§
§data: T
Data associated with the key given by the concatenation of this node’s ancestors’ words.
Implementations§
source§impl<S, const L: usize, C> FactorTrie<S, L, C, ()>where
C: Factor<S>,
impl<S, const L: usize, C> FactorTrie<S, L, C, ()>where C: Factor<S>,
sourcepub fn new() -> FactorTrie<S, L, C, ()>
pub fn new() -> FactorTrie<S, L, C, ()>
Creates a new trie associated to the given factorization
.
The trie contains the divisors of C::FACTORS
.
The words of a divisor are its prime factors, with multiplicities, in ascending order.
source§impl<S, const L: usize, C, T> FactorTrie<S, L, C, T>where
C: Factor<S>,
impl<S, const L: usize, C, T> FactorTrie<S, L, C, T>where C: Factor<S>,
sourcepub fn new_with<F>(f: F) -> FactorTrie<S, L, C, T>where
F: Fn(&[usize; L], usize) -> T,
pub fn new_with<F>(f: F) -> FactorTrie<S, L, C, T>where F: Fn(&[usize; L], usize) -> T,
Creates a new trie associated to the given factorization
.
The trie contains the divisors of C::FACTORS
.
The words of a divisor are its prime factors, with multiplicities, in ascending order.
The trie is seeded with data generated by f
.
source§impl<S, const L: usize, C, T> FactorTrie<S, L, C, T>
impl<S, const L: usize, C, T> FactorTrie<S, L, C, T>
sourcepub fn get_or_new_child<F>(
&mut self,
i: usize,
data: F
) -> &mut FactorTrie<S, L, C, T>where
F: FnOnce() -> T,
pub fn get_or_new_child<F>( &mut self, i: usize, data: F ) -> &mut FactorTrie<S, L, C, T>where F: FnOnce() -> T,
Returns this node’s child at index i
, or creates the child, initialized with the result
of the lazily-evaluated data
.
sourcepub fn update<F>(&mut self, t: &[usize; L], gen: F)where
F: Fn(&[usize; L], &mut T),
pub fn update<F>(&mut self, t: &[usize; L], gen: F)where F: Fn(&[usize; L], &mut T),
Updates a single node in the trie.
sourcepub fn map<U, F>(self, f: &F) -> FactorTrie<S, L, C, U>where
F: Fn(T, &[usize; L], usize) -> U,
pub fn map<U, F>(self, f: &F) -> FactorTrie<S, L, C, U>where F: Fn(T, &[usize; L], usize) -> U,
Transforms this trie into an equivalent trie with the same shape, but all data mapped via
f
.
sourcepub fn as_ref(&self) -> FactorTrie<S, L, C, &T>
pub fn as_ref(&self) -> FactorTrie<S, L, C, &T>
Returns a trie of borrowed data.
sourcepub fn as_mut(&mut self) -> FactorTrie<S, L, C, &mut T>
pub fn as_mut(&mut self) -> FactorTrie<S, L, C, &mut T>
Returns a trie of mutably borrowed data.
sourcepub fn for_each<F>(&self, f: &mut F)where
F: FnMut(&T, [usize; L]),
pub fn for_each<F>(&self, f: &mut F)where F: FnMut(&T, [usize; L]),
Runs f
on each node, in a pre-order traversal.
sourcepub fn children(&self) -> &[Option<Box<FactorTrie<S, L, C, T>>>]
pub fn children(&self) -> &[Option<Box<FactorTrie<S, L, C, T>>>]
This node’s array of children.
sourcepub fn child(&self, i: usize) -> Option<&FactorTrie<S, L, C, T>>
pub fn child(&self, i: usize) -> Option<&FactorTrie<S, L, C, T>>
Returns a reference to the child at index i
, if there is one.
sourcepub fn child_mut(&mut self, i: usize) -> Option<&mut FactorTrie<S, L, C, T>>
pub fn child_mut(&mut self, i: usize) -> Option<&mut FactorTrie<S, L, C, T>>
Returns a mutable reference to the child at index i
, if there is one.