java.lang.Object
model.logic.server.dictionary.CacheManager
-
Constructor Summary
ConstructorsConstructorDescriptionCacheManager(int size, CacheReplacementPolicy crp) The CacheManager function is responsible for managing the cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidThe add function adds a word to the cache.booleanThe equals function is used to compare two objects.inthashCode()The hashCode function is used to generate a unique hash code for each instance of the class.booleanThe query function takes in a string and returns true if the word is in the dictionary, false otherwise.
-
Constructor Details
-
CacheManager
The CacheManager function is responsible for managing the cache. It will add a new entry to the cache if it does not exist, or update an existing one. If there is no space in the cache, it will remove an entry according to its replacement policy and then add/update as needed.- Parameters:
size- size Set the size of the cachecrp- crp Determine which cache replacement policy to use
-
-
Method Details
-
equals
The equals function is used to compare two objects. -
hashCode
public int hashCode()The hashCode function is used to generate a unique hash code for each instance of the class. This is useful when storing instances in HashMaps or HashSets, as it allows us to quickly determine if two objects are equal by comparing their hash codes. If two objects have the same hash code, they are not guaranteed to be equal (as there may be collisions), but if they do not have the same hash code, then we know that they cannot possibly be equal. Thus, we can avoid having to compare them at all! The default implementation of this function in Java uses each field in an object's -
query
The query function takes in a string and returns true if the word is in the dictionary, false otherwise.- Parameters:
word- word Check if the word is in the cache- Returns:
- A boolean value indicating if the word is in the trie
-
add
The add function adds a word to the cache. If the cache is full, it removes the least recently used word from both wordsCache and crp. Then, it adds the new word to both wordsCache and crp.- Parameters:
word- word Add a word to the cache
-