derekparker / trie

Data structure and relevant algorithms for extremely fast prefix/fuzzy string searching.
MIT License
761 stars 115 forks source link

What is mask for? #30

Closed pathbox closed 2 years ago

pathbox commented 2 years ago
type Node struct {
    val       rune
    path      string
    term      bool
    depth     int
    meta      interface{}
    mask      uint64
    parent    *Node
    children  map[rune]*Node
    termCount int
}

hello derekparker: I don't understand the function of the field mask in the Node, could you explain it? And why this trie is so fast. Thank you so much!

derekparker commented 2 years ago

The mask is so that we can ensure all characters we are searching before are present in the subtree so that the algorithm can stop early if not, it's just an optimization.