Skip to content

Commit

Permalink
Update for release
Browse files Browse the repository at this point in the history
  • Loading branch information
boiseamit committed Oct 30, 2024
1 parent 0e69e0c commit ebe45d5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Examples:
### 4.3. Class Design
We will need a `BTree` class as well as a `BTreeNode` class. The `BTreeNode` class may be an
inner class in the main `BTree` class. The objects that we store in the BTree will be similar
to the objects we stored in the previous `Hashtable` assignment. You should call the relevant
to the objects we stored in the previous `Hashtable` assignment. You should use the relevant
class `TreeObject` to represent the objects using the `Comparable` interface.

### 4.4 Priority Queues
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/cs321/btree/TreeObject.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,95 @@
package cs321.btree;

/**
* A class that holds a key value and its count. The key value is a string of up
* to 32 characters. The size is limited to make data storage on disk simpler.
*
* @author amit, andre, natalie
*/
public class TreeObject implements Comparable<TreeObject> {

private String key;
private long count;
private static final int SIZE = 64; //#bytes

/**
* Create a TreeObject with the given key.
* @param key
*/
public TreeObject(String key) {
this.key = key;
this.count = 1;
}

/**
* Create a TreeObject with the given key and count.
* @param key
* @param count
*/
public TreeObject(String key, long count) {
this.key = key;
this.count = count;
}

/**
* Getter for the key.
* @return the key
*/
public String getKey() {
return key;
}

/**
* Setter for the key. Unlikely to be needed.
* @param key
*/
public void setKey(String key) {
this.key = key;
}

/**
* Get the frequency (aka count) for the key contained in this TreeObject.
* @return
*/
public long getCount() {
return count;
}

/**
* Set the count value.
* @param count
*/
public void setCount(long count) {
this.count = count;
}


/**
* Increment the count for the key.
*/
public void incCount() {
count++;
}


/**
* {@inheritDoc}
*/
@Override
public String toString() {
return key + " " + this.count;
}


/**
* Returns the size of the disk
* @return SIZE - the Disk's size
*/
public static int getDiskSize() { return SIZE;}


/**
* Two TreeObjects are equal if they contain equal keys.
* @param o the object to be compared.
* @return
*/
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/cs321/btree/BTreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
* Unit testing for BTree constructors, Insert, Search and
* some TreeObject interactions in the BTree (such as counting duplicates)
*
* Note some tests use Alphabetic letters as keys, using the simple
* mapping that key = index of letter in English alphabet.
* e.g. 'A' = 1, 'B' = 2 etc.
* Note some tests use Alphabetic letters as keys and follow the examples
* given in the textbook.
*
* This is to provide more complicated tests that can be modeled
* after figures in the CLRS textbook.
* @author CS321 instructors
*/
public class BTreeTest {

Expand Down

0 comments on commit ebe45d5

Please sign in to comment.