diff --git a/src/main/java/com/redhat/trie/PathNode.java b/src/main/java/com/redhat/trie/PathNode.java index e57c663..245465f 100644 --- a/src/main/java/com/redhat/trie/PathNode.java +++ b/src/main/java/com/redhat/trie/PathNode.java @@ -194,20 +194,29 @@ public class PathNode { /** * 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()) { return false; } + if (this.getId() == that.getId()) { + return true; + } + for (NodePair thisnp : this.getChildren()) { boolean found = false; for (NodePair thatnp : that.getChildren()) { if (thisnp.getName().equals(thatnp.getName())) { - found = true; - break; + if(thisnp.getConnection().isEquivalentTo(thatnp.getConnection())) { + found = true; + break; + } + else { + return false; + } } } - if (!found) { return false; } diff --git a/src/main/java/com/redhat/trie/PathTree.java b/src/main/java/com/redhat/trie/PathTree.java index 5476cec..c1e62b2 100644 --- a/src/main/java/com/redhat/trie/PathTree.java +++ b/src/main/java/com/redhat/trie/PathTree.java @@ -193,7 +193,7 @@ public class PathTree { for (String name : this.byteArrayToStringList(baos.toByteArray())) { 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; } @@ -234,7 +234,12 @@ public class PathTree { } value = bais.read(); 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++) { this.getNodeBits().append("0"); } @@ -243,7 +248,7 @@ public class PathTree { } 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; @@ -408,7 +413,7 @@ public class PathTree { * * -- vbatts */ - //condenseSubTreeNodes(endMarker); + condenseSubTreeNodes(endMarker); 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 nodes) { int smallest = -1; for (int index = 0; index < nodes.size(); index++) { diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index 8967405..d3e623d 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -1,6 +1,6 @@ # Define the root logger with appender file #log = /usr/home/log4j -log4j.rootLogger = DEBUG, stderr +log4j.rootLogger = WARN, stderr log4j.appender.stderr= org.apache.log4j.ConsoleAppender #log4j.appender.stderr.Threshold=DEBUG diff --git a/src/test/java/com/redhat/trie/TestPathNode.java b/src/test/java/com/redhat/trie/TestPathNode.java index 6edbe53..a8d4e0a 100644 --- a/src/test/java/com/redhat/trie/TestPathNode.java +++ b/src/test/java/com/redhat/trie/TestPathNode.java @@ -26,11 +26,10 @@ public class TestPathNode { @Test public void testEquivalent() { - NodeContext ctx0 = new NodeContext(); - NodeContext ctx1 = new NodeContext(); + NodeContext ctx = new NodeContext(); PathNode endMarker = new PathNode(); - PathNode pn0 = new PathNode(ctx0); - PathNode pn1 = new PathNode(ctx1); + PathNode pn0 = new PathNode(ctx); + PathNode pn1 = new PathNode(ctx); assertTrue(pn0.isEquivalentTo(pn1)); diff --git a/src/test/java/com/redhat/trie/TestPathTree.java b/src/test/java/com/redhat/trie/TestPathTree.java index f261dac..b004915 100644 --- a/src/test/java/com/redhat/trie/TestPathTree.java +++ b/src/test/java/com/redhat/trie/TestPathTree.java @@ -164,7 +164,6 @@ public class TestPathTree { pt1 = new PathTree(bytes); contents1 = pt1.toList(); - // FIXME These next two fail when condenseSubTreeNodes is used .. assertTrue(TestHelpers.cmpStrings(contents0, contents1)); assertEquals(contents0.size(), contents1.size());