Structures

Complexity Introductory

GSet

Alice, Bob, and Carol hike separate trails and list every wildlife camera they find. Their first rule is simple: they can add names to the survey, but they cannot remove them.

A wildlife camera strapped to a tree beside a notebook with distinct camera sketches and a loose copy of one existing report.

Alice reports Eagle Creek

Alice finds the Eagle Creek camera and adds its name to her notebook. Bob and Carol have not found her note yet, so their lists are still empty.

A GSet only adds members. When a note arrives, the hiker adds every name on it to their notebook; a name they already have is not added again. The notebook keeps the union of every name the hiker has seen.

MomentAliceBobCarol
Alice reportsEagle Creekemptyempty
Report deliveredEagle CreekEagle CreekEagle Creek
Old copy repeatsEagle CreekEagle CreekEagle Creek
The union keeps one member even when the trail delivers Alice's report more than once.

If Bob reports Ridge Pass at the same time, the order of arrival does not matter: every notebook ends with both names.

Three field notebooks

Combine the hikers' reports

Alice and Bob report different cameras while Carol waits. Exchange the records and watch every notebook keep the same union.

Merge rule Keep every distinct reported name.

Alice

No reports yet

Visible camera list

Empty set

Checkpoint note Report: Eagle Creek

Bob

No reports yet

Visible camera list

Empty set

Checkpoint note Report: Ridge Pass

Carol

No reports yet

Visible camera list

Empty set

Checkpoint note No note in this race

Trail relay No ordering decision 0 notes shared

Mechanism evidence Entries can only accumulate.

  1. No notes shared yet.

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

Run the survey race, or let any hiker report a camera.

Names cannot be removed

Alice returns to Eagle Creek and finds that the old camera has been taken down. The hikers now need a list of active cameras, but a GSet cannot express “remove Eagle Creek.” If Alice erased the name from her notebook, Carol's older note, which still lists Eagle Creek, would add it back at the next merge.

The next lesson, TwoPSet, records removals on a second page instead of erasing names.

Sources and implementation

Sources: Watershed's GSet kernel. The grow-only set is described in A comprehensive study of Convergent and Commutative Replicated Data Types.

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