Posts

Showing posts from July, 2025

AdhocTree in C#

A Performant Flexible Tree Structure with Type-Segregated Storage When working with hierarchical or tree-structured data, developers often face a trade-off between flexibility and performance . Traditional approaches either use: Concrete types for strict schemas and fast access, but limited flexibility. Dynamic objects for flexible, schema-less data, but with runtime overhead and boxing of value types. AdhocTree  attempts to provide the best of both worlds. It's a tree data structure that combines the flexibility of dynamic objects with the performance benefits of type-specific storage. What Is It? AdhocTree is a tree-like data structure designed to store arbitrary named values at each node, supporting a wide range of value types. It achieves this by: Storing values in separate arrays by type (e.g., one array for int , another for double , etc.), avoiding boxing of value types. Maintaining a mapping from names to (type, index) pairs, so each name points to the corr...