1 #ifndef RESERVOIR_H_MZSA8WJ3
2 #define RESERVOIR_H_MZSA8WJ3
14 typedef struct reservoir_
{
15 size_t reservoir_sz
; /* allocated slots */
16 size_t reservoir_used
; /* slots filled */
17 unsigned long reservoir_tally
; /* total number of items remembered */
22 #define D_RESERVOIR(__r__) do {\
24 NOTIFY_DEBUG("reservoir:%p sz: %zu used:%zu tally:%zu", (__r__), (__r__)->reservoir_sz, (__r__)->reservoir_used, (__r__)->reservoir_tally);\
25 for (i = 0; i < (__r__)->reservoir_sz; i++) {\
26 D_BUF("reservoir[%zu] ", (__r__)->reservoir[i], i);\
30 #define D_RESERVOIR(...)
34 Allocate and return a new reservoir capable of holding #sz bufs.
36 reservoir_t
reservoir_new(size_t sz
);
39 Increase the storage capacity of the reservoir pointed to by #preservoir
42 int reservoir_grow(reservoir_t
*preservoir
, size_t growby
);
45 Remember #buf, forgetting another buf at random if the reservoir
46 pointed to by #preservoir is already full to capacity.
48 void reservoir_remember(reservoir_t reservoir
, buf_t buf
);
51 Write the contents of the bufs within #reservoir to #fd, each with a
54 int reservoir_write(int fd
, reservoir_t reservoir
, char delim
);
56 /* reservoir_write_meta
57 Write metadata of #reservoir and #samples to fd.
59 int reservoir_write_meta(int fd
, reservoir_t reservoir
, unsigned long samples
, char delim
);
61 #endif /* RESERVOIR_H_MZSA8WJ3 */