hxSet
This contains two 'set' classes. They supports basic set operations. Both are implemented with a balanced tree.
Set should be used if you want to provide a function to generate a key from the given value to be used for comparison. SimpleSet should be used when the value itself should be used in comparisons. For example, use SimpleSet if the set is made up of ints or strings. Use Set if the set is made up of 'Person' objects, and you want to use the 'Person.name' field for comparison.
SimpleSet
new
create an empty set, optionally fill it with given items
V is the type for the values the set will contain
length
property that tells the number of items in the set
add(item :V) :Bool
add an item to the set
returns true if it was added
remove(item :V) :Bool
remove the given item from the set
returns true if it was removed
has(item :V) :Bool
returns true if the given item is in the set
isEmpty()
returns true if the set is empty
union(otherItems :Iterable
add the items from the given iterable to the set
returns the number of items added
intersection(otherItems :Iterable
remove items which are not in the given iterable
returns the number of items removed
minus(otherItems :Iterable
remove items what are in given iterable
return the number of items removed
equals(otherSet :Set
check if sets are equal (made up of the same items).
return true if both sets contain the same items
clear()
empty the set
iterator()
iterate over items in the set. order will be fifo.
Set
new
create an empty set, optionally set getKey and fill it with given items
getKey must be given if items is given
K is the type that will be used to compare values
V is the value's type
getKey(value :V) :K
dynamic function that must be overridden to return a key from a value
length
property that tells the number of items in the set
add(item :V) :Bool
add an item to the set
returns true if it was added
remove(?item :V, ?key :K) :Bool
remove the given item (or item found using the given key) from the set
returns true if it was removed
has(?item :V, ?key :K) :Bool
returns true if the given item is in the set
get(key :K) :V
returns the value for the given key
isEmpty()
returns true if the set is empty
union(otherItems :Iterable
add the items from the given iterable to the set
returns the number of items added
intersection(otherItems :Iterable
remove items which are not in the given iterable
returns the number of items removed
minus(?otherKeys :Iterable
remove items with given keys in otherKeys, or items in otherItems
return the number of items removed
equals(otherSet :Set
check if sets are equal (made up of the same items).
return true if both sets contain the same items
clear()
empty the set
iterator()
iterate over items in the set. order will be fifo.