Class: Set

bu. Set

Creates a new set given an equality predicate and hash function.


new Set(equals, hash, nbuckets)

Parameters:
Name Type Description
equals function

the equality predicate.

hash function

the hash function.

nbuckets number

the number of buckets.

Source:
bu/collections/set.js

Methods


add(item)

Adds an item, replacing an existing item. Returns the replaced item, or null if no item was replaced.

Parameters:
Name Type Description
item Object

the item to add.

Source:
bu/collections/set.js
Returns:

The replaced item.

Type
Object

clear()

Removes all items.

Source:
bu/collections/set.js

each(fn)

Calls fn(item) for each item in the set, in an undefined order. Returns the number of times fn was called. The result is undefined if the set is mutated during iteration.

Parameters:
Name Type Description
fn function

the function to call.

Source:
bu/collections/set.js
Returns:

Number of times fn was called.

Type
number

has(item)

Returns whether an item is in the set.

Parameters:
Name Type Description
item Object

the item to search.

Source:
bu/collections/set.js
Returns:

True if item exists.

Type
boolean

hashmod(x)

Returns the modulus of the hash and the number of buckets.

Parameters:
Name Type Description
x number

the value to hash.

Source:
bu/collections/set.js
Returns:

The modulus.

Type
number

remove(item)

Removes an item. Returns the removed item, or null if the item was not found.

Parameters:
Name Type Description
item Object

the item to remove.

Source:
bu/collections/set.js
Returns:

The item removed.

Type
Object

size()

Returns the number of items in the set.

Source:
bu/collections/set.js
Returns:

Number of items.

Type
number