Class: TrueSet

TrueSet(repr, classifieropt)

A TrueSet is a multiset-like collection where item equivalence is determined by a user-provided repr(item) function.

Internally, the set stores elements inside a Classifier as: classifier.add(repr(item), item)

Unlike a normal Set, equivalent items may coexist.
Both classes (repr values) and the items inside each class are sorted according to the sorting configuration of the underlying Classifier.

This class exposes:

  • A Collection interface (add, remove, has, n, clear, iteration)
  • A Queue interface (peek, poll, reverse)

The .classifier property is intentionally public so users may inspect or query the internal structure.

Constructor

new TrueSet(repr, classifieropt)

Parameters:
Name Type Attributes Default Description
repr function

A function producing the class key for each item.

classifier Classifier <optional>
new Classifier()

The internal classifier.

Source:

Classes

TrueSet

Methods

add(item, xTimesopt) → {this}

Adds the item xTimes times.

Parameters:
Name Type Attributes Default Description
item *
xTimes number <optional>
1
Source:
Returns:
Type
this

clear()

Remove all items

Source:

get()

Iterates all the equivalent items

Source:

has(item) → {boolean}

Parameters:
Name Type Description
item *
Source:
Returns:

whether an equivalent item exists

Type
boolean

n()

Total number of stored items

Source:

peek(firstopt) → {*}

Returns (without removing) the first or last stored item.

Parameters:
Name Type Attributes Default Description
first boolean <optional>
true
Source:
Returns:

the peeked item or undefined

Type
*

remove(item, xTimesopt) → {boolean}

Removes up to xTimes occurrences of the item.

Parameters:
Name Type Attributes Default Description
item *
xTimes number <optional>
Infinity
Source:
Returns:

true if removal occurred

Type
boolean

reverse() → {Iterator.<*>}

Returns an iterator of all items in reverse order.

Source:
Returns:
Type
Iterator.<*>