ArrayList Data Structure
npm install @structures/array-listClass 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])](#new_ArrayList_new)
* .add(...elements) ⇒ ArrayList
* .addAll(iterable) ⇒ ArrayList
* .clear() ⇒ ArrayList
* [.contains(element, [comparator])](#ArrayList+contains) ⇒ boolean
.get(index) ⇒ \
* [.indexOf(element, [comparator])](#ArrayList+indexOf) ⇒ number
* .insert(index, element) ⇒ ArrayList
* .isEmpty() ⇒ boolean
.remove(index) ⇒ \
.set(index, elemnet) ⇒ \
* .size() ⇒ number
* .toString() ⇒ string
* .iterator() ⇒ iterator
| 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. |
Kind: instance method of ArrayList
Returns: ArrayList - - This
| Param | Type | Description |
| --- | --- | --- |
| ...elements | \* | Elements to be added. |
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. |
Kind: instance method of ArrayList
Returns: ArrayList - - This
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. |
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. |
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. |
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. |
Kind: instance method of ArrayList
Returns: boolean - - Whether or not this list is empty
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. |
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. |
Kind: instance method of ArrayList
Returns: number - - The current list size.
Kind: instance method of ArrayList
Returns: string - - The string representation of this list.
Kind: instance method of ArrayList
Returns: iterator - - An iterator for the list. Not access safe.
8 - Doubles array capacity once limit is reached