]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_uniqid.h
DBUFF loging updated to match other projects.
[ulut.git] / ulut / ul_uniqid.h
1 /*******************************************************************
2   uLan Utilities Library - C library of basic reusable constructions
3
4   ul_uniqid.h  - unique ID generator
5
6   (C) Copyright 2003-2004 by Pavel Pisa - Originator
7
8   The uLan utilities library can be used, copied and modified under
9   next licenses
10     - GPL - GNU General Public License
11     - LGPL - GNU Lesser General Public License
12     - MPL - Mozilla Public License
13     - and other licenses added by project originators
14   Code can be modified and re-distributed under any combination
15   of the above listed licenses. If contributor does not agree with
16   some of the licenses, he/she can delete appropriate line.
17   Warning, if you delete all lines, you are not allowed to
18   distribute source code and/or binaries utilizing code.
19   
20   See files COPYING and README for details.
21
22  *******************************************************************/
23
24 #ifndef _UL_UNIQID_H
25 #define _UL_UNIQID_H
26
27 #include "ul_gavl.h"
28
29
30 typedef unsigned long ul_uniqid_t;
31
32 typedef struct ul_uniqid_range_t {
33   ul_uniqid_t first;
34   ul_uniqid_t last;
35 } ul_uniqid_range_t;
36
37 /**
38  * struct ul_uniqid_pool_t - The Unique Identifiers Pool
39  * @items:      GAVL tree of not allocated yet ranges
40  * @range:      numeric range to allocate IDs from
41  *
42  * The unique pool provides functions to manage unique numerical IDs.
43  * The pool is first initialized by function ul_uniqid_pool_init().
44  * The available range is specified at this time. The pool can be
45  * flushed and destroyed by call ul_uniqid_pool_done().
46  *
47  * The function ul_uniqid_pool_alloc_one() returns first free ID from
48  * range. The ID is returned to the pool by function ul_uniqid_pool_free_one().
49  * There are even functions to reserve and release specific IDs range.
50  */
51 typedef struct ul_uniqid_pool_t {
52   gavl_fles_int_root_field_t items;
53   ul_uniqid_range_t range;
54 } ul_uniqid_pool_t;
55
56 int ul_uniqid_pool_init(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last);
57 int ul_uniqid_pool_done(ul_uniqid_pool_t *pool);
58 int ul_uniqid_pool_reserve(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last);
59 int ul_uniqid_pool_release(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last);
60 int ul_uniqid_pool_alloc_one(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid);
61 int ul_uniqid_pool_alloc_one_after(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid, ul_uniqid_t afterid);
62 int ul_uniqid_pool_free_one(ul_uniqid_pool_t *pool, ul_uniqid_t id);
63
64
65 #endif /*_UL_UNIQID_H*/