Unordered Array Set

loop.collection.UnorderedArraySet


Class of objects that store a sequence of values as a Lua array like class UnorderedArray. However it additionally maps values to its current position in the array allowing efficient containment checks and location of a value in the array for removal. This class is useful when it is necessary to store a set elements (no duplicates) as an array (e.g. to comply with some library API) but such elements are removed and inserted frequently or it is necessary to perform quick containment checks.

Behaves like UnorderedArray class but provides operations to check containment, get the array position, or remove any element of the collection.

Behavior

Methods

add(value)
Adds value value to the collection if it was not already inserted and returns value. If value was already in the collection then the call has no effect and returns no value.
contains(value)
Return true if a value belongs to the collection or false otherwise.
indexof(value)
Returns the index where value is stored in the array part of the collection or returns nil if value does not belong to the collection. This operation has the same effect of doing self[index].
remove(value)
If value belongs to the collection then it is removed from it and is then returned by this function. Otherwise this function has no effect and no values are returned.
removeat(index)
Removes the element at position index of the array and returns the removed element. Otherwise this function has no effect and no values are returned. If index is out of the array bounds then the call has no effect and no values are returned.
valueat(index)
Returns the value at index of the array part of the collection. This operation has the same effect of doing self[index].

Examples

$ExampleDescription

-- example missing

Copyright (C) 2004-2008 Tecgraf, PUC-RioThis project is currently being maintained by Tecgraf at PUC-Rio.