-
Notifications
You must be signed in to change notification settings - Fork 0
/
mbq.h
28 lines (22 loc) · 916 Bytes
/
mbq.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
struct mbq_accounting {
size_t stale_threshhold;
int stale_item_count;
int begin_index;
size_t size;
size_t item_size;
void *array;
};
void *mbq_init(struct mbq_accounting *accounts, size_t item_size, size_t item_count);
void mbq_destroy(struct mbq_accounting *accounts);
void *mbq_expand(struct mbq_accounting *accounts, size_t extra_item_capacity);
size_t mbq_wipe_pages(struct mbq_accounting *accounts, size_t start_index, size_t dead_items);
void mbq_delete_head(struct mbq_accounting *accounts, size_t items_to_delete);
// Note: ARRAY must not be void *
// the array[0] ensures this.
// Note: The , operator in C
// is not common but is useful.
#define mbq_get_first_item(accounting, array) \
(array[0], array + accounting->stale_item_count)
#define mbq_get_item_from_index(accounting, array, index) \
(array[0], array + (accounting->stale_item_count + index - account->begin_index))