Options
All
  • Public
  • Public/Protected
  • All
Menu

A hash-based dictionary that can store multiple items with the same key.

import { HashMultiDict } from "scl"

Most methods in this collection, given that a proper hashing function is set up, are in Θ(1 + n/k). If you're out of luck, this characteristic can grow to O(n).

You can add as many items with the same key and value as you want, as the items will be stored next to each other.

const d = new HashMultiDict<number, string>()
d.emplace(1, 'foo') // ok
assert.strictEqual(d.getValue(1), 'foo')
d.emplace(1, 'bar') // ok
d.emplace(1, 'foo') // ok
const values = [...d.getValues(1)]
assert.strictEqual(values.length, 3)

Type parameters

  • K

  • V

Hierarchy

  • MultiDictBase<K, V>
    • HashMultiDict

Index

Constructors

constructor

  • new HashMultiDict<K, V>(opts?: Iterable<[K, V]> | HashIndex<[K, V], K> | HashDictOptions<K, V>): HashMultiDict<K, V>
  • Construct a new hash-based dictionary.

    const d = new HashMultiDict<number, string>()
    

    Similar to JavaScript's built-in map type, the constructor accepts a list of key-value pairs that will immediately be added to the resulting dictionary.

    const d = new HashMultiDict<number, string>([
      [1, 'one'],
      [2, 'two']
    ])
    

    The dictionary can be tweaked by providing a [[HashDictOptions]]-object, which allows to configure things like the default hashing function and value equality.

    const d = new HashMultiDict<number, string>({
      hash: num => num,
      keysEqual: (a, b) => a === b,
      valuesEqual: (a, b) => a === b,
      elements: [[1, 'one'], [2, 'two']]
    })
    

    Type parameters

    • K

    • V

    Parameters

    • opts: Iterable<[K, V]> | HashIndex<[K, V], K> | HashDictOptions<K, V> = ...

    Returns HashMultiDict<K, V>

Accessors

size

  • get size(): number

Methods

[Symbol.iterator]

  • [Symbol.iterator](): IterableIterator<[K, V]>

add

  • add(element: [K, V], hint?: unknown): AddResult<[K, V]>

clear

  • clear(): void

clone

delete

  • delete(element: [K, V]): boolean

deleteAll

  • deleteAll(element: [K, V]): number

deleteAt

  • deleteAt(position: Cursor<[K, V]>): void

deleteKey

  • deleteKey(key: K): number

emplace

  • emplace(key: K, value: V): [boolean, Cursor<[K, V]>]

equalKeys

  • equalKeys(key: K): Range<[K, V]>

findKey

  • findKey(key: K): null | Cursor<[K, V]>

getValues

  • getValues(key: K): IterableIterator<V>

has

  • has(element: [K, V]): boolean

hasKey

  • hasKey(key: K): boolean

toRange

  • toRange(): Range<[K, V]>

Legend

  • Property
  • Method
  • Accessor
  • Property
  • Method
  • Inherited property
  • Inherited method

Generated using TypeDoc