packageDocumentation module import { OrderedComparator } from "./Compare" ; import { CloneFunction , shallowClone , SortedArray } from "./SortedArray" ; public export class ReadonlyOrderedSet < T > implements Iterable < T > { protected readonly _array : SortedArray < T > ; param compare param clone public constructor ( compare , clone = shallowClone ) { this . _array = new SortedArray < T > ( compare , false , clone ) ; } /** The number of elements in the set. */ public get size ( ) : number { return this . _array . length ; } /** Returns true if `value` is present in the set. */ public has ( value ) { return - 1 !== this . _array . indexOf ( value ) ; } /** Iterate over the elements in sorted order (as opposed to `Set`'s iterator, which returns elements in insertion order). */ public [ Symbol . iterator ] ( ) { return this . _array [ Symbol . iterator ] ( ) ; } } public export class OrderedSet < T > extends ReadonlyOrderedSet < T > { param compare param clone public constructor ( compare , clone = shallowClone ) { super ( compare , clone ) ; } /** Remove all elements from the set. */ public clear ( ) { this . _array . clear ( ) ; } /** Add the specified element to the set. Returns this set. */ public add ( value ) { this . _array . insert ( value ) ; return this ; } /** Removes the specified element from the set. Returns `true` if the element was present. */ public delete ( value ) { return - 1 !== this . _array . remove ( value ) ; } }