Class AbstractPolicy

  • All Implemented Interfaces:
    Policy
    Direct Known Subclasses:
    FifoPolicy, LfuPolicy, LruPolicy

    public abstract class AbstractPolicy
    extends java.lang.Object
    implements Policy
    A base policy class
    Author:
    Greg Luck
    • Constructor Detail

      • AbstractPolicy

        public AbstractPolicy()
    • Method Detail

      • calculateSampleSize

        public static int calculateSampleSize​(int populationSize)
        sampleSize how many samples to take
        Parameters:
        populationSize - the size of the store
        Returns:
        the smaller of the map size and the default sample size of 30
      • selectedBasedOnPolicy

        public Element selectedBasedOnPolicy​(Element[] sampledElements,
                                             Element justAdded)
        Finds the best eviction candidate based on the sampled elements. What distuingishes this approach from the classic data structures approach, is that an Element contains metadata which can be used for making policy decisions, while generic data structures do not.
        Specified by:
        selectedBasedOnPolicy in interface Policy
        Parameters:
        sampledElements - this should be a random subset of the population
        justAdded - we never want to select the element just added. May be null.
        Returns:
        the least hit
      • generateRandomSample

        public static int[] generateRandomSample​(int populationSize)
        Generates a random sample from a population
        Parameters:
        populationSize - the size to draw from
        Returns:
        a list of random offsets