Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cse332-22au/p2-public
  • cse332-22sp/p2-public
  • cse332-22su/p2-public
  • cse332-23wi/p2-public
  • cse332-23sp/p2-public
  • cse332-23su/p2-public
  • cse332-23au/p2-public
  • cse332-24wi/p2-public
  • yc888/p-2-public-yc-888
  • ajk1004/p2-public
  • gpletosu/p2-public
  • cse332-24sp/p2-public
  • samganyx/p2-public
13 results
Show changes
Commits on Source (10)
......@@ -9,23 +9,24 @@ import java.util.Iterator;
import java.util.function.Supplier;
/**
* 1. You must implement a generic chaining hashtable. You may not
* restrict the size of the input domain (i.e., it must accept
* any key) or the number of inputs (i.e., it must grow as necessary).
* 3. Your HashTable should rehash as appropriate (use load factor as
* shown in class!).
* 5. HashTable should be able to resize its capacity to prime numbers for more
* than 200,000 elements. After more than 200,000 elements, it should
* continue to resize using some other mechanism.
* 6. We suggest you hard code some prime numbers. You can use this
* list: http://primes.utm.edu/lists/small/100000.txt
* NOTE: Do NOT copy the whole list!
* 7. When implementing your iterator, you should NOT copy every item to another
* dictionary/list and return that dictionary/list's iterator.
* - You must implement a generic chaining hashtable. You may not
* restrict the size of the input domain (i.e., it must accept
* any key) or the number of inputs (i.e., it must grow as necessary).
*
* - ChainingHashTable should rehash as appropriate (use load factor as shown in lecture!).
*
* - ChainingHashTable must resize its capacity into prime numbers via given PRIME_SIZES list.
* Past this, it should continue to resize using some other mechanism (primes not necessary).
*
* - When implementing your iterator, you should NOT copy every item to another
* dictionary/list and return that dictionary/list's iterator.
*/
public class ChainingHashTable<K, V> extends DeletelessDictionary<K, V> {
private Supplier<Dictionary<K, V>> newChain;
static final int[] PRIME_SIZES =
{11, 23, 47, 97, 193, 389, 773, 1549, 3089, 6173, 12347, 24697, 49393, 98779, 197573, 395147};
public ChainingHashTable(Supplier<Dictionary<K, V>> newChain) {
this.newChain = newChain;
}
......
......@@ -9,9 +9,7 @@ public class TopKSort {
sort(array, k, (x, y) -> x.compareTo(y));
}
/**
* Behaviour is undefined when k > array.length
*/
public static <E> void sort(E[] array, int k, Comparator<E> comparator) {
throw new NotYetImplementedException();
}
......
......@@ -7,6 +7,8 @@ import cse332.misc.LargeValueFirstItemComparator;
import cse332.sorts.InsertionSort;
import cse332.types.AlphabeticString;
import cse332.types.NGram;
import p2.sorts.QuickSort;
import p2.sorts.TopKSort;
import java.util.Comparator;
import java.util.Iterator;
......
package provided;
import cse332.datastructures.containers.Item;
import cse332.datastructures.trees.BinarySearchTree;
import cse332.interfaces.misc.Dictionary;
import datastructures.dictionaries.ChainingHashTable;
import datastructures.dictionaries.MoveToFrontList;
......@@ -25,8 +26,11 @@ public class ChainingHashTableTests {
@Test()
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void test_insertFind_manyElements_correctStructure() {
ChainingHashTable<String, Integer> list = new ChainingHashTable<>(MoveToFrontList::new);
/*
Replace BinarySearchTree with your own Dictionary implementations like MoveToFrontList or AVLTree
to test them as chains for the ChainingHashTable (highly recommended to find potential bugs)
* */
ChainingHashTable<String, Integer> list = new ChainingHashTable<>(BinarySearchTree::new);
int n = 1000;
// Add them
......
package provided;
import cse332.types.AlphabeticString;
import datastructures.dictionaries.HashTrieSet;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.*;
public class HashTrieSetTests {
/**
* Test to check if HashTrieSet has been copied over from P1
* */
@Test()
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void test_isHashTrieSetAvailable() {
HashTrieSet<Character, AlphabeticString> STUDENT = new HashTrieSet<>(AlphabeticString.class);
String[] words = {"dog", "doggy", "doge", "dragon", "cat", "draggin"};
String[] invalid = {"d", "cataract", "", "do"};
for (String word: words) {
STUDENT.add(a(word));
}
assertEquals(6, STUDENT.size());
for (String word: words) {
assertTrue(STUDENT.contains(a(word)));
}
for (String invalid_word: invalid) {
assertFalse(STUDENT.contains(a(invalid_word)));
}
}
private static AlphabeticString a(String s) {
return new AlphabeticString(s);
}
}