summaryrefslogtreecommitdiff
path: root/idlist.h
blob: 879b894105a58a663fe5185b94d0a114580efb82 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
#ifndef _LIBMANDA_IDLIST_H_
#define _LIBMANDA_IDLIST_H_

#include "libmanda.h"

struct manda_IDList {
	/* used ids are marked with a "1" in the bitvector (represented as array of gulong) */
	GArray *bitvector;

	/* all ids are in the range [0, max_ids[, i.e. 0 <= id < max_ids
	 * although the type is guint, it has to fit in a gint too, as we
	 * use gint for the ids in the interface, so we can use -1 as a special value.
	 */
	guint max_ids;

	/* if all ids in [0, used_ids-1] are used, next_free_id is -1
	 * if not, then all available ids are >= next_free_id,
	 * so we can start at next_free_id for searching the next free id
	 */
	gint next_free_id;
	guint used_ids;
};

/* create new idlist; the parameter max_ids is "signed" on purpose */
manda_IDList* manda_idlist_new(gint max_ids);

/* free idlist */
void manda_idlist_free(manda_IDList *l);

/* request new id; return -1 if no id is available, valid ids are always > 0 */
gint manda_idlist_get(manda_IDList *l);

/* check whether an id is in use and can be "_put" */
gboolean manda_idlist_is_used(manda_IDList *l, gint id);

/* release id. never release an id more than once! */
void manda_idlist_put(manda_IDList *l, gint id);

#endif