struct Oak::Context(T)

Overview

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:

Defined in:

oak/context.cr

Constant Summary

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

Instance Method Summary

Constructor Detail

def self.new(child : Node(T) | Nil = nil) #

[View source]

Instance Method Detail

def children #

[View source]
def children? #

Returns true of there are associated children


[View source]
def find_child(first_char : Char | Nil) #

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


[View source]
def payload #

[View source]
def payload? #

[View source]
def payloads #

[View source]
def payloads? #

Returns true of there are associated payloads


[View source]
def rebuild_child_map_if_needed #

Rebuild child map if threshold is exceeded


[View source]