Commit ce86ec25 authored by Adam Blank's avatar Adam Blank
Browse files

Merge branch 'bugfix-jan-14' into 'master'

Bugfix jan 14



See merge request !3
parents e168c273 21674cb3
No preview for this file type
......@@ -203,7 +203,11 @@ public abstract class TrieMap<A, K extends BString<A>, V> extends Dictionary<K,
}
public String toString() {
return this.root.toString();
if (this.root == null) {
return "null";
} else {
return this.root.toString();
}
}
}
......@@ -107,7 +107,17 @@ public class HuffmanCompressor
}
public int compareTo(Node other) {
return this.freq - other.freq;
int result = this.freq - other.freq;
if (result != 0) {
return result;
}
if (this.value == null) {
return 1;
}
else if (other.value == null) {
return -1;
}
return this.value.compareTo(other.value);
}
}
void reset() {
......
......@@ -32,8 +32,7 @@ public class SuffixTrie extends HashTrieMap<Byte, ByteString, Boolean> {
* To do this, we gradually shift elements from buffer to match as we
* determine that they are actually a match to a suffix in the trie.
*
* @postcondition pre(buffer) + pre(currentMatch) == post(buffer) + post(currentMatch)
* @postcondition currentMatch == suffix + b for the longest possible _partial_
* @postcondition currentMatch == suffix + b for the longest possible _partial_
* suffix in the trie and some single byte b
* @postcondition the node representing the last matched character in the trie
* is stored in this.lastMatchedNode (we might need this later)
......@@ -52,9 +51,9 @@ public class SuffixTrie extends HashTrieMap<Byte, ByteString, Boolean> {
* Then, the longest match is "abc", but this isn't a complete word in the trie.
* There is definitely a match; it's just a partial one.
*
* Regardless if you found a complete match or a partial match, you should return
* the total number of bytes you've matched against the buffer.
*
* If you find a COMPLETE match, you should return the total number of bytes you've
* matched against the buffer. Otherwise, you should return zero.
*
* When implementing this method, you should start by resetting this.lastMatchedNode,
* then start traversing from the root of the trie to try finding the new match. You
* should not traverse starting from the old value of this.lastMatchedNode. Make sure
......@@ -119,7 +118,8 @@ public class SuffixTrie extends HashTrieMap<Byte, ByteString, Boolean> {
* Adds the given byte to this.currentMatch. This method should
* NOT change this.lastMatchedNode.
*
* @precondition this.currentMatch.isFull() == false
* If the client tries adding a byte after this.currentMatch is full,
* you should do nothing.
*
* @param b the byte to add
*/
......@@ -155,15 +155,12 @@ public class SuffixTrie extends HashTrieMap<Byte, ByteString, Boolean> {
*
* 1. If the contents of the suffixtrie are at full capacity,
* shift off a byte and remove the whole word from the trie
* 2. Append b to the end of every stored node.
* 2. Append b to the end of every stored node
* 3. Re-insert the empty string back into the trie
*
* HINT: be sure to pay careful attention to how exactly you are updating
* your various fields, and how exactly they interact with one another. See the
* example and descriptions in the spec for more details about this method.
*
* @postcondition currentMatch.hasWork() == false
* @postcondition pre(current contents) + pre(currentMatch) == (shifted off) + post(current contents) + post(currentMatch)
*/
public void advance() {
throw new NotYetImplementedException();
......
......@@ -390,7 +390,9 @@ public class HashTrieMapTests extends TestsUtility {
STUDENT.delete(a("f"));
if (!equals(node(), getField(STUDENT, "root"))) {
boolean rootIsSingleNode = equals(node(), getField(STUDENT, "root"));
boolean rootIsNull = equals(null, getField(STUDENT, "root"));
if (!(rootIsSingleNode || rootIsNull)) {
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment