@structures/array-list v0.1.3
Classes
Constants
ArrayList
Class storing elements in contiguous memory. Allows precise control over resizing strategy. Note: In most cases, the built-in JS Array will outperform this structure due to internal optimizations.
Kind: global class
- ArrayList
- new ArrayList([initialCapacity], [resizeStrategy])
- .add(...elements) ⇒ ArrayList
- .addAll(iterable) ⇒ ArrayList
- .clear() ⇒ ArrayList
- .contains(element, [comparator]) ⇒ boolean
- .get(index) ⇒ *
- .indexOf(element, [comparator]) ⇒ number
- .insert(index, element) ⇒ ArrayList
- .isEmpty() ⇒ boolean
- .remove(index) ⇒ *
- .set(index, elemnet) ⇒ *
- .size() ⇒ number
- .toString() ⇒ string
- .iterator() ⇒ iterator
new ArrayList(initialCapacity, resizeStrategy)
Creates a new ArrayList
Param | Type | Default | Description |
---|---|---|---|
initialCapacity | number | DEFAULT_INITIAL_CAPACITY | Initial array capacity before resize required. |
resizeStrategy | function | DEFAULT_RESIZE_STRATEGY | Function to resize array after capacity met. |
arrayList.add(...elements) ⇒ ArrayList
Adds the passed elements to the list.
Kind: instance method of ArrayList
Returns: ArrayList - - This
Param | Type | Description |
---|---|---|
...elements | * | Elements to be added. |
arrayList.addAll(iterable) ⇒ ArrayList
Adds each element in the passed array to the list.
Kind: instance method of ArrayList
Returns: ArrayList - - This
Throws:
- Error Will throw if
iterable
does not implement iterable protocol.
Param | Type | Description |
---|---|---|
iterable | Array | Iterable containing the elements to be added. |
arrayList.clear() ⇒ ArrayList
Clears all elements from the list.
Kind: instance method of ArrayList
Returns: ArrayList - - This
arrayList.contains(element, comparator) ⇒ boolean
Checks if an element exists within the list, with the comparator if passed.
Kind: instance method of ArrayList
Returns: boolean - - Returns true if element exists, false if not.
Param | Type | Description |
---|---|---|
element | * | The element to check existence. |
comparator | function | The function used to compare two elements. |
arrayList.get(index) ⇒ *
Returns the element at the specified index.
Kind: instance method of ArrayList
Returns: * - - Returns the element at the index given.
Throws:
- Error - Will throw if |index| is out of bounds for this list.
Param | Type | Description |
---|---|---|
index | number | The index to retrieve an element from. Negatives allowed. |
arrayList.indexOf(element, comparator) ⇒ number
Returns the index of the element, or -1 if it is not in the list.
Kind: instance method of ArrayList
Returns: number - - Returns the index of the element, or else -1.
Param | Type | Description |
---|---|---|
element | * | The element to retrieve the index of. |
comparator | function | The function used to compare two elements. |
arrayList.insert(index, element) ⇒ ArrayList
Inserts the element at the specified index, shifting remaining elements down.
Kind: instance method of ArrayList
Returns: ArrayList - - This
Throws:
- Error - Will throw if |index| is out of bounds for this list.
Param | Type | Description |
---|---|---|
index | number | The index to insert the element at. Negatives allowed. |
element | * | The element to insert. |
arrayList.isEmpty() ⇒ boolean
Returns true if the list has no elements, or else false.
Kind: instance method of ArrayList
Returns: boolean - - Whether or not this list is empty
arrayList.remove(index) ⇒ *
Removes the element from the list, shifting remaining elements, and returns it.
Kind: instance method of ArrayList
Returns: * - - The element that was removed.
Throws:
- Error - Will throw if |index| is out of bounds for this list.
Param | Type | Description |
---|---|---|
index | number | The index of the element to remove. Negatives allowed. |
arrayList.set(index, elemnet) ⇒ *
Replaces the element at the specified index.
Kind: instance method of ArrayList
Returns: * - - The element that was replaced.
Throws:
- Error - Will throw if |index| is out of bounds for this list.
Param | Type | Description |
---|---|---|
index | number | The index of the element to replace. Negatives allowed. |
elemnet | * | The element to place in the list. |
arrayList.size() ⇒ number
Returns the current number of elements in the list.
Kind: instance method of ArrayList
Returns: number - - The current list size.
arrayList.toString() ⇒ string
Returns a string representation of this list.
Kind: instance method of ArrayList
Returns: string - - The string representation of this list.
arrayList.iterator() ⇒ iterator
Returns an object that implements the iterator protocol.
Kind: instance method of ArrayList
Returns: iterator - - An iterator for the list. Not access safe.
DEFAULT_INITIAL_CAPACITY
Kind: global constant
Default: 8
DEFAULT_RESIZE_STRATEGY
Kind: global constant
Default: - Doubles array capacity once limit is reached