In-Memory Communication Manager (Bidirectional Sessions)
Goal
Design a lightweight, in-memory manager that tracks bidirectional user-to-user sessions (think direct-message sessions). Provide 2–3 API functions:
-
connect(userA, userB): establish a bidirectional session.
-
disconnect(userA, userB): terminate the session.
-
clear(userA, userB): remove session state/history while keeping users connected.
Requirements
-
Specify method signatures (language of your choice), key data structures (e.g., hash maps, adjacency sets), and expected time/space complexities.
-
Discuss edge cases (duplicate connects, self-connects, missing sessions) and how to handle invalid inputs.
-
Describe concurrency handling and guarantees.
-
Include a brief testing plan.
Assume user IDs are strings (or integers) and all data lives in a single process. No persistence is required.