1 /*******************************************************************
2 uLan Utilities Library - C library of basic reusable constructions
4 ul_uniqid.h - unique ID generator
6 (C) Copyright 2003-2004 by Pavel Pisa - Originator
8 The uLan utilities library can be used, copied and modified under
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.
20 See files COPYING and README for details.
22 *******************************************************************/
33 typedef unsigned long ul_uniqid_t;
35 typedef struct ul_uniqid_range_t {
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
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().
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.
54 typedef struct ul_uniqid_pool_t {
55 gavl_fles_int_root_field_t items;
56 ul_uniqid_range_t range;
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);
71 #endif /*_UL_UNIQID_H*/