11typedef struct ts_node {
A sliding sampling window represented as a linked list of timestamps.
Definition window.h:19
struct timespec last_emit
Definition window.h:27
ts_node_t * head
Definition window.h:20
long window_size_ms
Definition window.h:24
size_t count
Definition window.h:22
ts_node_t * tail
Definition window.h:21
long slide_ms
Definition window.h:25
A timestamp node.
Definition window.h:11
struct ts_node * next
Definition window.h:13
struct timespec ts
Definition window.h:12
int sliding_window_should_emit(const sliding_window_t *w, struct timespec now)
Checks if it's time to emit (slide_ms elapsed since last emit).
Definition window.c:78
void sliding_window_mark_emitted(sliding_window_t *w, struct timespec now)
Called on emit, sets the last emit time.
Definition window.c:90
size_t sliding_window_count(const sliding_window_t *w)
Get the count of events currently in the window.
Definition window.c:95
void sliding_window_destroy(sliding_window_t *w)
Graceful cleanup of a window. Frees all ts_node_t in the window, not the window itself.
Definition window.c:29
int sliding_window_add(sliding_window_t *w, struct timespec event_ts)
Append the event timestamp as ts_node_t to tail. Evicts head while head->ts < (event_ts - window_size...
Definition window.c:42
struct timespec sliding_window_newest(const sliding_window_t *w)
Get the timestamp of the newest event in the window.
Definition window.c:102
struct timespec sliding_window_oldest(const sliding_window_t *w)
Get the timestamp of the oldest event in the window.
Definition window.c:97
void sliding_window_init(sliding_window_t *w, long window_size_ms, long slide_ms)
Initialize a sliding window.
Definition window.c:18