awelgorithms

Nested get with a missing inner map

Updated

Nested get is: inner = get(outer, u); if inner is missing, the whole lookup misses (or you create inner, if writing). You must not call get on a missing inner. Put-if-absent of {} is the write-path helper.

What to focus on

A missing inner is not the same as an empty inner {}. Empty inner means you have seen u and stored no v yet. Absent u means you have not created that row.

Worked examples

miss outer

a = [4] as {4:{1:2}}, get 9 then 1
  1. 9 is not an outer key
  2. stop

Result: miss — do not touch an inner

hit outer miss inner

a = [4] as {4:{1:2}}, get 4 then 9
  1. inner exists
  2. 9 is not in inner

Result: miss the leaf, outer stays

empty outer

a = []
  1. every nested get misses

Result: miss

Try it

Write nestedGet(m, u, v). m is the outer map of inner maps. u is the outer key. v is the inner key. If u is missing, return miss without touching an inner map. If u exists but v is missing, return miss. If both exist, return the leaf. Create an inner map only on writes, not on get. a = [4] as {4:{1:2}}, get 9 then 1 → miss — do not touch an inner. a = [4] as {4:{1:2}}, get 4 then 9 → miss the leaf, outer stays. a = [] → miss.

keys are integers. Outer maps store inner maps. Missing outer and missing inner keys are in scope.