struct

Oak::Context(T)

Inherits Struct / Value / Object

Internal data structure containing node children and payloads.

Performance Optimization

Context automatically builds a HashMap for O(1) child lookups when the number of children exceeds CHILD_MAP_THRESHOLD (10). This dramatically improves performance for high-fanout nodes common in REST APIs.

Example: A node with 20 children will use HashMap, reducing average lookup from 10 comparisons (linear search) to 1 (hash lookup).

:nodoc:

Constants

CHILD_MAP_THRESHOLD = 10

Threshold for switching from linear search to HashMap-based child lookup.

When children.size >= 10, a HashMap is automatically built for O(1) lookups. This threshold balances memory overhead vs. lookup performance.

Constructors

new(child : Node(T) | Nil = nil)

Instance methods

children
children?

Returns true of there are associated children

find_child(first_char : Char | Nil)

Find a child by first character, using hash map for large child sets

payload
payload?
payloads
payloads?

Returns true of there are associated payloads

rebuild_child_map_if_needed

Rebuild child map if threshold is exceeded