LongArrayQueue


@UnstableApi
public final class LongArrayQueue


Array-based unbounded queue for long primitives with amortized O(1) add and remove.

Use this class instead of a java.util.Deque to avoid boxing long primitives to instances.

Summary

Constants

static final int

Default initial capacity.

Public constructors

Creates a queue with an initial capacity of DEFAULT_INITIAL_CAPACITY.

LongArrayQueue(int minCapacity)

Creates a queue with capacity for at least minCapacity

Public methods

void
add(long value)

Add a new item to the queue.

void

Clears the queue.

long

Retrieves, but does not remove, the head of the queue.

boolean

Returns whether the queue is empty.

long

Remove an item from the queue.

int

Returns the number of items in the queue.

Constants

DEFAULT_INITIAL_CAPACITY

public static final int DEFAULT_INITIAL_CAPACITY = 16

Default initial capacity.

Public constructors

LongArrayQueue

public LongArrayQueue()

Creates a queue with an initial capacity of DEFAULT_INITIAL_CAPACITY.

LongArrayQueue

public LongArrayQueue(int minCapacity)

Creates a queue with capacity for at least minCapacity

Parameters
int minCapacity

minCapacity the minimum capacity, between 1 and 2^30 inclusive

Public methods

add

public void add(long value)

Add a new item to the queue.

clear

public void clear()

Clears the queue.

element

public long element()

Retrieves, but does not remove, the head of the queue.

Throws
java.util.NoSuchElementException

if the queue is empty.

isEmpty

public boolean isEmpty()

Returns whether the queue is empty.

remove

public long remove()

Remove an item from the queue.

Throws
java.util.NoSuchElementException

if the queue is empty.

size

public int size()

Returns the number of items in the queue.