Options
All
  • Public
  • Public/Protected
  • All
Menu

A hash-based dictionary for strings, which wraps a native JavaScript object to provide very fast lookup, insertion and deletion.

import { StringDict } from "scl"

When two items are added with the same key, the second item will override the first.

const d = new StringDict<number>()
d.add(1, 'one') // ok
d.add(1, 'two') // ok; replaced
assert.strictEqual(d.getValue(1), 'two')

All operations in the dictionary are in O(1).

deprecated

Type parameters

  • V

Hierarchy

  • StringDict

Implements

Index

Constructors

constructor

  • new StringDict<V>(iterable?: Iterable<[string, V]>): StringDict<V>
  • Construct a new string-based dictionary.

    const d = new StringDict<number>()
    

    You can also constrcut this dictionary from any iterable, like so:

    const d = new StringDict([
      ['one', 1],
      ['two', 2]
    ])
    

    Type parameters

    • V

    Parameters

    • Optional iterable: Iterable<[string, V]>

    Returns StringDict<V>

Accessors

size

  • get size(): number
  • Count the amount of elements in the collection.

    ⚠️ In most cases, this should be an O(1) operation. However, there are cases where this can be an O(n) operation. Therefore, it is recommended to always cache the result in a local variable.

    Returns number

Methods

[Symbol.iterator]

  • [Symbol.iterator](): IterableIterator<[string, V]>
  • Returns an object which is able to sift through the values in this collection.

    The order by which the elements are traversed depends on the kind of collection. For unordered collections, the iteration order is unspecified and may even differ between two iterations on the same collection.

    Returns IterableIterator<[string, V]>

add

  • add(__namedParameters: Pair<string, V>): [boolean, Cursor<[string, V]>]

clear

  • clear(): void
  • Remove all elements from this collection, effectively setting the collection to the empty collection.

    Returns void

clone

delete

  • delete(pair: Pair<string, V>): boolean

deleteAll

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

deleteAt

  • deleteAt(cursor: ObjectCursor<V>): void

deleteKey

  • deleteKey(key: string): 0 | 1

emplace

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

equalKeys

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

findKey

  • findKey(key: string): ObjectCursor<V>

getValue

  • getValue(key: string): any

has

  • has(element: Pair<string, V>): boolean

hasKey

  • hasKey(key: string): boolean

toRange

  • toRange(): ObjectRange<V>

Legend

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

Generated using TypeDoc