#include <time.h>
#include <stdlib.h>
#include <stdint.h>
Go to the source code of this file.
◆ sliding_window_add()
Append the event timestamp as ts_node_t to tail. Evicts head while head->ts < (event_ts - window_size_ms).
- Parameters
-
| w | Pointer to the window. |
| event_ts | Timestamp of the event. |
- Returns
- 0 on success, -1 on alloc error, -2 on empty sliding window.
◆ sliding_window_count()
Get the count of events currently in the window.
- Parameters
-
- Returns
- Number of events in the window.
◆ sliding_window_destroy()
Graceful cleanup of a window. Frees all ts_node_t in the window, not the window itself.
- Parameters
-
◆ sliding_window_init()
| void sliding_window_init |
( |
sliding_window_t * | w, |
|
|
long | window_size_ms, |
|
|
long | slide_ms ) |
Initialize a sliding window.
- Parameters
-
| w | Pointer to the window. |
| window_size_ms | Window span. |
| slide_ms | Sliding interval. |
◆ sliding_window_mark_emitted()
Called on emit, sets the last emit time.
- Parameters
-
| w | Pointer to the window. |
| now | Current timestamp. |
◆ sliding_window_newest()
Get the timestamp of the newest event in the window.
- Parameters
-
- Returns
- Timespec of the newest event.
◆ sliding_window_oldest()
Get the timestamp of the oldest event in the window.
- Parameters
-
- Returns
- Timespec of the oldest event.
◆ sliding_window_should_emit()
| 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).
- Parameters
-
| w | Pointer to the window. |
| now | Current timestamp. |
- Returns
- 1 if should emit, 0 otherwise.