pub struct PQTree<T>{ /* private fields */ }
Implementations§
Source§impl<T: Clone + Eq + Hash> PQTree<T>
impl<T: Clone + Eq + Hash> PQTree<T>
Sourcepub fn from_leaves(initial: &[T]) -> Result<Self, ReplacementError<T>>
pub fn from_leaves(initial: &[T]) -> Result<Self, ReplacementError<T>>
Creates PQTree from list of leaves.
First creates an empty tree, then replaces whole tree by new leaves:
PQTree::new().replace_tree_by_new_leaves(initial)
§Errors
Returns Err(ReplacementError::DuplicateLeaf(leaf))
if leaf
presents in initial
more than one time.
Sourcepub fn reduction(self, s: &[T]) -> Result<Self, ReductionError<T>>
pub fn reduction(self, s: &[T]) -> Result<Self, ReductionError<T>>
Applies reduction to the tree enforcing leaves from s
to be consequent
and marks pertinent subroot.
§Errors
Returns Err(ReductionError::EmptyLeafSet)
if s
is empty.
Returns Err(ReductionError::LeafNotFound(leaf))
if leaf
from s
not found in the tree.
Returns Err(ReductionError::IrreducibleTree)
if tree cannot be reduced over new constraint.
Sourcepub fn replace_tree_by_new_leaves(
self,
leaves: &[T],
) -> Result<Self, ReplacementError<T>>
pub fn replace_tree_by_new_leaves( self, leaves: &[T], ) -> Result<Self, ReplacementError<T>>
Replaces whole tree by new leaves.
Same as PQTree::from_leaves
but without reallocation.
§Errors
Returns Err(ReplacementError::DuplicateLeaf(leaf))
if leaf
presents in leaves
more than one time.
Sourcepub fn replace_leaf_by_new_leaves(
self,
leaf: &T,
leaves: &[T],
) -> Result<Self, ReplacementError<T>>
pub fn replace_leaf_by_new_leaves( self, leaf: &T, leaves: &[T], ) -> Result<Self, ReplacementError<T>>
Replaces single leaf
by new leaves
.
Can be called with empty leaves
to remove leaf
from tree.
First removes leaf
from tree, then adds new leaves.
Clears pertinent root mark if any.
§Errors
Returns Err(ReplacementError::LeafNotFound(leaf))
if leaf
not found in the tree.
Returns Err(ReplacementError::DuplicateLeaf(leaf))
if leaf
already exists in the tree or presents in leaves
more than one time.
Sourcepub fn replace_pertinent_by_new_leaves(
self,
leaves: &[T],
) -> Result<Self, ReplacementError<T>>
pub fn replace_pertinent_by_new_leaves( self, leaves: &[T], ) -> Result<Self, ReplacementError<T>>
Replaces full children of the pertinent root by new leaves
.
Can be called with empty leaves
to remove all full children from the tree.
First removes all full nodes and leaves from the tree, then adds new leaves.
Marks added subtree root as the pertinent root if leaves
is not empty or clears the mark.
§Errors
Returns Err(ReplacementError::DuplicateLeaf(leaf))
if leaf
already exists in the tree or presents in leaves
more than one time.
Returns Err(ReplacementError::NoPertinentRoot))
if no pertinent root is marked in the tree.