Skip to content

Add function to calculate average TTL #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: redesign-expire
Choose a base branch
from

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