SharedMap
As in RegisterMap, each notebook holds a page of named lines, and the ranger station numbers every change. This time there is one rule: the last numbered change to each line wins. Alice writes Trail open on the gate-status line while Bob writes Trail closed, before either sees the other's note. The bridge-status line stays as it was.
The ranger numbers each change
In a SharedMap, the ranger numbers every accepted change. Each named line has its own answer: changing gate-status does not erase bridge-status. When two hikers change the same line, all three hikers copy the answer from the higher-numbered note after delivery.
Unlike RegisterMap, SharedMap shows a change before the ranger numbers it. Alice sees her own note as soon as she writes it. She keeps it in her notebook while she waits for the ranger's number. Even if Bob's note arrives first, Alice still sees her own answer until the ranger sends back the numbered changes.
| Line | Before | After Alice and Bob's notes |
|---|---|---|
| gate-status | Report pending | Trail closed |
| bridge-status | Inspection due | Inspection due |
Three hikers' notebooks
Update a shared trail report table
Change either line from any notebook. Turn off Auto-deliver to compare local views before the ranger numbers the notes.
How they agree For each line, keep the change with the highest number from the ranger.
Alice
Starting notes received
- Line
- Report
- bridge-status
- Inspection due
- gate-status
- Report pending
Bob
Starting notes received
- Line
- Report
- bridge-status
- Inspection due
- gate-status
- Report pending
Carol
Starting notes received
- Line
- Report
- bridge-status
- Inspection due
- gate-status
- Report pending
What the notes show No operations shared yet. The starting map uses numbers through 7. This list shows new changes.
- No operations shared yet.
Enable JavaScript to run the demo. The race and expected result remain in the lesson.
Each notebook starts with the same two reports. Change either line from any notebook.
Two limits
Alice's gate answer is gone. Like LWWRegister, SharedMap keeps one answer for each line and discards the other. And like every sequenced structure, it needs the ranger station to number changes.
The next lesson, LWWMap, drops the ranger: the hikers compare the time beside each line instead.
Sources and implementation
Sources: Watershed's SharedMap kernel.
Implementation: The demo calls the Watershed kernel through the site's Gleam toolkit and connects three clients through Sluice, which plays the ranger station.