Class ByteSemiIndirectHeaps

java.lang.Object
it.unimi.dsi.fastutil.bytes.ByteSemiIndirectHeaps

public final class ByteSemiIndirectHeaps extends Object
A class providing static methods and objects that do useful things with semi-indirect heaps.

A semi-indirect heap is based on a reference array. Elements of a semi-indirect heap are integers that index the reference array (note that in an indirect heap you can also map elements of the reference array to heap positions).

  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    downHeap(byte[] refArray, int[] heap, int size, int i, ByteComparator c)
    Moves the given element down into the semi-indirect heap until it reaches the lowest possible position.
    static int
    front(byte[] refArray, int[] heap, int size, int[] a)
    Retrieves the front of a heap in a given array.
    static int
    front(byte[] refArray, int[] heap, int size, int[] a, ByteComparator c)
    Retrieves the front of a heap in a given array using a given comparator.
    static void
    makeHeap(byte[] refArray, int[] heap, int size, ByteComparator c)
    Creates a semi-indirect heap from a given index array.
    static void
    makeHeap(byte[] refArray, int offset, int length, int[] heap, ByteComparator c)
    Creates a semi-indirect heap in the given array.
    static int[]
    makeHeap(byte[] refArray, int offset, int length, ByteComparator c)
    Creates a semi-indirect heap, allocating its heap array.
    static int
    upHeap(byte[] refArray, int[] heap, int size, int i, ByteComparator c)
    Moves the given element up in the semi-indirect heap until it reaches the highest possible position.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • downHeap

      public static int downHeap(byte[] refArray, int[] heap, int size, int i, ByteComparator c)
      Moves the given element down into the semi-indirect heap until it reaches the lowest possible position.
      Parameters:
      refArray - the reference array.
      heap - the semi-indirect heap (starting at 0).
      size - the number of elements in the heap.
      i - the index in the heap of the element to be moved down.
      c - a type-specific comparator, or null for the natural order.
      Returns:
      the new position in the heap of the element of heap index i.
    • upHeap

      public static int upHeap(byte[] refArray, int[] heap, int size, int i, ByteComparator c)
      Moves the given element up in the semi-indirect heap until it reaches the highest possible position.
      Parameters:
      refArray - the reference array.
      heap - the semi-indirect heap (starting at 0).
      size - the number of elements in the heap.
      i - the index in the heap of the element to be moved up.
      c - a type-specific comparator, or null for the natural order.
      Returns:
      the new position in the heap of the element of heap index i.
    • makeHeap

      public static void makeHeap(byte[] refArray, int offset, int length, int[] heap, ByteComparator c)
      Creates a semi-indirect heap in the given array.
      Parameters:
      refArray - the reference array.
      offset - the first element of the reference array to be put in the heap.
      length - the number of elements to be put in the heap.
      heap - the array where the heap is to be created.
      c - a type-specific comparator, or null for the natural order.
    • makeHeap

      public static int[] makeHeap(byte[] refArray, int offset, int length, ByteComparator c)
      Creates a semi-indirect heap, allocating its heap array.
      Parameters:
      refArray - the reference array.
      offset - the first element of the reference array to be put in the heap.
      length - the number of elements to be put in the heap.
      c - a type-specific comparator, or null for the natural order.
      Returns:
      the heap array.
    • makeHeap

      public static void makeHeap(byte[] refArray, int[] heap, int size, ByteComparator c)
      Creates a semi-indirect heap from a given index array.
      Parameters:
      refArray - the reference array.
      heap - an array containing indices into refArray.
      size - the number of elements in the heap.
      c - a type-specific comparator, or null for the natural order.
    • front

      public static int front(byte[] refArray, int[] heap, int size, int[] a)
      Retrieves the front of a heap in a given array.

      The front of a semi-indirect heap is the set of indices whose associated elements in the reference array are equal to the element associated to the first index.

      In several circumstances you need to know the front, and scanning linearly the entire heap is not the best strategy. This method simulates (using a partial linear scan) a breadth-first visit that terminates when all visited nodes are larger than the element associated to the top index, which implies that no elements of the front can be found later. In most cases this trick yields a significant improvement.

      Parameters:
      refArray - the reference array.
      heap - an array containing indices into refArray.
      size - the number of elements in the heap.
      a - an array large enough to hold the front (e.g., at least long as refArray).
      Returns:
      the number of elements actually written (starting from the first position of a).
    • front

      public static int front(byte[] refArray, int[] heap, int size, int[] a, ByteComparator c)
      Retrieves the front of a heap in a given array using a given comparator.

      The front of a semi-indirect heap is the set of indices whose associated elements in the reference array are equal to the element associated to the first index.

      In several circumstances you need to know the front, and scanning linearly the entire heap is not the best strategy. This method simulates (using a partial linear scan) a breadth-first visit that terminates when all visited nodes are larger than the element associated to the top index, which implies that no elements of the front can be found later. In most cases this trick yields a significant improvement.

      Parameters:
      refArray - the reference array.
      heap - an array containing indices into refArray.
      size - the number of elements in the heap.
      a - an array large enough to hold the front (e.g., at least long as refArray).
      c - a type-specific comparator.
      Returns:
      the number of elements actually written (starting from the first position of a).