hxSet

simple set class
https://github.com/ianxm/hxSet

To install, run:

haxelib install hxSet 2.1.0 

See using Haxelib in Haxelib documentation for more information.

README.md

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(?items :Iterable)

    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) :Int

    add the items from the given iterable to the set
    returns the number of items added

intersection(otherItems :Iterable) :Int

    remove items which are not in the given iterable
    returns the number of items removed

minus(otherItems :Iterable) :Int

    remove items what are in given iterable
    return the number of items removed

equals(otherSet :Set) :Bool

    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(?getKey :V->K, ?items :Iterable)

    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) :Int

    add the items from the given iterable to the set
    returns the number of items added

intersection(otherItems :Iterable) :Int

    remove items which are not in the given iterable
    returns the number of items removed

minus(?otherKeys :Iterable, ?otherItems :Iterable) :Int

    remove items with given keys in otherKeys, or items in otherItems
    return the number of items removed

equals(otherSet :Set) :Bool

    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.
Contributors
ianxm
Version
2.1.0
Published
3 months ago
License
BSD

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub