Class HashSet

A hashmap Set of items.

A Set implmentation that stores items as keys using a table as a hashmap. This provides good addition, removal, and lookup characteristics.

Addition, deletion, and lookup of any element are all Θ(1) amortized.

HashSet implements all optional Set and Collection methods.

Implements: Set, Collection, Enumerable

Functions

HashSet.fromTable(table) Creates a new HashSet from a set-formatted table.
HashSet.new(collection) Creates a new HashSet.

Methods

HashSet:Add(item) Adds an item to the HashSet.
HashSet:AddAll(items) Adds all provided items to the HashSet.
HashSet:Clear() Removes everything from the HashSet.
HashSet:Contains(item) Determines whether the HashSet contains an item.
HashSet:ContainsAll(items) Determines whether the HashSet contains all of the items.
HashSet:ContainsAny(items) Determines whether the HashSet contains any of the provided items.
HashSet:Count() Gets the number of items in the HashSet.
HashSet:Empty() Determines whether the HashSet has no elements.
HashSet:Enumerator() Creates an enumerator for the HashSet.
HashSet:Except(items) Transforms the HashSet to remove all elements from a Collection.
HashSet:Intersect(items) Transforms the HashSet to keep only elements from a Collection.
HashSet:Overlaps(items) Determines whether the HashSet elements overlaps a Collection.
HashSet:ProperSubsetOf(items) Determines whether the HashSet is a strict subset of a Collection.
HashSet:ProperSupersetOf(items) Determines whether the HashSet is a strict superset of a Collection.
HashSet:Remove(item) Removes the specified item from the HashSet.
HashSet:RemoveAll(items) Removes all provided items from the HashSet.
HashSet:RetainAll(items) Removes all items except those provided from the HashSet.
HashSet:SetEquals(items) Determines whether the HashSet contains the same elements as a Collection.
HashSet:SubsetOf(items) Determines whether the HashSet is a subset of a Collection.
HashSet:SupersetOf(items) Determines whether the HashSet is a superset of a Collection.
HashSet:SymmetricExcept(items) Transforms the HashSet to keep only elements in it or a Collection, not both.
HashSet:ToArray() Creates a new array indexed table of this HashSet.
HashSet:ToTable() Creates a new table of this HashSet.
HashSet:Union(items) Transforms the HashSet to include all elements from a Collection.


Functions

Methods
HashSet.fromTable(table)
Creates a new HashSet from a set-formatted table. This constructor creates a new HashSet copy of the table using only its keys. A typical set-formatted table consists of keys that have the value true, although any non-nil value will result in a valid HashSet. The values associated with the keys in the table will not be preserved in the HashSet.

Parameters:

  • table

Returns:

    the new HashSet
HashSet.new(collection)
Creates a new HashSet. Creates a HashSet copy of the provided Collection or array-indexed table if one is provided, otherwise creates an empty HashSet.

Parameters:

Returns:

    the new HashSet

Methods

HashSet:Add(item)
Adds an item to the HashSet.

This method is optional. All HashSet implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this HashSet.

Inherited from:

Parameters:

  • item the item to add

Returns:

    true if the HashSet changed as a result, false otherwise
HashSet:AddAll(items)
Adds all provided items to the HashSet.

This method is optional. All HashSet implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this HashSet.

Inherited from:

Parameters:

  • items the Collection of items to add to this HashSet

Returns:

    true if the HashSet changed as a result, false otherwise
HashSet:Clear()
Removes everything from the HashSet.

This method is optional. All HashSet implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this HashSet.

Inherited from:

HashSet:Contains(item)
Determines whether the HashSet contains an item.

Inherited from:

Parameters:

  • item the item to locate in the HashSet

Returns:

    true if the item is in the HashSet, false otherwise
HashSet:ContainsAll(items)
Determines whether the HashSet contains all of the items. Checks for items provided in another Collection in an arbitrary, deterministic order. The order is the same as the order of enumeration.

Inherited from:

Parameters:

  • items the Collection of items to locate in this HashSet

Returns:

    true if all items are in the HashSet, false otherwise
HashSet:ContainsAny(items)
Determines whether the HashSet contains any of the provided items. Checks for items provided in another Collection in an arbitrary, deterministic order. The order is the same as the order of enumeration.

