Structures

Complexity Advanced

OR-map

In an LWWMap, a crossing-out with a later time would erase a delivery its writer never saw. The hikers also track supplies: each notebook has a stockpile page where Eagle Creek holds 5 crates. Alice crosses out the old listing while Bob records a new delivery, before either has seen the other's note.

A stockpile ledger retains its tally and an old identity slip beside a loaded cart and a differently tagged delivery report.

Cross out only what you have seen

All three hikers start with Eagle Creek · 5 crates in their notebooks. Alice thinks the old stockpile listing is no longer needed, so she crosses out her line. She has not removed any physical crates. Bob has not seen her note. He records a delivery of 3 more crates and changes his own total from 5 to 8. Carol still has the earlier 5-crate report.

An OR-map is an observed-remove map: the rule from the observed-remove set, applied to named lines. Alice can remove the entry she saw, but she cannot remove Bob's update before she receives it.

Hiker Before either note Notes not yet shared After sharing
Alice Eagle Creek · 5 crates Eagle Creek · 5 crates Eagle Creek · 8 crates
Bob Eagle Creek · 5 crates Eagle Creek · 8 crates (5 + 3) Eagle Creek · 8 crates
Carol Eagle Creek · 5 crates Eagle Creek · 5 crates Eagle Creek · 8 crates
Before sharing, Bob's update has not reached Alice, and Carol has received neither note. Scroll sideways to read every notebook.

When the hikers exchange notes, they keep the Eagle Creek line because Alice had not seen Bob's update when she crossed it out. Bob's tally includes the original 5 crates and the 3 he added, so all three notebooks show 8. If Alice had seen Bob's update before crossing out the line, she could have removed that entry too.

Three hikers' notebooks

Keep a new stockpile note

Start with 5 crates. Alice crosses out the line she saw while Bob logs 3 more. Compare their notebooks.

How they agree Crossing out an entry does not remove a new note you have not seen.

Alice

Starting notes received

Eagle Creek
5

Note to share Cross out Eagle Creek the stockpile entry Alice saw

Bob

Starting notes received

Eagle Creek
5

Note to share Eagle Creek tally: +3 Bob's new crate count

Carol

Starting notes received

Eagle Creek
5

Note to share No note in this race Carol observes delivery

Trail relay New stockpile notes stay 0 operations shared

What the notes show No race delivered yet.

  1. No operations shared yet.

Enable JavaScript to run the demo. The race and expected result remain in the lesson.

Eagle Creek starts with 5 supply crates. Race removal against a concurrent delivery.

A merge rule inside each line

The Eagle Creek line has two parts. Alice crosses out the version she has seen in the outer OR-map. Under that name, each notebook holds a PN-counter for the crates. Bob records 3 more crates alongside the starting 5. The hikers merge the counter values, and the result is 8. If two hikers add crates without seeing each other's notes, both additions count after merging.

The crate count is one choice. Watershed's OR-map can hold other values under each name, and each keeps its own merge rule: a last-writer-wins register (RegisterMode), a multi-value register (MvRegisterMode), or a set of names (OrSetMode). Removing a name always uses observed removal. This demo uses only the crate-count mode, TallyMode.

A removal can lose to new work

Alice wanted the Eagle Creek line gone, but it came back with 8 crates. An OR-map always favors new work the remover did not see. Like the OR-set, it also keeps a record of removals, which costs storage.

The next lesson, SharedDirectory, brings the ranger station back to keep folders apart when names repeat.

Sources and implementation

Sources: Watershed's OR-map kernel.

Implementation: The demo calls the Watershed kernel's tally mode through the site's Gleam toolkit. The trail relay carries notes without ordering them.