moving the list copying inside the makeTrie, so the argument object is
not destroyed
This commit is contained in:
parent
2a9511cbe5
commit
5a3abc75a1
1 changed files with 18 additions and 18 deletions
|
@ -419,26 +419,30 @@ public class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public HuffNode makeTrie(List<HuffNode> nodesList) {
|
public HuffNode makeTrie(List<HuffNode> nodesList) {
|
||||||
|
List<HuffNode> trieNodesList = new ArrayList<HuffNode>();
|
||||||
|
|
||||||
|
trieNodesList.addAll(nodesList);
|
||||||
|
|
||||||
// drop the first node if path node value, it is not needed
|
// drop the first node if path node value, it is not needed
|
||||||
if (nodesList.get(0).getValue() instanceof PathNode) {
|
if (trieNodesList.get(0).getValue() instanceof PathNode) {
|
||||||
nodesList.remove(0);
|
trieNodesList.remove(0);
|
||||||
}
|
}
|
||||||
while (nodesList.size() > 1) {
|
while (trieNodesList.size() > 1) {
|
||||||
int node1 = findSmallest(-1, nodesList);
|
int node1 = findSmallest(-1, trieNodesList);
|
||||||
int node2 = findSmallest(node1, nodesList);
|
int node2 = findSmallest(node1, trieNodesList);
|
||||||
HuffNode hn1 = nodesList.get(node1);
|
HuffNode hn1 = trieNodesList.get(node1);
|
||||||
HuffNode hn2 = nodesList.get(node2);
|
HuffNode hn2 = trieNodesList.get(node2);
|
||||||
HuffNode merged = mergeNodes(hn1, hn2);
|
HuffNode merged = mergeNodes(hn1, hn2);
|
||||||
nodesList.remove(hn1);
|
trieNodesList.remove(hn1);
|
||||||
nodesList.remove(hn2);
|
trieNodesList.remove(hn2);
|
||||||
nodesList.add(merged);
|
trieNodesList.add(merged);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (treeDebug) {
|
if (treeDebug) {
|
||||||
printTrie(nodesList.get(0), 0);
|
printTrie(trieNodesList.get(0), 0);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return nodesList.get(0);
|
return trieNodesList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] byteProcess(List<String> entries)
|
private byte[] byteProcess(List<String> entries)
|
||||||
|
@ -515,9 +519,7 @@ public class Util {
|
||||||
pathDictionary.add(new HuffNode(getHuffNodeContext(), name, weight++));
|
pathDictionary.add(new HuffNode(getHuffNodeContext(), name, weight++));
|
||||||
}
|
}
|
||||||
pathDictionary.add(new HuffNode(HuffNode.END_NODE, weight));
|
pathDictionary.add(new HuffNode(HuffNode.END_NODE, weight));
|
||||||
List<HuffNode> triePathDictionary = new ArrayList<HuffNode>();
|
HuffNode pathTrie = makeTrie(pathDictionary);
|
||||||
triePathDictionary.addAll(pathDictionary);
|
|
||||||
HuffNode pathTrie = makeTrie(triePathDictionary);
|
|
||||||
|
|
||||||
StringBuffer nodeBits = new StringBuffer();
|
StringBuffer nodeBits = new StringBuffer();
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(payload,
|
ByteArrayInputStream bais = new ByteArrayInputStream(payload,
|
||||||
|
@ -546,9 +548,7 @@ public class Util {
|
||||||
for (int j = 0; j < nodeCount; j++) {
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
nodeDictionary.add(new HuffNode(new PathNode(), j));
|
nodeDictionary.add(new HuffNode(new PathNode(), j));
|
||||||
}
|
}
|
||||||
List<HuffNode> trieNodeDictionary = new ArrayList<HuffNode>();
|
HuffNode nodeTrie = makeTrie(nodeDictionary);
|
||||||
trieNodeDictionary.addAll(nodeDictionary);
|
|
||||||
HuffNode nodeTrie = makeTrie(trieNodeDictionary);
|
|
||||||
|
|
||||||
// populate the PathNodes so we can rebuild the cool url tree
|
// populate the PathNodes so we can rebuild the cool url tree
|
||||||
Set<PathNode> pathNodes = populatePathNodes(nodeDictionary,
|
Set<PathNode> pathNodes = populatePathNodes(nodeDictionary,
|
||||||
|
|
Loading…
Reference in a new issue