Class Heap


  • public final class Heap
    extends java.lang.Object
    the v2 CAS heap - used in modeling some binary (de)serialization
    • Constructor Summary

      Constructors 
      Constructor Description
      Heap()
      Default constructor.
      Heap​(int initialSize)
      Constructor lets you set initial heap size.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int add​(int[] fs)
      Add a structure to the heap.
      int add​(int len, int val)
      Reserve space for len items on the heap and set the first item to val.
      (package private) int getCellsUsed()
      Return the number of cells used (including slot 0 reserved for null)
      (package private) int getHeapSize()  
      int getInitialSize()  
      (package private) int[] getMetaData()  
      int getNextId()  
      (package private) static int getRoundedSize​(int size)  
      private void grow()  
      void grow​(int len)  
      private void initHeap()  
      private void initHeap​(int size)  
      (package private) void reinit​(int[] md, int[] shortHeap)  
      private void reinitNoMetaData​(int[] shortHeap)
      Re-init the heap without metadata.
      (package private) void reinitSizeOnly​(int newSize)
      Re-create the heap for the given size.
      void reset()
      Reset the temporary heap.
      (package private) void reset​(boolean doFullReset)
      Reset the temporary heap.
      int[] toArray()  
      • Methods inherited from class java.lang.Object

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

      • Heap

        public Heap()
        Default constructor.
      • Heap

        public Heap​(int initialSize)
        Constructor lets you set initial heap size. Use only if you know what you're doing.
        Parameters:
        initialSize - The initial heap size. If this is smaller than the MIN_SIZE, the default will be used instead.
    • Method Detail

      • initHeap

        private void initHeap()
      • initHeap

        private void initHeap​(int size)
      • reinit

        void reinit​(int[] md,
                    int[] shortHeap)
      • reinitNoMetaData

        private void reinitNoMetaData​(int[] shortHeap)
        Re-init the heap without metadata. Use default values for metadata.
        Parameters:
        shortHeap -
      • reinitSizeOnly

        void reinitSizeOnly​(int newSize)
        Re-create the heap for the given size. Just use the size of the incoming heap, unless it's smaller than our minimum. It is expected that the caller will then fill in the new heap up to newSize.
        Parameters:
        newSize -
      • getCellsUsed

        int getCellsUsed()
        Return the number of cells used (including slot 0 reserved for null)
      • getHeapSize

        int getHeapSize()
        Returns:
        The overall size of the heap (in words) (including unused space).
      • getMetaData

        int[] getMetaData()
      • grow

        private void grow()
      • getRoundedSize

        static int getRoundedSize​(int size)
      • reset

        public void reset()
        Reset the temporary heap.
      • reset

        void reset​(boolean doFullReset)
        Reset the temporary heap. Logic for shrinking: Based on a short history of the sizes needed to hold the larger of the previous 2 sizes (Note: can be overridden by calling reset() multiple times in a row) Never shrink below initialSize Shrink in exact reverse sequence of growth - using the subtraction method and then (for small enough sizes) the dividing method Shrink 1/2 the distance to the size needed to hold the large of the prev 2 sizes
      • add

        public int add​(int[] fs)
        Add a structure to the heap.
        Parameters:
        fs - The input structure.
        Returns:
        The position where the structure was added, i.e., a pointer to the first element of the structure.
      • add

        public int add​(int len,
                       int val)
        Reserve space for len items on the heap and set the first item to val. The other items are set to 0.
        Parameters:
        len - The length of the new structure.
        val - The value of the first cell in the new structure.
        Returns:
        The position where the structure was added, i.e., a pointer to the first element of the structure.
      • getNextId

        public int getNextId()
      • grow

        public void grow​(int len)
      • getInitialSize

        public int getInitialSize()
      • toArray

        public int[] toArray()