Out of Order Events
A function to handle out of order streamed events. [This is the second assignment for Bhumio]
Edge case considerations
- Out-of-order arrival — Events are applied only when timestamp is strictly greater than the last seen for that id; older arrivals are ignored.
- Duplicate events — Same id + timestamp is treated as already seen and skipped, so duplicates do not change state.
- Late events — Late-arriving events with a newer timestamp still win; stale updates are rejected by the timestamp check.
- Delete safety — A delete is applied only if its timestamp is the latest for that id; out-of-order deletes do not remove newer creates/updates.
- Update before create — An update (or create) with a newer timestamp will overwrite or create the item; no separate "create" required first.
- Infinite stream safety — Bounded state: one entry per id in items and latestTimestamp; safe for unbounded event streams.
- Time complexity: O(1) per event — Map get/set/delete and switch are constant time; getActiveItems() is O(n) in active item count.