LongArrayQueue


@UnstableApi
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

const Int

Default initial capacity.

Public constructors

Creates a queue with an initial capacity of DEFAULT_INITIAL_CAPACITY.

LongArrayQueue(minCapacity: Int)

Creates a queue with capacity for at least minCapacity

Public functions

Unit
add(value: Long)

Add a new item to the queue.

Unit

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

const val DEFAULT_INITIAL_CAPACITY = 16: Int

Default initial capacity.

Public constructors

LongArrayQueue

LongArrayQueue()

Creates a queue with an initial capacity of DEFAULT_INITIAL_CAPACITY.

LongArrayQueue

LongArrayQueue(minCapacity: Int)

Creates a queue with capacity for at least minCapacity

Parameters
minCapacity: Int

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

Public functions

add

fun add(value: Long): Unit

Add a new item to the queue.

clear

fun clear(): Unit

Clears the queue.

element

fun element(): Long

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

Throws
java.util.NoSuchElementException

if the queue is empty.

isEmpty

fun isEmpty(): Boolean

Returns whether the queue is empty.

remove

fun remove(): Long

Remove an item from the queue.

Throws
java.util.NoSuchElementException

if the queue is empty.

size

fun size(): Int

Returns the number of items in the queue.