pub struct CharacteristicVector {
pub counts: [u32; 23],
pub max_depth: u32,
pub node_count: u32,
}Expand description
Shape-tag counts plus tree size and depth: a candidate filter.
The count vector is a cheap lower-bound proxy for tree edit distance: two
subtrees within edit distance d differ by at most 2 * d in L1 count
distance, so a large CharacteristicVector::l1_distance rules a pair
out without touching either tree. That is what
CharacteristicVector::shape_divergence gates candidate pairs on, and
what CharacteristicVector::cosine_similarity contributes to the
structural dimension of a verdict.
Fields§
§counts: [u32; 23]Node count per shape tag; index = tag, index 0 unused.
max_depth: u32Number of nodes on the longest root-to-leaf path of the unit subtree; a lone node has depth 1.
node_count: u32Total number of nodes in the unit subtree.
Implementations§
Source§impl CharacteristicVector
impl CharacteristicVector
Sourcepub fn l1_distance(&self, other: &Self) -> u64
pub fn l1_distance(&self, other: &Self) -> u64
L1 distance between the two count vectors. Depth and node count do not participate.
Sourcepub fn shape_divergence(&self, other: &Self) -> f64
pub fn shape_divergence(&self, other: &Self) -> f64
How far apart the two shape mixes are, on a 0.0–1.0 scale: the L1
count distance over the nodes the two units have between them. 0.0
when they hold the same shapes in the same numbers, 1.0 when they
share no shape at all. 0.0 for two empty vectors, which are not
divergent — they are simply nothing to tell apart.
Size is part of it, and deliberately so: the vectors sum to their unit
node counts, so the distance is at least |na - nb| / (na + nb) and a
pair whose sizes differ by a factor of r scores at least
(r - 1) / (r + 1) before any difference in shape mix is counted.
A limit of 0.5 therefore says exactly what
max_length_ratio’s
3.0 says about size, and says it about the shape mix too.
Sourcepub fn cosine_similarity(&self, other: &Self) -> f64
pub fn cosine_similarity(&self, other: &Self) -> f64
Cosine similarity of the two count vectors, 0.0 when either vector
is all-zero. Depth and node count do not participate.
Trait Implementations§
Source§impl Clone for CharacteristicVector
impl Clone for CharacteristicVector
Source§fn clone(&self) -> CharacteristicVector
fn clone(&self) -> CharacteristicVector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CharacteristicVector
impl Debug for CharacteristicVector
Source§impl Default for CharacteristicVector
impl Default for CharacteristicVector
Source§fn default() -> CharacteristicVector
fn default() -> CharacteristicVector
impl Eq for CharacteristicVector
Source§impl PartialEq for CharacteristicVector
impl PartialEq for CharacteristicVector
impl StructuralPartialEq for CharacteristicVector
Auto Trait Implementations§
impl Freeze for CharacteristicVector
impl RefUnwindSafe for CharacteristicVector
impl Send for CharacteristicVector
impl Sync for CharacteristicVector
impl Unpin for CharacteristicVector
impl UnsafeUnpin for CharacteristicVector
impl UnwindSafe for CharacteristicVector
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.