]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_uniqid.h
ulut: global hash tables size-step table variables have to be declared as extern.
[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 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 typedef unsigned long ul_uniqid_t;
34
35 typedef struct ul_uniqid_range_t {
36   ul_uniqid_t first;
37   ul_uniqid_t last;
38 } ul_uniqid_range_t;
39
40 /**
41  * struct ul_uniqid_pool_t - The Unique Identifiers Pool
42  * @items:      GAVL tree of not allocated yet ranges
43  * @range:      numeric range to allocate IDs from
44  *
45  * The unique pool provides functions to manage unique numerical IDs.
46  * The pool is first initialized by function ul_uniqid_pool_init().
47  * The available range is specified at this time. The pool can be
48  * flushed and destroyed by call ul_uniqid_pool_done().
49  *
50  * The function ul_uniqid_pool_alloc_one() returns first free ID from
51  * range. The ID is returned to the pool by function ul_uniqid_pool_free_one().
52  * There are even functions to reserve and release specific IDs range.
53  */
54 typedef struct ul_uniqid_pool_t {
55   gavl_fles_int_root_field_t items;
56   ul_uniqid_range_t range;
57 } ul_uniqid_pool_t;
58
59 int ul_uniqid_pool_init(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last);
60 int ul_uniqid_pool_done(ul_uniqid_pool_t *pool);
61 int ul_uniqid_pool_reserve(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last);
62 int ul_uniqid_pool_release(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last);
63 int ul_uniqid_pool_alloc_one(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid);
64 int ul_uniqid_pool_alloc_one_after(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid, ul_uniqid_t afterid);
65 int ul_uniqid_pool_free_one(ul_uniqid_pool_t *pool, ul_uniqid_t id);
66
67 #ifdef __cplusplus
68 } /* extern "C"*/
69 #endif
70
71 #endif /*_UL_UNIQID_H*/