Skip to content

Conversation

sggeorgiev
Copy link

Overview

Adds efficient TTL tracking and average TTL computation to the estore system using a constant-time algorithm. This enhancement allows for quick insights into expiration characteristics without needing to scan all keys.

Changes

  • estoreGetAvgTTL(): Returns the average TTL across all items in an estore (sum_ttl / count)
  • estoreReduceTTLSum(): Efficiently reduces the total TTL sum based on elapsed time and number of keys, simulating TTL decay over time

Key Features

  • O(1) Performance: Both TTL reading and TTL sum adjustment are performed in constant time, regardless of the number of keys
  • Accurate Decay Modeling: TTL sum is reduced as time progresses to maintain realistic tracking, without tracking each key individually

Test Coverage

✅ estoreGetAvgTTL() correctly computes average TTL with multiple entries
✅ TTL averages are correctly updated after removing expirable items
✅ estoreReduceTTLSum() reduces TTL sum proportionally based on elapsed time and key count
✅ Ensures TTL sum never becomes negative
✅ Handles edge cases like empty estore or zero elapsed time gracefully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant