Tracing the LinkedMap
Let’s trace a sequence of operations and watch how head, the nodes, and size change. Each node is drawn as key: value.
We start with new LinkedMap<>() and put three new keys: put("ann", "x7"), put("bo", "q3"), then put("cal", "m9"). Each call links a new node at the head and returns true. The size is 3.
┌─────────┐ ┌─────────┐ ┌─────────┐
head ───▶ │ cal: m9 │ ──▶ │ bo: q3 │ ──▶ │ ann: x7 │ ──▶ null
└─────────┘ └─────────┘ └─────────┘
put("bo", "z5") finds the node for bo and replaces its value with z5. No node is created, so the size stays 3, and put returns false.
┌─────────┐ ┌─────────┐ ┌─────────┐
head ───▶ │ cal: m9 │ ──▶ │ bo: z5 │ ──▶ │ ann: x7 │ ──▶ null
└─────────┘ └─────────┘ └─────────┘
get("ann") passes cal and bo before it reaches ann, and returns x7.
Removals work as in the LinkedSet trace.