Package org.ddogleg.struct
Class DogLinkedList<T>
java.lang.Object
org.ddogleg.struct.DogLinkedList<T>
A double linked list. Internal data structures are recycled to minimize creation of new memory.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected final ArrayDeque<DogLinkedList.Element<T>>
protected @Nullable DogLinkedList.Element<T>
protected @Nullable DogLinkedList.Element<T>
protected int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add all elements in list into this linked listvoid
Adds the specified elements from array into this list@Nullable DogLinkedList.Element<T>
Returns the first element which contains 'object' starting from the head.getElement
(int index, boolean fromFront) Returns the N'th element when counting from the from or from the backgetFirst()
Returns the value in the head@Nullable DogLinkedList.Element<T>
getHead()
Returns the first element in the listgetLast()
Returns the value in the trail@Nullable DogLinkedList.Element<T>
getTail()
Returns the last element in the listinsertAfter
(DogLinkedList.Element<T> previous, T object) Inserts the object into a new element after the provided element.insertBefore
(DogLinkedList.Element<T> next, T object) Inserts the object into a new element before the provided element.boolean
isEmpty()
Checks to see if there are no elements in the listAdds the element to the front of the list.Adds the element to the back of the list.void
remove
(DogLinkedList.Element<T> element) Removes the element from the list and saves the element data structure for later reuse.Removes the first element from the listRemoves the last element from the listprotected DogLinkedList.Element<T>
Returns a new element.void
reset()
Puts the linked list back into its initial state.int
size()
Returns the number of elements in the listvoid
swap
(DogLinkedList.Element<T> a, DogLinkedList.Element<T> b) Swaps the location of the two elements
-
Field Details
-
first
-
last
-
size
protected int size -
available
-
-
Constructor Details
-
DogLinkedList
public DogLinkedList()
-
-
Method Details
-
reset
public void reset()Puts the linked list back into its initial state. Elements are saved for later use. -
isEmpty
public boolean isEmpty()Checks to see if there are no elements in the list- Returns:
- true if empty or false if not
-
getElement
Returns the N'th element when counting from the from or from the back- Parameters:
index
- Number of elements away from the first or last element. Must be positive.- Returns:
- if true then the number of elements will be from first otherwise last
-
pushHead
Adds the element to the front of the list.- Parameters:
object
- Object being added.- Returns:
- The element it was placed inside of
-
pushTail
Adds the element to the back of the list.- Parameters:
object
- Object being added.- Returns:
- The element it was placed inside of
-
insertAfter
Inserts the object into a new element after the provided element.- Parameters:
previous
- Element which will be before the new oneobject
- The object which goes into the new element- Returns:
- The new element
-
insertBefore
Inserts the object into a new element before the provided element.- Parameters:
next
- Element which will be after the new oneobject
- The object which goes into the new element- Returns:
- The new element
-
swap
Swaps the location of the two elements- Parameters:
a
- Elementb
- Element
-
remove
Removes the element from the list and saves the element data structure for later reuse.- Parameters:
element
- The item which is to be removed from the list
-
removeHead
Removes the first element from the list- Returns:
- The object which was contained in the first element
-
removeTail
Removes the last element from the list- Returns:
- The object which was contained in the last element
-
find
Returns the first element which contains 'object' starting from the head.- Parameters:
object
- Object which is being searched for- Returns:
- First element which contains object or null if none can be found
-
getHead
Returns the first element in the list- Returns:
- first element
-
getTail
Returns the last element in the list- Returns:
- last element
-
getFirst
Returns the value in the head -
getLast
Returns the value in the trail -
addAll
Add all elements in list into this linked list- Parameters:
list
- List
-
addAll
Adds the specified elements from array into this list- Parameters:
array
- The arrayfirst
- First element to be addedlength
- The number of elements to be added
-
size
public int size()Returns the number of elements in the list -
requestNew
Returns a new element. If there are old elements available those are returned, otherwise a new one is returned.- Returns:
- Unused element.
-