Skip to content

StdLib Map Set

Roger Johansson edited this page Jan 14, 2026 · 1 revision

Map, Set, WeakMap, WeakSet

Collection types for storing key-value pairs and unique values.

Implementation Status: 100% Complete

Overview

Type Methods Implemented
Map 13 13
Set 18 18
WeakMap 5 5
WeakSet 4 4
Total 40 40

Map

A collection of key-value pairs with any key type.

Static Methods

Method Status Description
Map.groupBy(items, callback) Implemented Groups by callback key (ES2024)
Map[Symbol.species] Implemented Returns constructor

Prototype Methods

Method Status Description
set(key, value) Implemented Adds/updates entry, returns Map
get(key) Implemented Returns value or undefined
has(key) Implemented Checks if key exists
delete(key) Implemented Removes entry, returns boolean
clear() Implemented Removes all entries
forEach(callback, thisArg) Implemented Iterates entries
entries() Implemented Returns [key, value] iterator
keys() Implemented Returns key iterator
values() Implemented Returns value iterator
size (getter) Implemented Returns entry count
[Symbol.iterator] Implemented Alias for entries()

Set

A collection of unique values.

Static Methods

Method Status Description
Set[Symbol.species] Implemented Returns constructor

Prototype Methods

Method Status Description
add(value) Implemented Adds value, returns Set
has(value) Implemented Checks if value exists
delete(value) Implemented Removes value, returns boolean
clear() Implemented Removes all values
forEach(callback, thisArg) Implemented Iterates values
entries() Implemented Returns [value, value] iterator
keys() Implemented Alias for values()
values() Implemented Returns value iterator
size (getter) Implemented Returns value count
[Symbol.iterator] Implemented Alias for values()

Set Methods (ES2025)

Method Status Description
union(other) Implemented Returns new Set combining both
intersection(other) Implemented Returns common elements
difference(other) Implemented Returns elements not in other
symmetricDifference(other) Implemented Returns exclusive elements
isSubsetOf(other) Implemented Checks if all elements in other
isSupersetOf(other) Implemented Checks if contains all of other
isDisjointFrom(other) Implemented Checks for no common elements

WeakMap

A Map with weakly held object keys (allows garbage collection).

Prototype Methods

Method Status Description
set(key, value) Implemented Key must be object
get(key) Implemented Returns value or undefined
has(key) Implemented Checks if key exists
delete(key) Implemented Removes entry

Limitations

  • Keys must be objects (no primitives)
  • Not iterable (no forEach, entries, etc.)
  • No size property
  • Entries auto-removed when key is garbage collected

WeakSet

A Set with weakly held object values.

Prototype Methods

Method Status Description
add(value) Implemented Value must be object
has(value) Implemented Checks if value exists
delete(value) Implemented Removes value

Limitations

  • Values must be objects (no primitives)
  • Not iterable
  • No size property
  • Values auto-removed when garbage collected

Key Differences

Feature Map/Set WeakMap/WeakSet
Key/Value Types Any Objects only
Enumerable Yes No
size property Yes No
Prevents GC Yes No
Use Case General storage Metadata on objects

Implementation Notes

SameValueZero

Map and Set use SameValueZero for key/value comparison:

  • NaN === NaN is true
  • +0 === -0 is true

Insertion Order

Map and Set maintain insertion order during iteration.

Weak Reference Implementation

WeakMap and WeakSet use .NET's ConditionalWeakTable internally.

Files

File Purpose
StdLib/MapSet/MapConstructor.cs Map constructor
StdLib/MapSet/MapPrototype.cs Map prototype
StdLib/MapSet/SetConstructor.cs Set constructor
StdLib/MapSet/SetPrototype.cs Set prototype
StdLib/MapSet/WeakMapConstructor.cs WeakMap constructor
StdLib/MapSet/WeakMapPrototype.cs WeakMap prototype
StdLib/MapSet/WeakSetConstructor.cs WeakSet constructor
StdLib/MapSet/WeakSetPrototype.cs WeakSet prototype
JsTypes/JsMap.cs Map implementation
JsTypes/JsSet.cs Set implementation
JsTypes/JsWeakMap.cs WeakMap implementation
JsTypes/JsWeakSet.cs WeakSet implementation

See Also

Clone this wiki locally