public class ByteSemiIndirectHeaps extends Object
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).
Modifier and Type | Method and 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 int[] |
makeHeap(byte[] refArray,
int offset,
int length,
ByteComparator c)
Creates a semi-indirect heap, allocating its heap 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 |
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.
|
public static int downHeap(byte[] refArray, int[] heap, int size, int i, ByteComparator c)
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.i
.public static int upHeap(byte[] refArray, int[] heap, int size, int i, ByteComparator c)
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.i
.public static void makeHeap(byte[] refArray, int offset, int length, int[] heap, ByteComparator c)
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.public static int[] makeHeap(byte[] refArray, int offset, int length, ByteComparator c)
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.public static void makeHeap(byte[] refArray, int[] heap, int size, ByteComparator c)
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.public static int front(byte[] refArray, int[] heap, int size, int[] a)
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.
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
).a
).public static int front(byte[] refArray, int[] heap, int size, int[] a, ByteComparator c)
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.
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.a
).