How to use @esfx/collections-hashset - 10 common examples

To help you get started, we’ve selected a few @esfx/collections-hashset examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rbuckton / iterable-query / src / lib / fn / unionBy.ts View on Github external
*[Symbol.iterator](): Iterator {
        const keySelector = this._keySelector;
        const set = this._keyEqualer ? new HashSet() : new Set();
        for (const element of this._left) {
            if (TryAdd(set, keySelector(element))) {
                yield element;
            }
        }
        for (const element of this._right) {
            if (TryAdd(set, keySelector(element))) {
                yield element;
            }
        }
    }
}
github rbuckton / iterable-query / src / lib / fn / symmetricDifferenceBy.ts View on Github external
*[Symbol.iterator](): Iterator {
        const keySelector = this._keySelector;
        const rightKeys = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        const right = this._keyEqualer ? new HashMap(this._keyEqualer) : new Map();
        for (const element of this._right) {
            const key = keySelector(element);
            if (TryAdd(rightKeys, key)) {
                right.set(key, element);
            }
        }
        const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        for (const element of this._left) {
            const key = keySelector(element);
            if (TryAdd(set, key) && !right.has(key)) {
                yield element;
            }
        }
        for (const [key, element] of right) {
            if (TryAdd(set, key)) {
github rbuckton / iterable-query / src / lib / fn / symmetricDifferenceBy.ts View on Github external
*[Symbol.iterator](): Iterator {
        const keySelector = this._keySelector;
        const rightKeys = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        const right = this._keyEqualer ? new HashMap(this._keyEqualer) : new Map();
        for (const element of this._right) {
            const key = keySelector(element);
            if (TryAdd(rightKeys, key)) {
                right.set(key, element);
            }
        }
        const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        for (const element of this._left) {
            const key = keySelector(element);
            if (TryAdd(set, key) && !right.has(key)) {
                yield element;
            }
        }
        for (const [key, element] of right) {
            if (TryAdd(set, key)) {
                yield element;
            }
        }
    }
}
github rbuckton / iterable-query / src / lib / fn / toSet.ts View on Github external
export function toSet(source: Queryable, elementSelector: ((element: T) => T) | Equaler = identity, equaler?: Equaler): Set | HashSet {
    if (IsEqualer(elementSelector)) {
        equaler = elementSelector;
        elementSelector = identity;
    }
    assert.mustBeQueryable(source, "source");
    assert.mustBeFunction(elementSelector, "elementSelector");
    assert.mustBeEqualerOrUndefined(equaler, "equaler");
    const set = equaler ? new HashSet(equaler) : new Set();
    for (const item of ToIterable(source)) {
        const element = elementSelector(item);
        set.add(element);
    }
    return set;
}
github rbuckton / iterable-query / src / lib / fn / distinctByAsync.ts View on Github external
async *[Symbol.asyncIterator](): AsyncIterator {
        const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        const selector = this._keySelector;
        for await (const element of this._source) {
            const key = selector(element);
            if (!set.has(key)) {
                set.add(key);
                yield element;
            }
        }
    }
}
github rbuckton / iterable-query / src / lib / fn / distinctBy.ts View on Github external
*[Symbol.iterator](): Iterator {
        const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        const keySelector = this._keySelector;
        for (const element of this._source) {
            const key = keySelector(element);
            if (!set.has(key)) {
                set.add(key);
                yield element;
            }
        }
    }
}
github rbuckton / iterable-query / src / lib / fn / toSetAsync.ts View on Github external
export async function toSetAsync(source: AsyncQueryable, elementSelector: ((element: T) => T | PromiseLike) | Equaler = identity, equaler?: Equaler): Promise | HashSet> {
    if (IsEqualer(elementSelector)) {
        equaler = elementSelector;
        elementSelector = identity;
    }
    assert.mustBeAsyncQueryable(source, "source");
    assert.mustBeFunction(elementSelector, "elementSelector");
    assert.mustBeEqualerOrUndefined(equaler, "equaler");
    const set = equaler ? new HashSet(equaler) : new Set();
    for await (const item of ToPossiblyAsyncIterable(source)) {
        const element = await elementSelector(item);
        set.add(element);
    }
    return set;
}
github rbuckton / iterable-query / src / lib / fn / symmetricDifferenceByAsync.ts View on Github external
async *[Symbol.asyncIterator](): AsyncIterator {
        const keySelector = this._keySelector;
        const rightKeys = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        const right = this._keyEqualer ? new HashMap(this._keyEqualer) : new Map();
        for await (const element of this._right) {
            const key = keySelector(element);
            if (TryAdd(rightKeys, key)) {
                right.set(key, element);
            }
        }
        const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        for await (const element of this._left) {
            const key = keySelector(element);
            if (TryAdd(set, key) && !right.has(key)) {
                yield element;
            }
        }
        for (const [key, element] of right) {
            if (TryAdd(set, key)) {
github rbuckton / iterable-query / src / lib / fn / symmetricDifferenceByAsync.ts View on Github external
async *[Symbol.asyncIterator](): AsyncIterator {
        const keySelector = this._keySelector;
        const rightKeys = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        const right = this._keyEqualer ? new HashMap(this._keyEqualer) : new Map();
        for await (const element of this._right) {
            const key = keySelector(element);
            if (TryAdd(rightKeys, key)) {
                right.set(key, element);
            }
        }
        const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        for await (const element of this._left) {
            const key = keySelector(element);
            if (TryAdd(set, key) && !right.has(key)) {
                yield element;
            }
        }
        for (const [key, element] of right) {
            if (TryAdd(set, key)) {
                yield element;
            }
        }
    }
}
github rbuckton / iterable-query / src / lib / fn / unionByAsync.ts View on Github external
async *[Symbol.asyncIterator](): AsyncIterator {
        const keySelector = this._keySelector;
        const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
        for await (const element of this._left) {
            if (TryAdd(set, keySelector(element))) {
                yield element;
            }
        }
        for await (const element of this._right) {
            if (TryAdd(set, keySelector(element))) {
                yield element;
            }
        }
    }
}

@esfx/collections-hashset

Provides 'HashSet', a collection class that utilizes '@esfx/collection-core' and '@esfx/equatable'.

Apache-2.0
Latest version published 2 years ago

Package Health Score

42 / 100
Full package analysis

Popular @esfx/collections-hashset functions

Similar packages