Class IntrusiveDoublyLinkedQueue<VALUE_TYPE>
java.lang.Object
com.illumon.util.datastructures.linked.IntrusiveDoublyLinkedStructureBase<VALUE_TYPE>
com.illumon.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 com.illumon.util.datastructures.linked.IntrusiveDoublyLinkedStructureBase
IntrusiveDoublyLinkedStructureBase.Adapter<NODE_TYPE>
-
Constructor Summary
Constructors Constructor Description IntrusiveDoublyLinkedQueue(IntrusiveDoublyLinkedStructureBase.Adapter<VALUE_TYPE> adapter)
Construct a new queue -
Method Summary
Modifier and Type Method Description void
clear()
Remove and unlink all nodes in the queue.void
clearFast()
Remove all nodes in the queue, without unlinking anything.boolean
contains(VALUE_TYPE node)
Determine if a node is currently in the queue.void
insert(VALUE_TYPE node, int offset)
Add a node at the the specified offset into the queue.boolean
isEmpty()
Test if the queue is empty.Iterator<VALUE_TYPE>
iterator()
boolean
offer(VALUE_TYPE node)
Add a node at the end of the queue.VALUE_TYPE
peek()
Get the node at the front of the queue without modifying the queue.VALUE_TYPE
poll()
Remove and get the node at the front of the queue.VALUE_TYPE
remove()
Remove and get the node at the front of the queue.boolean
remove(VALUE_TYPE node)
Remove a node from the queue.int
size()
Get the size of this queue.Spliterator<VALUE_TYPE>
spliterator()
Stream<VALUE_TYPE>
stream()
void
transferAfterTailFrom(IntrusiveDoublyLinkedQueue<VALUE_TYPE> other)
Move all nodes fromother
to the back of this queue in O(1) time.void
transferBeforeHeadFrom(IntrusiveDoublyLinkedQueue<VALUE_TYPE> other)
Move all nodes fromother
to the front of this queue in O(1) time.Methods inherited from class com.illumon.util.datastructures.linked.IntrusiveDoublyLinkedStructureBase
compatible, getNext, getPrev, isLinked, linkAfter, linkBefore, setNext, setPrev, unlink
-
Constructor Details
-
IntrusiveDoublyLinkedQueue
public IntrusiveDoublyLinkedQueue(@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
Move all nodes fromother
to the front of this queue in O(1) time.- Parameters:
other
- The queue to transfer from
-
transferAfterTailFrom
Move all nodes fromother
to 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 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
-
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:
iterator
in interfaceIterable<VALUE_TYPE>
-
spliterator
- Specified by:
spliterator
in interfaceIterable<VALUE_TYPE>
-
stream
-