Class DirectCircularList<E>

java.lang.Object
math.DirectCircularList<E>

public class DirectCircularList<E> extends Object

Title: Direct Circular List

Description: This class implements a direct access O(1) fixed size circular list extremely useful for caching purposes.

Author:
Bertoli Marco Date: 14-feb-2006 Time: 11.17.24
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Object[]
     
    protected int
     
    protected int
     
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new DirectCircularList with specified size
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    exists(int index)
    Tells if specified element is present in the list.
    get(int index)
    Returns value for item in position index or null if it does not exist.
    int
    Returns size of this Circular List.
    void
    set(int index, E value)
    Sets element in position index to specified value.
    Used for debugging purposes: provides a string representation of every object in the data structure

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • last

      protected int last
    • lastIndex

      protected int lastIndex
    • data

      protected Object[] data
    • size

      protected int size
  • Constructor Details

    • DirectCircularList

      public DirectCircularList(int size)
      Creates a new DirectCircularList with specified size
      Parameters:
      size - maximum size of the data structure
  • Method Details

    • set

      public void set(int index, E value)
      Sets element in position index to specified value. This method is O(1) if values are inserted with adiacent indices, otherwise some computation is needed to mark null elements.
      Parameters:
      index - position of item to be set
      value - value for the item
    • get

      public E get(int index)
      Returns value for item in position index or null if it does not exist. This method is always O(1).
      Parameters:
      index - index of element to be retrieved
      Returns:
      requested element or null if it does not exist getSize()
    • exists

      public boolean exists(int index)
      Tells if specified element is present in the list. This method is O(1).
      Parameters:
      index - index of specified element
      Returns:
      true iff element is not null
    • getSize

      public int getSize()
      Returns size of this Circular List. This method is O(1).
      Returns:
      size of this Circular List
    • toString

      public String toString()
      Used for debugging purposes: provides a string representation of every object in the data structure
      Overrides:
      toString in class Object
      Returns:
      a string representation of every object in the data structure