0.1.3 • Published 6 years ago

@structures/array-list v0.1.3

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

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

new ArrayList(initialCapacity, resizeStrategy)

Creates a new ArrayList

ParamTypeDefaultDescription
initialCapacitynumberDEFAULT_INITIAL_CAPACITYInitial array capacity before resize required.
resizeStrategyfunctionDEFAULT_RESIZE_STRATEGYFunction 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

ParamTypeDescription
...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.
ParamTypeDescription
iterableArrayIterable 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.

ParamTypeDescription
element*The element to check existence.
comparatorfunctionThe 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.
ParamTypeDescription
indexnumberThe 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.

ParamTypeDescription
element*The element to retrieve the index of.
comparatorfunctionThe 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.
ParamTypeDescription
indexnumberThe 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.
ParamTypeDescription
indexnumberThe 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.
ParamTypeDescription
indexnumberThe 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

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago