Object buckets.LinkedList

A linked list is a sequence of items arranged one after another. The size is not fixed and it can grow or shrink on demand. One of the main benefits of a linked list is that you can add or remove elements at both ends in constant time. One disadvantage of a linked list against an array is that it doesn’t provide constant time random access.

Object Summary
Constructor Name and Description
Creates an empty Linked List.
Method Summary
Method Name and Description
buckets.LinkedList.add(item, index)
Adds an element to the list.
buckets.LinkedList.clear()
Removes all the elements from the list.
buckets.LinkedList.contains(item, equalsFunction)
Returns true if the list contains the specified element.
buckets.LinkedList.elementAtIndex(index)
Returns the element at the specified position in the list.
buckets.LinkedList.equals(other, equalsFunction)
Returns true if the list is equal to another list.
buckets.LinkedList.first()
Returns the first element in the list.
buckets.LinkedList.forEach(callback)
Executes the provided function once per element present in the list in order.
buckets.LinkedList.indexOf(item, equalsFunction)
Returns the index of the first occurrence of the specified element, or -1 if the list does not contain the element.
buckets.LinkedList.isEmpty()
Returns true if the list contains no elements.
buckets.LinkedList.last()
Returns the last element in the list.
buckets.LinkedList.remove(item, equalsFunction)
Removes the first occurrence of the specified element in the list.
buckets.LinkedList.removeElementAtIndex(index)
Removes the element at the specified position in the list.
buckets.LinkedList.reverse()
Reverses the order of the elements in the linked list (makes the last element first, and the first element last).
buckets.LinkedList.size()
Returns the number of elements in the list.
buckets.LinkedList.toArray()
Returns an array containing all the elements in the list in proper sequence.
Object Detail
buckets.LinkedList()
Creates an empty Linked List.
Method Detail
<static> {boolean} buckets.LinkedList.add(item, index)
Adds an element to the list.
Parameters:
{Object} item
Element to be added.
{number=} index
Optional index to add the element. If no index is specified the element is added to the end of the list.
Returns:
{boolean} True if the element was added or false if the index is invalid or if the element is undefined.

<static> buckets.LinkedList.clear()
Removes all the elements from the list.

<static> {boolean} buckets.LinkedList.contains(item, equalsFunction)
Returns true if the list contains the specified element.

If the elements inside the list are not comparable with the === operator, a custom equals function should be provided to perform searches, that function must receive two arguments and return true if they are equal, false otherwise. Example:

var petsAreEqualByName = function(pet1, pet2) {
 return pet1.name === pet2.name;
}
Parameters:
{Object} item
Element to search for.
{function(Object|Object):boolean=} equalsFunction
Optional function used to check if two elements are equal.
Returns:
{boolean} True if the list contains the specified element, false otherwise.

<static> {*} buckets.LinkedList.elementAtIndex(index)
Returns the element at the specified position in the list.
Parameters:
{number} index
Desired index.
Returns:
{*} The element at the given index or undefined if the index is out of bounds.

<static> {boolean} buckets.LinkedList.equals(other, equalsFunction)
Returns true if the list is equal to another list. Two lists are equal if they have the same elements in the same order.
Parameters:
{buckets.LinkedList} other
The other list.
{function(Object|Object):boolean=} equalsFunction
Optional function to check if two elements are equal. If the elements in the lists are custom objects you should provide a custom equals function, otherwise the === operator is used to check equality between elements.
Returns:
{boolean} true if the list is equal to the given list.

<static> {*} buckets.LinkedList.first()
Returns the first element in the list.
Returns:
{*} The first element in the list or undefined if the list is empty.

<static> buckets.LinkedList.forEach(callback)
Executes the provided function once per element present in the list in order.
Parameters:
{function(Object):*} callback
Function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false inside the callback.

<static> {number} buckets.LinkedList.indexOf(item, equalsFunction)
Returns the index of the first occurrence of the specified element, or -1 if the list does not contain the element.

If the elements inside the list are not comparable with the === operator, a custom equals function should be provided to perform searches, that function must receive two arguments and return true if they are equal, false otherwise. Example:

var petsAreEqualByName = function(pet1, pet2) {
 return pet1.name === pet2.name;
}
Parameters:
{Object} item
Element to search for.
{function(Object|Object):boolean=} equalsFunction
Optional function used to check if two elements are equal.
Returns:
{number} The index in the list of the first occurrence of the specified element, or -1 if the list does not contain the element.

<static> {boolean} buckets.LinkedList.isEmpty()
Returns true if the list contains no elements.
Returns:
{boolean} true if the list contains no elements.

<static> {*} buckets.LinkedList.last()
Returns the last element in the list.
Returns:
{*} The last element in the list or undefined if the list is empty.

<static> {boolean} buckets.LinkedList.remove(item, equalsFunction)
Removes the first occurrence of the specified element in the list.

If the elements inside the list are not comparable with the === operator, a custom equals function should be provided to perform searches, that function must receive two arguments and return true if they are equal, false otherwise. Example:

var petsAreEqualByName = function(pet1, pet2) {
 return pet1.name === pet2.name;
}
Parameters:
{Object} item
Element to be removed from the list, if present.
equalsFunction
Returns:
{boolean} True if the list contained the specified element.

<static> {*} buckets.LinkedList.removeElementAtIndex(index)
Removes the element at the specified position in the list.
Parameters:
{number} index
Given index.
Returns:
{*} Removed element or undefined if the index is out of bounds.

<static> buckets.LinkedList.reverse()
Reverses the order of the elements in the linked list (makes the last element first, and the first element last).

<static> {number} buckets.LinkedList.size()
Returns the number of elements in the list.
Returns:
{number} The number of elements in the list.

<static> {Array.<*>} buckets.LinkedList.toArray()
Returns an array containing all the elements in the list in proper sequence.
Returns:
{Array.<*>} An array containing all the elements in the list, in proper sequence.