Inherited from:

Parameters:

  • items the Collection of items to locate in this HashSet

Returns:

    true if any items are in the HashSet, false otherwise
HashSet:Count()
Gets the number of items in the HashSet.

Inherited from:

Returns:

    the number of items
HashSet:Empty()
Determines whether the HashSet has no elements.

Inherited from:

Returns:

    true if the HashSet empty, false otherwise
HashSet:Enumerator()
Creates an enumerator for the HashSet. The enumerator can be used directly in a generic for loop similar to pairs or ipairs.

Inherited from:

Returns:

  1. the enumerator generator
  2. the invariant state
  3. the control variable state
HashSet:Except(items)
Transforms the HashSet to remove all elements from a Collection.

In HashSet this is identical to RemoveAll.

Inherited from:

Parameters:

HashSet:Intersect(items)
Transforms the HashSet to keep only elements from a Collection.

In HashSet this is identical to RetainAll.

Inherited from:

Parameters:

HashSet:Overlaps(items)
Determines whether the HashSet elements overlaps a Collection.

In HashSet this is identical to ContainsAny.

Inherited from:

Parameters:

  • items the Collection of items to locate in this HashSet

Returns:

    true if they overlap, false otherwise
HashSet:ProperSubsetOf(items)
Determines whether the HashSet is a strict subset of a Collection. A proper or strict subset is one where every element in this set is contained in the other, and the other contains at least one additional element.

Inherited from:

Parameters:

Returns:

    true if the HashSet is a proper subset, false otherwise
HashSet:ProperSupersetOf(items)
Determines whether the HashSet is a strict superset of a Collection. A proper or strict superset is one where every element in the other is contained in this set, and this set contains at least one additional element.

Inherited from:

Parameters:

Returns:

    true if the HashSet is a proper superset, false otherwise
HashSet:Remove(item)
Removes the specified item from the HashSet.

This method is optional. All HashSet implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this HashSet.

Inherited from:

Parameters:

  • item the item to remove from the HashSet

Returns:

    true if the HashSet changed as a result, false otherwise
HashSet:RemoveAll(items)
Removes all provided items from the HashSet. Removes each instance of a provided item.

This method is optional. All HashSet implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this HashSet.

Inherited from:

Parameters:

  • items the Collection of items to remove from this HashSet

Returns:

    true if the HashSet changed as a result, false otherwise
HashSet:RetainAll(items)
Removes all items except those provided from the HashSet. Retains only the items contained in the specified Collection. If there are duplicates they are all kept.

This method is optional. All HashSet implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this HashSet.

Inherited from:

Parameters:

  • items the Collection of items to retain in this HashSet

Returns:

    true if the HashSet changed as a result, false otherwise
HashSet:SetEquals(items)
Determines whether the HashSet contains the same elements as a Collection. Determines only that the same exact Sets of elements are contained and does not care for duplicates or any other associated data.

Inherited from:

Parameters:

Returns:

    true if the Sets are equal, false otherwise
HashSet:SubsetOf(items)
Determines whether the HashSet is a subset of a Collection. A subset is one where every element in this HashSet is contained in the other.

Inherited from:

Parameters:

Returns:

    true if the HashSet is a superset, false otherwise
HashSet:SupersetOf(items)
Determines whether the HashSet is a superset of a Collection. A superset is one where every element in the other is contained in this set.

In HashSet this is identical to ContainsAll.

Inherited from:

Parameters:

Returns:

    true if the HashSet is a superset, false otherwise
HashSet:SymmetricExcept(items)
Transforms the HashSet to keep only elements in it or a Collection, not both.

Inherited from:

Parameters:

  • items the Collection of items to symmetric except
HashSet:ToArray()
Creates a new array indexed table of this HashSet.

Inherited from:

Returns:

    the array indexed table

See also:

HashSet:ToTable()
Creates a new table of this HashSet. The indices of the table are the elements of the set. The only values in the table are true if the element exists, or nil if it does not.

Inherited from:

Returns:

    the table
HashSet:Union(items)
Transforms the HashSet to include all elements from a Collection.

In HashSet this is identical to AddAll.

Inherited from:

Parameters:

generated by LDoc 1.4.6 Last updated 2022-03-30 00:04:00