Module: collections.ordered_map
Source: ./collections/ordered_map.reef
Overview
collections/ordered_map - Insertion-Order Preserving Map
A map that maintains the order in which keys were inserted. Useful for deterministic iteration (e.g., code generation output).
Capacity: FIXED at create (default via create_* / create_cap). Does NOT auto-grow. set updates existing keys in place; new keys are silently dropped when count >= capacity (no bool/Result signal). Size for known workloads with create_*_cap, or plan growth later.
Usage: import collections.ordered_map
let om = ordered_map.create_int() ordered_map.set_int(om, "first", 1) ordered_map.set_int(om, "second", 2) ordered_map.set_int(om, "third", 3)
// Iterates in insertion order: first, second, third mut i = 0 while i < ordered_map.len_int(om) println(ordered_map.key_at_int(om, i)) i = i + 1 end while
Implementation:
- Parallel entry array (insertion order) + hash buckets for O(1) lookup
- Remove is O(n) due to array compaction
Types
IntOrderedMapEntry
Fields:
| Name | Type |
|---|---|
key |
string |
value |
int |
next |
int |
IntOrderedMap
Fields:
| Name | Type |
|---|---|
entries |
[IntOrderedMapEntry] |
buckets |
[int] |
count |
int |
capacity |
int |
bucket_count |
int |
StringOrderedMapEntry
Fields:
| Name | Type |
|---|---|
key |
string |
value |
string |
next |
int |
StringOrderedMap
Fields:
| Name | Type |
|---|---|
entries |
[StringOrderedMapEntry] |
buckets |
[int] |
count |
int |
capacity |
int |
bucket_count |
int |
PtrOrderedMapEntry
Fields:
| Name | Type |
|---|---|
key |
string |
value |
pointer |
next |
int |
PtrOrderedMap
Fields:
| Name | Type |
|---|---|
entries |
[PtrOrderedMapEntry] |
buckets |
[int] |
count |
int |
capacity |
int |
bucket_count |
int |
Functions
fn hash_string(s: string): int
fn default_capacity(): int
fn create_int(): IntOrderedMap
fn create_int_cap(capacity: int): IntOrderedMap
fn find_int_index(m: IntOrderedMap, key: string): int
fn get_int(m: IntOrderedMap, key: string): option.Option[int]
fn has_int(m: IntOrderedMap, key: string): bool
fn len_int(m: IntOrderedMap): int
fn key_at_int(m: IntOrderedMap, index: int): string
fn value_at_int(m: IntOrderedMap, index: int): int
fn create_string(): StringOrderedMap
fn create_string_cap(capacity: int): StringOrderedMap
fn find_str_index(m: StringOrderedMap, key: string): int
fn get_str(m: StringOrderedMap, key: string): option.Option[string]
fn has_str(m: StringOrderedMap, key: string): bool
fn len_str(m: StringOrderedMap): int
fn key_at_str(m: StringOrderedMap, index: int): string
fn value_at_str(m: StringOrderedMap, index: int): string
fn create_ptr(): PtrOrderedMap
fn create_ptr_cap(capacity: int): PtrOrderedMap
fn find_ptr_index(m: PtrOrderedMap, key: string): int
fn get_ptr(m: PtrOrderedMap, key: string): option.Option[pointer]
fn has_ptr(m: PtrOrderedMap, key: string): bool
fn len_ptr(m: PtrOrderedMap): int
fn key_at_ptr(m: PtrOrderedMap, index: int): string
fn value_at_ptr(m: PtrOrderedMap, index: int): pointer
Procedures
proc set_int(m: IntOrderedMap, key: string, value: int)
proc remove_int(m: IntOrderedMap, key: string)
proc rebuild_int_buckets(m: IntOrderedMap)
proc clear_int(m: IntOrderedMap)
proc set_str(m: StringOrderedMap, key: string, value: string)
proc remove_str(m: StringOrderedMap, key: string)
proc rebuild_str_buckets(m: StringOrderedMap)
proc clear_str(m: StringOrderedMap)
proc set_ptr(m: PtrOrderedMap, key: string, value: pointer)
proc remove_ptr(m: PtrOrderedMap, key: string)
proc rebuild_ptr_buckets(m: PtrOrderedMap)
proc clear_ptr(m: PtrOrderedMap)
Generated by reefc doc