pub fn find_match(&self, histogram: &[crate::Bin]) -> Option<&'a Glyph> {
        let mut c: &LookupNode = &self.tree;
        let mut best: &LookupNode = c;

        macro_rules! return_best {
            ( ) => {
                return match best.leafs.get(0) {
                    Some(g) => Some(*g),
                    _ => None,
                }
            };
        }

        // Iterate through the values in d.
        for b in histogram.iter() {
            // Use the value in the histrogram as index.
            let v = b.count as usize;

            if c.children.len() == 0 {
                // Reached a leaf in the tree, return the glyph... we must have one, otherwise 'c'
                // would be None.
                // We may have multiple though, in that case the glyph set is ambiguous.
                return match c.leafs.get(0) {
                    Some(g) => Some(g),
                    _ => None,
                };
            }

            // If v exceeds the length of children, we terminate the search and return the
            // best matching token so far.
            if v >= c.children.len() {
                return_best!();
            }

            // Check if we have a new node in our search tree at this histogram value.
            if let Some(ref new_c) = c.children[v] {
                c = new_c; // assign new position.

                // If we would have a leaf here, assign it to the best match, because this is a
                // valid match, but we'll continue searching to find a longer match.
                if !new_c.leafs.is_empty() {
                    best = new_c;
                }
            } else {
                // We got a none, return best matching glyph, or none.
                return_best!();
            }
        }
        None
    }
/// Find a glyph matching the provided histogram. Returns None if no glyph exactly matches this
/// histogram, if multiple glyphs would match perfectly it returns the one that occured earliest
/// in the original slice used to setup the glyph matcher.
Find a glyph matching the provided histogram. Returns None if no glyph exactly matches this
histogram, if multiple glyphs would match perfectly it returns the one that occured earliest
in the original slice used to setup the glyph matcher.
Find a glyph matching the provided histogram . Returns None if no glyph exactly matches this histogram if multiple glyphs would match perfectly it returns the one that occured earliest in the original slice used to setup the glyph matcher .
pub fn find_match(&self, histogram: &[crate::Bin]) -> Option<&'a Glyph> {
        let mut c: &LookupNode = &self.tree;
        let mut best: &LookupNode = c;
        macro_rules! return_best {
            ( ) => {
                return match best.leafs.get(0) {
                    Some(g) => Some(*g),
                    _ => None,
                }
            };
        }
        // Iterate through the values in d.
        for b in histogram.iter() {
            // Use the value in the histrogram as index.
            let v = b.count as usize;
            if c.children.len() == 0 {
                // Reached a leaf in the tree, return the glyph... we must have one, otherwise 'c'
                // would be None.
                // We may have multiple though, in that case the glyph set is ambiguous.
                return match c.leafs.get(0) {
                    Some(g) => Some(g),
                    _ => None,
                };
            }
            // If v exceeds the length of children, we terminate the search and return the
            // best matching token so far.
            if v >= c.children.len() {
                return_best!();
            }
            // Check if we have a new node in our search tree at this histogram value.
            if let Some(ref new_c) = c.children[v] {
                c = new_c; // assign new position.
                // If we would have a leaf here, assign it to the best match, because this is a
                // valid match, but we'll continue searching to find a longer match.
                if !new_c.leafs.is_empty() {
                    best = new_c;
                }
            } else {
                // We got a none, return best matching glyph, or none.
                return_best!();
            }
        }
        None
    }
pub fn find_match ( & self , histogram : & [ crate :: Bin ] ) -> Option < & ' a Glyph > { let mut c : & LookupNode = & self . tree ; let mut best : & LookupNode = c ; macro_rules! return_best { ( ) => { return match best leafs get ( 0 ) { Some ( g ) Some ( g ) None } } ; } // Iterate through the values in d. for b in histogram . iter ( ) { // Use the value in the histrogram as index. let v = b . count as usize ; if c . children . len ( ) == 0 { // Reached a leaf in the tree, return the glyph... we must have one, otherwise 'c' // would be None. // We may have multiple though, in that case the glyph set is ambiguous. return match c . leafs . get ( 0 ) { Some ( g ) => Some ( g ) , _ => None , } ; } // If v exceeds the length of children, we terminate the search and return the // best matching token so far. if v >= c . children . len ( ) { return_best ! ( ) ; } // Check if we have a new node in our search tree at this histogram value. if let Some ( ref new_c ) = c . children [ v ] { c = new_c ; // assign new position. // If we would have a leaf here, assign it to the best match, because this is a // valid match, but we'll continue searching to find a longer match. if ! new_c . leafs . is_empty ( ) { best = new_c ; } } else { // We got a none, return best matching glyph, or none. return_best ! ( ) ; } } None }
Find a glyph matching the provided histogram.
Find a glyph matching the provided histogram .
&self
histogram
&[crate::Bin]