# Class IndexedMap<T>

A simple map-like data structure that uses an array for storage. This class is not memory efficient for sparse lookups, as it uses an array internally and will allocate memory for all indices up to the highest key used. It is however very fast for lookups.

#### Remarks

It is not possible to store `undefined` values in this map, as `undefined` is used to represent keys that have not been set. This class is only intended to be used where the key is mostly a sequential number.

#### Type Parameters

- T

##### Index

### Constructors

constructor

### Accessors

capacity

### Methods

clear
get
has
set

## Constructors

### constructor

- new IndexedMap<T>(initialCapacity?: number): IndexedMap<T>

  Constructs a new IndexedMap.

  #### Type Parameters

  - T

  #### Parameters

  - initialCapacity: number = 0

    The initial capacity of the map. Defaults to `0`.

  #### Returns IndexedMap<T>

## Accessors

### capacity

- get capacity(): number

  Gets the current capacity of the map. This is not the number of items stored in the map, but rather the size of the internal array.

  #### Returns number

  The current capacity of the map.

## Methods

### clear

- clear(): void

  Clears all items from the map. This is a heavy operation as it has to zero out the memory used by.

  #### Returns void

### get

- get(key: number): undefined | T

  Gets the value for the given key.

  #### Parameters

  - key: number

    The key to get the value for.

  #### Returns undefined | T

  The value for the key, or `undefined` if the key does not exist.

### has

- has(key: number): boolean

  Checks if the map contains the given key.

  #### Parameters

  - key: number

    The key to check for.

  #### Returns boolean

  `true` if the key exists in the map, otherwise `false`.

### set

- set(key: number, value: T): T

  Sets the value for the given key.

  #### Parameters

  - key: number

    The key to set the value for.

  - value: T

    The value to set.

  #### Returns T

  The value that was set.