wottop just posted a fix for the isEquivalentTo() logic, which fixes the

condense sub tree logic
This commit is contained in:
Vincent Batts 2012-12-07 10:27:22 -05:00
parent b296506b6e
commit 0d00f4ad00
5 changed files with 30 additions and 14 deletions

View file

@ -194,20 +194,29 @@ public class PathNode {
/** /**
* same number of children with the same names for child nodes * same number of children with the same names for child nodes
*/ */
public boolean isEquivalentTo(PathNode that) { boolean isEquivalentTo(PathNode that) {
// same number of children with the same names for child nodes
if (this.getChildren().size() != that.getChildren().size()) { if (this.getChildren().size() != that.getChildren().size()) {
return false; return false;
} }
if (this.getId() == that.getId()) {
return true;
}
for (NodePair thisnp : this.getChildren()) { for (NodePair thisnp : this.getChildren()) {
boolean found = false; boolean found = false;
for (NodePair thatnp : that.getChildren()) { for (NodePair thatnp : that.getChildren()) {
if (thisnp.getName().equals(thatnp.getName())) { if (thisnp.getName().equals(thatnp.getName())) {
if(thisnp.getConnection().isEquivalentTo(thatnp.getConnection())) {
found = true; found = true;
break; break;
} }
else {
return false;
}
}
} }
if (!found) { if (!found) {
return false; return false;
} }

View file

@ -193,7 +193,7 @@ public class PathTree {
for (String name : this.byteArrayToStringList(baos.toByteArray())) { for (String name : this.byteArrayToStringList(baos.toByteArray())) {
this.pathDictionary.add(new HuffNode(getHuffNodeContext(), name, weight++)); this.pathDictionary.add(new HuffNode(getHuffNodeContext(), name, weight++));
} }
this.pathDictionary.add(new HuffNode(HuffNode.END_NODE, weight)); this.pathDictionary.add(new HuffNode(getHuffNodeContext(), HuffNode.END_NODE, weight));
} }
return this.pathDictionary; return this.pathDictionary;
} }
@ -234,7 +234,12 @@ public class PathTree {
} }
value = bais.read(); value = bais.read();
while (value != -1) { while (value != -1) {
String someBits = Integer.toString(value, 2); String someBits = Integer.toString(value, 2); // string of binary for the byte
// ensure there are zeros to fill the space,
// such that each 8 positions is a single node
// XXX if the mapping for nodes is confined to 8 bits,
// then we can't have more than 255 unique nodes?
for (int pad = 0; pad < 8 - someBits.length(); pad++) { for (int pad = 0; pad < 8 - someBits.length(); pad++) {
this.getNodeBits().append("0"); this.getNodeBits().append("0");
} }
@ -243,7 +248,7 @@ public class PathTree {
} }
for (int j = 0; j < this.getNodeCount(); j++) { for (int j = 0; j < this.getNodeCount(); j++) {
this.nodeDictionary.add(new HuffNode(new PathNode(getPathNodeContext()), j)); this.nodeDictionary.add(new HuffNode(getHuffNodeContext(), new PathNode(getPathNodeContext()), j));
} }
} }
return this.nodeDictionary; return this.nodeDictionary;
@ -408,7 +413,7 @@ public class PathTree {
* *
* -- vbatts * -- vbatts
*/ */
//condenseSubTreeNodes(endMarker); condenseSubTreeNodes(endMarker);
return parent; return parent;
} }
@ -536,6 +541,10 @@ public class PathTree {
} }
} }
/** Return the weight of the smallest weighted node of the nodes list.
*
* You can pass a index of the list to skip (-1 will not skip any index)
*/
private int findSmallest(int exclude, List<HuffNode> nodes) { private int findSmallest(int exclude, List<HuffNode> nodes) {
int smallest = -1; int smallest = -1;
for (int index = 0; index < nodes.size(); index++) { for (int index = 0; index < nodes.size(); index++) {

View file

@ -1,6 +1,6 @@
# Define the root logger with appender file # Define the root logger with appender file
#log = /usr/home/log4j #log = /usr/home/log4j
log4j.rootLogger = DEBUG, stderr log4j.rootLogger = WARN, stderr
log4j.appender.stderr= org.apache.log4j.ConsoleAppender log4j.appender.stderr= org.apache.log4j.ConsoleAppender
#log4j.appender.stderr.Threshold=DEBUG #log4j.appender.stderr.Threshold=DEBUG

View file

@ -26,11 +26,10 @@ public class TestPathNode {
@Test @Test
public void testEquivalent() { public void testEquivalent() {
NodeContext ctx0 = new NodeContext(); NodeContext ctx = new NodeContext();
NodeContext ctx1 = new NodeContext();
PathNode endMarker = new PathNode(); PathNode endMarker = new PathNode();
PathNode pn0 = new PathNode(ctx0); PathNode pn0 = new PathNode(ctx);
PathNode pn1 = new PathNode(ctx1); PathNode pn1 = new PathNode(ctx);
assertTrue(pn0.isEquivalentTo(pn1)); assertTrue(pn0.isEquivalentTo(pn1));

View file

@ -164,7 +164,6 @@ public class TestPathTree {
pt1 = new PathTree(bytes); pt1 = new PathTree(bytes);
contents1 = pt1.toList(); contents1 = pt1.toList();
// FIXME These next two fail when condenseSubTreeNodes is used ..
assertTrue(TestHelpers.cmpStrings(contents0, contents1)); assertTrue(TestHelpers.cmpStrings(contents0, contents1));
assertEquals(contents0.size(), contents1.size()); assertEquals(contents0.size(), contents1.size());