Procedure SequenceTreeCreation |
Input: sequencesD, the data table of PiecesStateSequence in database. |
Output: root, the root node of the sequence-tree. |
Method: |
() let stateIds save the ids of PiecesState; |
() root = new Node(value = 0, branches = null); |
() for = 0 to sequencesD.length − 1 do |
() stateIds = sequencesD[].sequenceStr.split(“:”); |
() //Eliminate redundant pieces-state of stateIds. |
() for = stateIds.length − 1 to 2 do |
() for = − 2 to 0 by 2 do |
() if stateIds[] ==stateIds[]then |
() stateIds.delete( + 1, ); |
() = ; |
() endif |
() endfor |
() endfor |
() node = root; |
() for = 1 to stateIds.length − 1 do |
() if node.value == 0 then |
() node.value = ; |
() endif |
() isFound = false; |
() if node.branches != null then |
() for = 0 to node.branches.length − 1 do |
() if node.branches[].next.value == then |
() node.branches[].weight += (stateIds[]/); |
() node = node.branches[].next; |
() isFound = true; |
() break; |
() endif |
() endfor |
() endif |
() if isFound == false then |
() branch = new Branch( |
() weight = stateIds[]/, |
() next = new Node(value = , branches = null) |
() ); |
() node.branches.add(branch); |
() node = node.branches[node.branches.length − 1].next; |
() endif |
() //Merge the nodes of same values. |
() BranchShifting(root, node); |
() endfor |
() endfor |
() return root; |