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 arrivalEvents are applied only when timestamp is strictly greater than the last seen for that id; older arrivals are ignored.
  • Duplicate eventsSame id + timestamp is treated as already seen and skipped, so duplicates do not change state.
  • Late eventsLate-arriving events with a newer timestamp still win; stale updates are rejected by the timestamp check.
  • Delete safetyA 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 createAn update (or create) with a newer timestamp will overwrite or create the item; no separate "create" required first.
  • Infinite stream safetyBounded state: one entry per id in items and latestTimestamp; safe for unbounded event streams.
  • Time complexity: O(1) per eventMap get/set/delete and switch are constant time; getActiveItems() is O(n) in active item count.

How to use in React