Options
All
  • Public
  • Public/Protected
  • All
Menu

Class VectorMap<U, V>

Type parameters

  • U

  • V

Hierarchy

  • VectorMap

Index

Constructors

constructor

  • new VectorMap<U, V>(arr?: [U, V][]): VectorMap<U, V>
  • Create a new VectorMap.

    Type parameters

    • U

    • V

    Parameters

    • Optional arr: [U, V][]

      Initial data which has pairs of key and value.

    Returns VectorMap<U, V>

Properties

pointer

pointer: Map<U, number>

Pointer map.

It contains an index of the source array to access the target directly.

source

source: MapSource<U, V>[]

Data source array.

Accessors

head

size

  • get size(): number

tail

Methods

[iterator]

  • [iterator](): Generator<MapSource<U, V>, void, unknown>

clear

  • clear(): void

delete

  • delete(key: U, callback?: (swapped: MapSource<U, V>, deleted: MapSource<U, V>) => any): boolean
  • Swap item with tail and remove it from map.

    Parameters

    • key: U

      key.

    • Optional callback: (swapped: MapSource<U, V>, deleted: MapSource<U, V>) => any

      Calls callback when item swapped with tail. Arguments are reference of each item, and 'key' is the key of map that indicates array index(pointer), therefore should be careful to not modify 'key' or it could make mangling pointer.

    Returns boolean

forEach

  • forEach(callback: (data: MapSource<U, V>, index: number, arr: MapSource<U, V>[]) => any): void
  • Iterate items. Same to Array.forEach in source array.

    Parameters

    • callback: (data: MapSource<U, V>, index: number, arr: MapSource<U, V>[]) => any

      callback function to execute every iteration.

    Returns void

get

  • get(key: U): undefined | V
  • Get item from map.

    Parameters

    • key: U

      key.

    Returns undefined | V

getIndex

  • getIndex(key: U): undefined | number
  • Get index(pointer) of item.

    Parameters

    • key: U

      key.

    Returns undefined | number

has

  • has(key: U): boolean
  • Check if item exists.

    Parameters

    • key: U

      key.

    Returns boolean

map

  • Generate a new array. Same to Array.map in source array.

    Type parameters

    • T

    Parameters

    Returns T[]

    Array.

pop

reduce

  • reduce<T>(reducer: (acc: T, data: MapSource<U, V>, index: number, arr: MapSource<U, V>[]) => T, accumulator: T): T
  • Reduce map. Same to Array.reduce in source array.

    Type parameters

    • T

    Parameters

    • reducer: (acc: T, data: MapSource<U, V>, index: number, arr: MapSource<U, V>[]) => T

      reducer function to execute every iteration.

    • accumulator: T

      default value of accumulator.

    Returns T

    T

reverse

  • reverse(): void
  • Reverse order of source array.

    Returns void

set

  • set(key: U, value: V): number
  • Add item in map and return its index.

    Parameters

    • key: U

      key.

    • value: V

      value.

    Returns number

shallowClone

  • shallow clone itself. Useful when use with immutable state management (ex. React state).

    Returns VectorMap<U, V>

some

  • some(someFunc: (data: MapSource<U, V>, index: number, arr: MapSource<U, V>[]) => boolean): boolean
  • Equivalent to Array.some.

    Parameters

    • someFunc: (data: MapSource<U, V>, index: number, arr: MapSource<U, V>[]) => boolean

      function to execute every iteration. Must return boolean type.

    Returns boolean

    boolean.

swap

  • swap(key1: U, key2: U): void
  • Swap item without preserve its order. Equivalent to swapPointer + swapOrder, but more simple & efficient.

    Parameters

    • key1: U

      key 1.

    • key2: U

      key 2.

    Returns void

swapIndex

  • swapIndex(key1: U, key2?: U): void
  • Swap source order.

    Parameters

    • key1: U

      key 1.

    • Optional key2: U

      key 2.

    Returns void

swapPointer

  • swapPointer(key1: U, key2: U): void
  • Swap item with preserve its order.

    Parameters

    • key1: U

      key 1.

    • key2: U

      key 2.

    Returns void

Generated using TypeDoc