Hazel Tree

High-performance tree structure

Hazel Tree is the tree structure system used by Blackcube to organize content hierarchically: menus, breadcrumbs, section navigation, etc. It relies on a mathematical approach that prioritizes read performance over write performance.

Concretely, Blackcube uses a structure based on rational fractions rather than the classic parent-child reference approach.

Attribution

Hazel Tree is an implementation of Dan Hazel's research work published in 2008: "Using rational numbers to key nested sets". This innovative approach solves the limitations of traditional Nested Sets by using rational fractions rather than integers, making insertion operations much more efficient. Read the original paper on arXiv

The Problem with Classic Trees

Traditional Trees (Adjacency List)

Classic trees simply store a reference to each element's parent. This approach has advantages and disadvantages:

  1. Simple and fast insertion
  2. Reading requires multiple recursive queries
  3. Cache mandatory to obtain acceptable performance

Hazel Tree

The Hazel Tree approach inverts this logic by optimizing reading at the expense of writing:

  1. Slightly more complex insertion, but these operations are rare
  2. Ultra-fast reading with a single SQL query
  3. No cache necessary for read operations

Performance

Display a 3-Level Menu

With a classic approach, about 50 SQL queries are needed to load all elements and their relationships. With Hazel Tree, a single query is sufficient.

Generate a 5-Level Breadcrumb

The classic approach requires 5 consecutive SQL queries to traverse the hierarchy upward. Hazel Tree retrieves everything in a single query.

Retrieve All Descendants

With classic trees, recursive queries are needed whose number depends on the tree's depth. Hazel Tree retrieves the entire branch in a single query, regardless of depth.

In Practice

You automatically benefit from Hazel Tree when using the following features:

  1. Displaying a navigation menu
  2. Generating a breadcrumb
  3. List of a section's children
  4. Retrieving a complete tree branch

No specific action is required from you. Blackcube automatically manages the Hazel Tree structure in the background when creating, modifying or deleting nodes.

Key Points to Remember

  1. Optimized for reading: Hazel Tree is designed for sites where displaying hierarchical content is frequent. Every visitor navigating your site benefits from optimal performance.
  2. Automatic management: You have nothing to configure or manage. Blackcube automatically takes care of maintaining the Hazel Tree structure consistently.

Warning

Adding, moving or deleting nodes is slightly more resource-intensive than with a classic approach. However, these administration operations are rare compared to the millions of displays generated by your visitors.