java.lang.Object
model.logic.server.dictionary.LFU
All Implemented Interfaces:
CacheReplacementPolicy

public class LFU extends Object implements CacheReplacementPolicy
  • Constructor Summary

    Constructors
    Constructor
    Description
    LFU()
    The LFU function takes in a string and adds it to the LinkedHashMap words.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String word)
    The add function adds a word to the map.
    The remove function removes the least frequently used word from the cache.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LFU

      public LFU()
      The LFU function takes in a string and adds it to the LinkedHashMap words. If the word is already in the map, then its value is incremented by 1.
  • Method Details

    • add

      public void add(String word)
      The add function adds a word to the map. If the word is already in the map, it increments its count by 1. Otherwise, it adds a new entry with value 1.
      Specified by:
      add in interface CacheReplacementPolicy
      Parameters:
      word - word Add a word to the map
    • remove

      public String remove()
      The remove function removes the least frequently used word from the cache.
      Specified by:
      remove in interface CacheReplacementPolicy
      Returns:
      The key with the lowest value