Inspired by dances, here is a data structure called “pair”. Please let me know if similar data structure exists.
A pair has two elements – element  and element .
An element may “join” or “leave” the pair under some conditions:
- The pair is in “empty” state to start with
- When created, an element must be in “waiting” state. The pair goes into “proposed” state
- If two elements are in “waiting” state, they enter in a “bonded” state. The pair goes into “full” state.
- Once “bonded”, if one of the element wants to “leave”, it enters “leave requested” state. The pair goes into “shaky” state
- If both the elements are in “leave requested” state, they are “debonded” from the pair and destroyed. The pair goes into “empty” state
- If a “waiting” element wants to “leave” [that is, the pair was “proposed”], it is directly debonded and destroyed. The pair goes into “empty” state
Most paired dances follow this data structure. I guess one-to-one chats also must be following this structure. What other uses can you think of?
Also, there is a possibility of a directional pair – kind of inner/outer loops of a raasa dance.
And finally, it could be more than a pair, a n-tuplet.