Lesson 5.2

Inserting a route - the longest common prefix and the split

The four cases of inserting a label under a node, the edge split at the longest common prefix, and the RouteRecord whose property layout is fixed at creation. Then you write route and the recursive insert.

34 minsrc/router.js
  • Walk the four insert cases - new leaf, exact match, descend, and the partial-match split.
  • Handle the split sub-case where the incoming label is entirely a prefix of an existing edge.
  • Build a RouteRecord with all seven lifetime fields declared at creation, and store it in a null-prototype method map.
Locked

This chapter is part of the framework capstone. Chapters 1 and 2 are free to build - unlock the rest to keep going.

Unlock the depth