]> git.sur5r.net Git - openldap/blob - libraries/libmdb/midl.h
31a4b67bd2ce4907f33a3b8451e4f1b061f8c304
[openldap] / libraries / libmdb / midl.h
1 /* idl.h - ldap bdb back-end ID list header file */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2011 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #ifndef _MDB_MIDL_H_
18 #define _MDB_MIDL_H_
19
20 #define ID      unsigned long
21 #define NOID    ((ID)~0)
22
23 /* IDL sizes - likely should be even bigger
24  *   limiting factors: sizeof(ID), thread stack size
25  */
26 #define MDB_IDL_LOGN    16      /* DB_SIZE is 2^16, UM_SIZE is 2^17 */
27 #define MDB_IDL_DB_SIZE         (1<<MDB_IDL_LOGN)
28 #define MDB_IDL_UM_SIZE         (1<<(MDB_IDL_LOGN+1))
29 #define MDB_IDL_UM_SIZEOF       (MDB_IDL_UM_SIZE * sizeof(ID))
30
31 #define MDB_IDL_DB_MAX          (MDB_IDL_DB_SIZE-1)
32
33 #define MDB_IDL_UM_MAX          (MDB_IDL_UM_SIZE-1)
34
35 #define MDB_IDL_IS_RANGE(ids)   ((ids)[0] == NOID)
36 #define MDB_IDL_RANGE_SIZE              (3)
37 #define MDB_IDL_RANGE_SIZEOF    (MDB_IDL_RANGE_SIZE * sizeof(ID))
38 #define MDB_IDL_SIZEOF(ids)             ((MDB_IDL_IS_RANGE(ids) \
39         ? MDB_IDL_RANGE_SIZE : ((ids)[0]+1)) * sizeof(ID))
40
41 #define MDB_IDL_RANGE_FIRST(ids)        ((ids)[1])
42 #define MDB_IDL_RANGE_LAST(ids)         ((ids)[2])
43
44 #define MDB_IDL_RANGE( ids, f, l ) \
45         do { \
46                 (ids)[0] = NOID; \
47                 (ids)[1] = (f);  \
48                 (ids)[2] = (l);  \
49         } while(0)
50
51 #define MDB_IDL_ZERO(ids) \
52         do { \
53                 (ids)[0] = 0; \
54                 (ids)[1] = 0; \
55                 (ids)[2] = 0; \
56         } while(0)
57
58 #define MDB_IDL_IS_ZERO(ids) ( (ids)[0] == 0 )
59 #define MDB_IDL_IS_ALL( range, ids ) ( (ids)[0] == NOID \
60         && (ids)[1] <= (range)[1] && (range)[2] <= (ids)[2] )
61
62 #define MDB_IDL_CPY( dst, src ) (memcpy( dst, src, MDB_IDL_SIZEOF( src ) ))
63
64 #define MDB_IDL_ID( bdb, ids, id ) MDB_IDL_RANGE( ids, id, ((bdb)->bi_lastid) )
65 #define MDB_IDL_ALL( bdb, ids ) MDB_IDL_RANGE( ids, 1, ((bdb)->bi_lastid) )
66
67 #define MDB_IDL_FIRST( ids )    ( ids[1] )
68 #define MDB_IDL_LAST( ids )             ( MDB_IDL_IS_RANGE(ids) \
69         ? ids[2] : ids[ids[0]] )
70
71 #define MDB_IDL_N( ids )                ( MDB_IDL_IS_RANGE(ids) \
72         ? (ids[2]-ids[1])+1 : ids[0] )
73
74 int mdb_midl_insert( ID *ids, ID id );
75
76 typedef struct MIDL2 {
77         ID mid;
78         void *mptr;
79 } MIDL2;
80
81 unsigned mdb_midl2_search( MIDL2 *ids, MIDL2 *id );
82 int mdb_midl2_insert( MIDL2 *ids, MIDL2 *id );
83
84 #endif  /* _MDB_MIDL_H_ */