shared/trie.js
// Deep copy a node, return leaves
Deep copy a node, return leaves
Deep copy a node return leaves
deepCopy() {
    const result = new Node();
    result.entries = new Set(this.entries.values());
    let leaves = [];
    for(let i = 0; i < 26; ++i)
      if(this.children[i]) {
        const [node, subleaves] = this.children[i].deepCopy();
        result.children[i] = node;
        leaves = leaves.concat(subleaves);
      }
    if(leaves.length === 0) leaves = [result];
    return [result, leaves];
  }
deepCopy ( ) { const result = new Node ( ) ; result . entries = new Set ( this . entries . values ( ) ) ; let leaves = [ ] ; for ( let i = 0 ; i < 26 ; ++ i ) if ( this . children [ i ] ) { const [ node , subleaves ] = this . children [ i ] . deepCopy ( ) ; result . children [ i ] = node ; leaves = leaves . concat ( subleaves ) ; } if ( leaves . length === 0 ) leaves = [ result ] ; return [ result , leaves ] ; }
Deep copy a node, return leaves
Deep copy a node return leaves