HashList

Data Structures View source
HashList
public class HashList<T>

HashLists are used if you require quick contains operations on a large list object. LinkedLists should be generally used, but are slow in this regard. Removing elements from a HashList is slower than of LinkedLists.

Constructors

construct()
construct(thistype base)

Create a new list by copying all elements from another list into it

Methods

count(T elem) returns int

Returns the number of occurences of an element in this list

add(vararg T elems)

Add an element to the end of the list

set(int index, T elem)

Set an element at the given index. If the index is higher than the list’s size, the list will be resized with null elements added between the index and the previous size. Errors if the index is negative.

addAll(HashList<T> elems)

Add all elements from elems to this list. Adding a list to itself duplicates its current contents.

clear()

Remove all elements from this list without destroying it

removeAt(int index) returns T

Removes and returns the element at the given index. Errors if the index is outside [0, size).

remove(T t) returns boolean

Removes the first occurence of t from this list. Returns true if an element was removed from the list.

size() returns int

Get the size of the list

isEmpty() returns bool

Return whether the list is empty

get(int index) returns T

Get the element at the given index from this list. Indices outside [0, size) are not validated and yield the null/zero value.

has(T elem) returns bool

Return whether the element exists in the list

hasAt(int index) returns bool

Return whether the given index is valid, i.e. inside [0, size)

iterator() returns HLIterator<T>

Get an iterator for this list

copy() returns HashList<T>

Returns a shallow copy of this list

forEach(HLItrClosure<T> itr) returns HashList<T>

Executes the closure for each element

staticItr() returns HLIterator<T>

get the static iterator for this list

removeIf(RemovePredicate<T> predicate)

Removes the element if the predicates returns true. Single pass compaction - removing through the iterator instead would shift the tail once per removal, making this O(n^2).

getRandomElement() returns T