Hybrid Logical Clock update
Your task
Hybrid Logical Clocks (HLC) combine physical time with a logical counter to give monotonic, causally-consistent timestamps. An HLC is a pair [l, c] where l is the physical-time component and c is the logical counter. On a SEND or LOCAL event with current physical clock reading pt, the update is: new_l = max(old_l, pt); if new_l == old_l then c = old_c + 1 else c = 0. On a RECEIVE of a message stamped [m_l, m_c] with physical reading pt: new_l = max(old_l, m_l, pt); if new_l == old_l == m_l then c = max(old_c, m_c) + 1; elif new_l == old_l then c = old_c + 1; elif new_l == m_l then c = m_c + 1; else c = 0. Process the event stream and return the final HLC [l, c]. Each event is ['local', pt] or ['recv', pt, m_l, m_c]. Start at HLC [0, 0].
Examples
hlc_final(events: list[list]) -> list[int]Example 1
Input
hlc_final([["local", 10], ["local", 10]])Output
[10, 1]