How to use @esfx/collections-hashmap - 7 common examples

To help you get started, we’ve selected a few @esfx/collections-hashmap 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 / 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 / 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 / toMapAsync.ts View on Github external
export async function toMapAsync(source: AsyncQueryable, keySelector: (element: T) => K, elementSelector: ((element: T) => T | PromiseLike) | Equaler = identity, keyEqualer?: Equaler): Promise | HashMap> {
    if (IsEqualer(elementSelector)) {
        keyEqualer = elementSelector;
        elementSelector = identity;
    }
    assert.mustBeAsyncQueryable(source, "source");
    assert.mustBeFunction(keySelector, "keySelector");
    assert.mustBeFunction(elementSelector, "elementSelector");
    assert.mustBeEqualerOrUndefined(keyEqualer, "keyEqualer");
    const map = keyEqualer ? new HashMap(keyEqualer) : new Map();
    for await (const item of ToPossiblyAsyncIterable(source)) {
        const key = keySelector(item);
        const element = await elementSelector(item);
        map.set(key, element);
    }
    return map;
}
github rbuckton / iterable-query / src / lib / internal / utils.ts View on Github external
/** @internal */ export async function CreateGroupingsAsync(source: AsyncQueryable, keySelector: (element: T) => K, elementSelector: (element: T) => V | PromiseLike, keyEqualer?: Equaler): Promise | HashMap> {
    const map = keyEqualer ? new HashMap(keyEqualer) : new Map();
    for await (const item of ToPossiblyAsyncIterable(source)) {
        let key = keySelector(item);
        let element = await elementSelector(item);
        let grouping = map.get(key);
        if (grouping == null) {
            grouping = [];
            map.set(key, grouping);
        }
        grouping.push(element);
    }
    return map;
}
github rbuckton / iterable-query / src / lib / fn / toMap.ts View on Github external
export function toMap(source: Queryable, keySelector: (element: T) => K, elementSelector: ((element: T) => T) | Equaler = identity, keyEqualer?: Equaler): Map | HashMap {
    if (IsEqualer(elementSelector)) {
        keyEqualer = elementSelector;
        elementSelector = identity;
    }
    assert.mustBeQueryable(source, "source");
    assert.mustBeFunction(keySelector, "keySelector");
    assert.mustBeFunction(elementSelector, "elementSelector");
    assert.mustBeEqualerOrUndefined(keyEqualer, "keyEqualer");
    const map = keyEqualer ? new HashMap(keyEqualer) : new Map();
    for (const item of ToIterable(source)) {
        const key = keySelector(item);
        const element = elementSelector(item);
        map.set(key, element);
    }
    return map;
}
github rbuckton / iterable-query / src / lib / lookup.ts View on Github external
constructor(entries: Queryable<[K, Queryable]>, keyEqualer?: Equaler) {
        assert.mustBeQueryable(entries, "entries");
        assert.mustBeEqualerOrUndefined(keyEqualer, "keyEqualer");
        this._entries = keyEqualer ? new HashMap(ToIterable(entries), keyEqualer) : new Map(ToIterable(entries));
        this._source = new LookupIterable(this._entries, CreateGrouping);
    }
github rbuckton / iterable-query / src / lib / internal / utils.ts View on Github external
export function CreateGroupings(source: Queryable, keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer?: Equaler): Map | HashMap {
    const map = keyEqualer ? new HashMap(keyEqualer) : new Map();
    for (const item of ToIterable(source)) {
        let key = keySelector(item);
        let element = elementSelector(item);
        let grouping = map.get(key);
        if (grouping == null) {
            grouping = [];
            map.set(key, grouping);
        }
        grouping.push(element);
    }
    return map;
}

@esfx/collections-hashmap

Provides 'HashMap', 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-hashmap functions

Similar packages