durian-hypermediaStyle

All fixtures · From the Format page · format/63-animation-an-array-a-map-and-a-tree-in-one-scene.dh.md

Source
---
title: "Animation: an array, a map and a tree in one scene"
description: A fixture made from the Format page section of the same name.
---

## Animation: an array, a map and a tree in one scene

Data structures are things like any other, and live in one scene with a person, a service and a database. Each is `closed=yes`: small and faint until the story zooms into it. `map cart "cart sizes" buckets=3: ana: 3, ...` is a map of keys and values, drawn as a hash table: a key's bucket is the sum of its letters' codes, mod 3. `get cart ana` looks a key up (its entry lights up, and its bucket is framed), `get ids 3` reads an array by index, and `put cart dee: 4` adds an entry. `dir=down` on the fence runs the scene top to bottom. Without `buckets=`, a map is a table of keys and values.

```animation dir=down size=s
family svc "the service"
family data "its data"
person ana "Ana"
group api "orders service" layout=row is=svc
array ids "sorted ids" in api closed=yes is=data: 12, 19, 27, 34
map cart "cart sizes" in api buckets=3 closed=yes is=data: ana: 3, ben: 7, cy: 9
tree idx "price index" in api closed=yes is=data
pill p30 "30" in idx
pill p20 "20" in idx under p30 left
pill p50 "50" in idx under p30 right
pill p40 "40" in idx under p50 left
cylinder db "orders database"
ana -> api
api -> db
@step Ana asks for her orders. The service keeps three structures in memory.
say ana: my orders, please
@step Zoom into the array: four ids, sorted.
zoom into ids
@step Index 3 is read at once: 34. No search.
get ids 3
@step Now the map. A key's bucket: the sum of its letters' codes, mod 3.
zoom out
then
zoom into cart
@step ana goes to bucket 1, which cy shares (a chain). Its value: 3 items.
get cart ana
@step A new key, dee, goes to bucket 2.
put cart dee: 4
@step Now the tree: smaller prices go left, bigger right.
zoom out
then
zoom into idx
@step Find 40: at the root, 30, go right.
highlight p30
@step At 50, go left.
highlight p50
@step 40 is found.
highlight p40 tone=good
@step Back out: the service answered from memory, not the database.
zoom out
say ana: that was fast
```
LLM view
---
title: "Animation: an array, a map and a tree in one scene"
description: A fixture made from the Format page section of the same name.
source: format/63-animation-an-array-a-map-and-a-tree-in-one-scene.dh.md
---
<!-- Made by dh llm from the source; nobody edits this file. -->

## Animation: an array, a map and a tree in one scene

Data structures are things like any other, and live in one scene with a person, a service and a database. Each is `closed=yes`: small and faint until the story zooms into it. `map cart "cart sizes" buckets=3: ana: 3, ...` is a map of keys and values, drawn as a hash table: a key's bucket is the sum of its letters' codes, mod 3. `get cart ana` looks a key up (its entry lights up, and its bucket is framed), `get ids 3` reads an array by index, and `put cart dee: 4` adds an entry. `dir=down` on the fence runs the scene top to bottom. Without `buckets=`, a map is a table of keys and values.

Animation, 11 steps. Starts with: person ana "Ana"; group api "orders service" [array ids "sorted ids": 12, 19, 27, 34, map cart "cart sizes" closed, 3 buckets, a key's bucket is the sum of its letters' codes mod 3: ben: 7 (bucket 0), ana: 3 (bucket 1), cy: 9 (bucket 1), tree idx "price index" closed [pill p30 "30", pill p20 "20" under p30 left, pill p50 "50" under p30 right, pill p40 "40" under p50 left]]; cylinder db "orders database". Connected: ana -> api, api -> db. Families, one colour each: svc "the service" (api); data "its data" (ids, cart, idx).

1. Ana asks for her orders. The service keeps three structures in memory.
2. Zoom into the array: four ids, sorted.
   zoom into ids
3. Index 3 is read at once: 34. No search.
   get ids 3 -> 34
4. Now the map. A key's bucket: the sum of its letters' codes, mod 3.
   zoom out of ids
   zoom into cart
5. ana goes to bucket 1, which cy shares (a chain). Its value: 3 items.
   get cart ana -> 3 (bucket 1)
6. A new key, dee, goes to bucket 2.
   put cart dee: 4
7. Now the tree: smaller prices go left, bigger right.
   zoom out of cart
   zoom into idx
8. Find 40: at the root, 30, go right.
9. At 50, go left.
10. 40 is found.
11. Back out: the service answered from memory, not the database.
   zoom out of idx

Animation: an array, a map and a tree in one scene

Data structures are things like any other, and live in one scene with a person, a service and a database. Each is closed=yes: small and faint until the story zooms into it. map cart "cart sizes" buckets=3: ana: 3, ... is a map of keys and values, drawn as a hash table: a key's bucket is the sum of its letters' codes, mod 3. get cart ana looks a key up (its entry lights up, and its bucket is framed), get ids 3 reads an array by index, and put cart dee: 4 adds an entry. dir=down on the fence runs the scene top to bottom. Without buckets=, a map is a table of keys and values.

Animation, 11 steps. Starts with: person ana "Ana"; group api "orders service" [array ids "sorted ids": 12, 19, 27, 34, map cart "cart sizes" closed, 3 buckets, a key's bucket is the sum of its letters' codes mod 3: ben: 7 (bucket 0), ana: 3 (bucket 1), cy: 9 (bucket 1), tree idx "price index" closed [pill p30 "30", pill p20 "20" under p30 left, pill p50 "50" under p30 right, pill p40 "40" under p50 left]]; cylinder db "orders database". Connected: ana -> api, api -> db. Families, one colour each: svc "the service" (api); data "its data" (ids, cart, idx). 1. Ana asks for her orders. The service keeps three structures in memory. 2. Zoom into the array: four ids, sorted. zoom into ids 3. Index 3 is read at once: 34. No search. get ids 3 -> 34 4. Now the map. A key's bucket: the sum of its letters' codes, mod 3. zoom out of ids zoom into cart 5. ana goes to bucket 1, which cy shares (a chain). Its value: 3 items. get cart ana -> 3 (bucket 1) 6. A new key, dee, goes to bucket 2. put cart dee: 4 7. Now the tree: smaller prices go left, bigger right. zoom out of cart zoom into idx 8. Find 40: at the root, 30, go right. 9. At 50, go left. 10. 40 is found. 11. Back out: the service answered from memory, not the database. zoom out of idx

  • the service
  • its data
orders serviceorders servicesorted ids · 4 itemssorted ids · 4 itemscart sizes · 3 keyscart sizes · 3 keysprice index · 4 nodesprice index · 4 nodes001122AnaAna12192734ben: 7ana: 3cy: 930205040orders databaseorders databasemy orders, please
1Ana asks for her orders. The service keeps three structures in memory.
1 / 11
All steps (11)