Collection Kit

HashMap

Hash-Based

A HashMap is a data structure that implements an associative array, mapping keys to values using a hash function for efficient retrieval.

Import Statement
import { HashMap } from "collection-kit";

Key Features

  • Key-Value Pairs: Stores data in key-value pairs for quick access.
  • Dynamic Size: Can grow and shrink as elements are added or removed.

Common Operations

Put
Add a key-value pair to the map.
Get
Retrieve the value associated with a given key.
Remove
Delete a key-value pair by key.
ContainsKey
Check if a key exists in the map.

Example Code

import { HashMap } from "collection-kit";

const map = new HashMap();
map.put("name", "John");
map.put("age", 30);
map.put("city", "New York");

console.log("Name:", map.get("name"));      // John
console.log("Has age:", map.containsKey("age")); // true
map.remove("city");