src/Functions.cpp
/**
 * The validation code consists of two functions. All it does
 * is traverse the entire tree. walk_tree() calls itself
 * recursively, building suffix strings up as it goes. When
 * walk_tree() reaches a leaf node, it checks to see if the
 * suffix derived from the tree matches the suffix starting
 * at the same point in the input text. If so, it tags that
 * suffix as correct in the GoodSuffixes[] array. When the tree
 * has been traversed, every entry in the GoodSuffixes array should
 * have a value of 1.
 * In addition, the BranchCount[] array is updated while the tree is
 * walked as well. Every count in the array has the number of child edges
 * emanating from that node.  If the node is a leaf node, the value is set to -1.
 *  When the routine finishes, every node should be a branch or a leaf.
 * The number of leaf nodes should match the number of suffixes (the length)
 * of the input string. The total number of branches from all
 * nodes should match the node count. */
The validation code consists of two functions. All it does
is traverse the entire tree. walk_tree() calls itself
recursively, building suffix strings up as it goes. When
walk_tree() reaches a leaf node, it checks to see if the
suffix derived from the tree matches the suffix starting
at the same point in the input text. If so, it tags that
suffix as correct in the GoodSuffixes[] array. When the tree
has been traversed, every entry in the GoodSuffixes array should
have a value of 1.
In addition, the BranchCount[] array is updated while the tree is
walked as well. Every count in the array has the number of child edges
emanating from that node.  If the node is a leaf node, the value is set to -1.
When the routine finishes, every node should be a branch or a leaf.
The number of leaf nodes should match the number of suffixes (the length)
of the input string. The total number of branches from all
nodes should match the node count.
The validation code consists of two functions . All it does is traverse the entire tree . walk_tree () calls itself recursively building suffix strings up as it goes . When walk_tree () reaches a leaf node it checks to see if the suffix derived from the tree matches the suffix starting at the same point in the input text . If so it tags that suffix as correct in the GoodSuffixes [] array . When the tree has been traversed every entry in the GoodSuffixes array should have a value of 1 . In addition the BranchCount [] array is updated while the tree is walked as well . Every count in the array has the number of child edges emanating from that node . If the node is a leaf node the value is set to - 1 . When the routine finishes every node should be a branch or a leaf . The number of leaf nodes should match the number of suffixes ( the length ) of the input string . The total number of branches from all nodes should match the node count .
void validate(ofstream &file) {
    for (int i = 0; i < Length; i++)
        GoodSuffixes[i] = 0;
    walk_tree(0, 0, file);
    int error = 0;
    for (int i = 0; i < Length; i++)
        if (GoodSuffixes[i] != 1) {
            cout << "Suffix " << i << " count wrong!\n";
            file << "Suffix " << i << " count wrong!\n";
            error++;
        }
    if (error == 0) {
        cout << "All Suffixes are present!\n";
        file << "All Suffixes are present!\n";
    }
    int leaf_count = 0;
    int branch_count = 0;
    for (int i = 0; i < Node::Count; i++) {
        if (BranchCount[i] == 0) {
            cout << "Logic error on node " << i << ", not a leaf or internal node!\n";
            file << "Logic error on node " << i << ", not a leaf or internal node!\n";
        } else if (BranchCount[i] == -1) {
            leaf_count++;
        } else {
            branch_count += BranchCount[i];
        }
    }
    cout << "Leaf count : " << leaf_count
    << (leaf_count == (Length + 1) ? " OK" : " Error!") << "\n";
    file << "Leaf count : " << leaf_count
    << (leaf_count == (Length + 1) ? " OK" : " Error!") << "\n";
    cout << "Branch count : " << branch_count
    << (branch_count == (Node::Count - 1) ? " OK" : " Error!") << endl;
    file << "Branch count : " << branch_count
    << (branch_count == (Node::Count - 1) ? " OK" : " Error!") << endl;
}
void validate ( ofstream & file ) { for ( int i = 0 ; i < Length ; i ++ ) GoodSuffixes [ i ] = 0 ; walk_tree ( 0 , 0 , file ) ; int error = 0 ; for ( int i = 0 ; i < Length ; i ++ ) if ( GoodSuffixes [ i ] != 1 ) { cout << " " << i << " \n " ; file << " " << i << " \n " ; error ++ ; } if ( error == 0 ) { cout << " \n " ; file << " \n " ; } int leaf_count = 0 ; int branch_count = 0 ; for ( int i = 0 ; i < Node :: Count ; i ++ ) { if ( BranchCount [ i ] == 0 ) { cout << " " << i << " \n " ; file << " " << i << " \n " ; } else if ( BranchCount [ i ] == -1 ) { leaf_count ++ ; } else { branch_count += BranchCount [ i ] ; } } cout << " " << leaf_count << ( leaf_count == ( Length + 1 ) ? " " : " " ) << " \n " ; file << " " << leaf_count << ( leaf_count == ( Length + 1 ) ? " " : " " ) << " \n " ; cout << " " << branch_count << ( branch_count == ( Node :: Count - 1 ) ? " " : " " ) << endl ; file << " " << branch_count << ( branch_count == ( Node :: Count - 1 ) ? " " : " " ) << endl ; }
The validation code consists of two functions.
The validation code consists of two functions .