Structures

Complexity Advanced

SharedDirectory

The ranger station returns. So far each notebook held one flat page of named lines. Alice wants a folder for the Eagle Creek gate and bridge notes. Bob makes a folder by the same name before he sees Alice's, while Carol has notes from another trail to file.

A diamond-sealed folder sits in a nested cabinet; a delayed note remains tied to a retired folder's round seal.

Give each trail its own folder

A SharedDirectory works like SharedMap (the ranger numbers every change) but adds folders. Each folder has its own map of named entries and can hold more folders. Alice makes /eagle-creek and files gate-status: Report pending inside it. She can put bridge-status: Inspection due in a child folder at /eagle-creek/bridge. Carol can make a /ridge-pass folder for notes from that trail. Any hiker can add or remove a named note, or remove a folder when the survey no longer needs it.

Alice can use her new folder and see the notes she adds or removes while she waits for the ranger's number. Bob also makes /eagle-creek before he sees Alice's folder. The ranger numbers both creates, so all three hikers end up with one shared folder. The ranger also numbers changes to the entries inside it, as in SharedMap.

HikerActionAfter sharing
AliceMake /eagle-creekOne shared /eagle-creek folder
BobMake /eagle-creek
Both hikers' notebooks refer to the same folder.

The demo below shows creating and removing folders at the root. SharedDirectory also supports notes inside folders and folders inside other folders.

Three hikers' notebooks

Make one shared folder

Create or remove a folder from any notebook. Try Alice and Bob making /eagle-creek before sharing their notes.

How they agree The ranger numbers folder changes. A new folder can reuse an old name without reusing its identity.

Alice

No notes yet

No folders

Bob

No notes yet

No folders

Carol

No notes yet

No folders
Trail relay Ranger numbers folder changes 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.

Run the race, or let any hiker change their own notebook.

A new folder can reuse an old name

Later, Alice removes /eagle-creek when that survey ends. Bob still has a delayed change to a note in the old folder. Carol makes a fresh /eagle-creek for a new survey. The ranger gives the new folder its own identity even though its path is the same. When Bob's note arrives, it cannot change Carol's new folder. She does not find an old survey note in it.

This is the observed-remove set's lesson again: a name is not an identity. There, dots told two Eagle Creek cameras apart. Here, the ranger gives each folder its own identity.

The ranger station must be reachable

Like every sequenced structure, SharedDirectory needs the ranger to number folder and note changes. Inside a folder, each note follows SharedMap's rule: the last numbered change wins.

The next lesson, JsonOt, edits one JSON document, where two hikers can insert into the same list at the same position.

Sources and implementation

Sources: Watershed's SharedDirectory 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.