Class IntrusiveDoublyLinkedQueue<VALUE_TYPE>
java.lang.Object
io.deephaven.util.datastructures.linked.IntrusiveDoublyLinkedStructureBase<VALUE_TYPE>
io.deephaven.util.datastructures.linked.IntrusiveDoublyLinkedQueue<VALUE_TYPE>
- All Implemented Interfaces:
Iterable<VALUE_TYPE>
public class IntrusiveDoublyLinkedQueue<VALUE_TYPE>
extends IntrusiveDoublyLinkedStructureBase<VALUE_TYPE>
implements Iterable<VALUE_TYPE>
A simple queue based on circular intrusive doubly linked nodes (for O(1) random removal).
-
Nested Class Summary
Nested classes/interfaces inherited from class io.deephaven.util.datastructures.linked.IntrusiveDoublyLinkedStructureBase
IntrusiveDoublyLinkedStructureBase.Adapter<NODE_TYPE> -
Constructor Summary
ConstructorsConstructorDescriptionIntrusiveDoublyLinkedQueue(@NotNull IntrusiveDoublyLinkedStructureBase.Adapter<VALUE_TYPE> adapter) Construct a new queue -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclear()Remove and unlink all nodes in the queue.final voidRemove all nodes in the queue, without unlinking anything.final booleancontains(VALUE_TYPE node) Determine if a node is currently in the queue.final voidinsert(VALUE_TYPE node, int offset) Add a node at the specified offset into the queue.final voidinsertBefore(VALUE_TYPE node, VALUE_TYPE other) Insertnodebeforeother.final booleanisEmpty()Test if the queue is empty.@NotNull Iterator<VALUE_TYPE>iterator()final booleanoffer(VALUE_TYPE node) Add a node at the end of the queue.final VALUE_TYPEpeek()Get the node at the front of the queue without modifying the queue.final VALUE_TYPEpoll()Remove and get the node at the front of the queue.final VALUE_TYPEremove()Remove and get the node at the front of the queue.final booleanremove(VALUE_TYPE node) Remove a node from the queue.final intsize()Get the size of this queue.@NotNull Stream<VALUE_TYPE>stream()final voidtransferAfterTailFrom(@NotNull IntrusiveDoublyLinkedQueue<VALUE_TYPE> other) Move all nodes fromotherto the back of this queue in O(1) time.final voidtransferBeforeHeadFrom(@NotNull IntrusiveDoublyLinkedQueue<VALUE_TYPE> other) Move all nodes fromotherto the front of this queue in O(1) time.Methods inherited from class io.deephaven.util.datastructures.linked.IntrusiveDoublyLinkedStructureBase
compatible, getNext, getPrev, isLinked, linkAfter, linkBefore, setNext, setPrev, unlink
-
Constructor Details
-
IntrusiveDoublyLinkedQueue
public IntrusiveDoublyLinkedQueue(@NotNull @NotNull IntrusiveDoublyLinkedStructureBase.Adapter<VALUE_TYPE> adapter) Construct a new queue- Parameters:
adapter- The adapter for updating a node's next and previous nodes.
-
-
Method Details
-
isEmpty
public final boolean isEmpty()Test if the queue is empty.- Returns:
- Whether the queue is empty
-
size
public final int size()Get the size of this queue.- Returns:
- The size of the queue
-
transferBeforeHeadFrom
public final void transferBeforeHeadFrom(@NotNull @NotNull IntrusiveDoublyLinkedQueue<VALUE_TYPE> other) Move all nodes fromotherto the front of this queue in O(1) time.- Parameters:
other- The queue to transfer from
-
transferAfterTailFrom
public final void transferAfterTailFrom(@NotNull @NotNull IntrusiveDoublyLinkedQueue<VALUE_TYPE> other) Move all nodes fromotherto the back of this queue in O(1) time.- Parameters:
other- The queue to transfer from
-
offer
Add a node at the end of the queue.- Parameters:
node- The node to add- Returns:
- true
-
insert
Add a node at the specified offset into the queue. This is necessarily an O(n) operation.- Parameters:
node- The node to addoffset- The offset (in [0, size()] to add the node at
-
insertBefore
Insertnodebeforeother. Ifotherisnull, inserts at the end. This is intended for use in a pattern combined with iteration.- Parameters:
node- The node to insertother- The node to insert before; ifnullthen this method is the same asoffer(node)
-
peek
Get the node at the front of the queue without modifying the queue.- Returns:
- The current head of the queue, or null if the queue is empty
-
poll
Remove and get the node at the front of the queue.- Returns:
- The node at the head of the queue (now removed)
-
remove
Remove and get the node at the front of the queue.- Returns:
- The node at the head of the queue (now removed)
- Throws:
NoSuchElementException- If the queue is empty
-
remove
Remove a node from the queue.- Parameters:
node- The node to remove- Returns:
- Whether the node was in the queue (and now removed)
-
clear
public final void clear()Remove and unlink all nodes in the queue. -
clearFast
public final void clearFast()Remove all nodes in the queue, without unlinking anything. This is suitable for nodes that will be discarded. -
contains
Determine if a node is currently in the queue. Assumes that the node's prev/next pointers are only used in this queue.- Parameters:
node- The node- Returns:
- Whether the node is currently in the queue
-
iterator
- Specified by:
iteratorin interfaceIterable<VALUE_TYPE>
-
spliterator
- Specified by:
spliteratorin interfaceIterable<VALUE_TYPE>
-
stream
-