MDB
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
midl.h
Go to the documentation of this file.
1 
11 /* $OpenLDAP$ */
12 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
13  *
14  * Copyright 2000-2013 The OpenLDAP Foundation.
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted only as authorized by the OpenLDAP
19  * Public License.
20  *
21  * A copy of this license is available in the file LICENSE in the
22  * top-level directory of the distribution or, alternatively, at
23  * <http://www.OpenLDAP.org/license.html>.
24  */
25 
26 #ifndef _MDB_MIDL_H_
27 #define _MDB_MIDL_H_
28 
29 #include <stddef.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
45 typedef size_t MDB_ID;
46 
53 typedef MDB_ID *MDB_IDL;
54 
55 /* IDL sizes - likely should be even bigger
56  * limiting factors: sizeof(ID), thread stack size
57  */
58 #define MDB_IDL_LOGN 16 /* DB_SIZE is 2^16, UM_SIZE is 2^17 */
59 #define MDB_IDL_DB_SIZE (1<<MDB_IDL_LOGN)
60 #define MDB_IDL_UM_SIZE (1<<(MDB_IDL_LOGN+1))
61 
62 #define MDB_IDL_DB_MAX (MDB_IDL_DB_SIZE-1)
63 #define MDB_IDL_UM_MAX (MDB_IDL_UM_SIZE-1)
64 
65 #define MDB_IDL_SIZEOF(ids) (((ids)[0]+1) * sizeof(MDB_ID))
66 #define MDB_IDL_IS_ZERO(ids) ( (ids)[0] == 0 )
67 #define MDB_IDL_CPY( dst, src ) (memcpy( dst, src, MDB_IDL_SIZEOF( src ) ))
68 #define MDB_IDL_FIRST( ids ) ( (ids)[1] )
69 #define MDB_IDL_LAST( ids ) ( (ids)[(ids)[0]] )
70 
72 #define mdb_midl_xappend(idl, id) do { \
73  MDB_ID *xidl = (idl), xlen = ++(xidl[0]); \
74  xidl[xlen] = (id); \
75  } while (0)
76 
82 unsigned mdb_midl_search( MDB_IDL ids, MDB_ID id );
83 
88 MDB_IDL mdb_midl_alloc(int num);
89 
93 void mdb_midl_free(MDB_IDL ids);
94 
100 int mdb_midl_shrink(MDB_IDL *idp);
101 
107 int mdb_midl_need(MDB_IDL *idp, unsigned num);
108 
114 int mdb_midl_append( MDB_IDL *idp, MDB_ID id );
115 
121 int mdb_midl_append_list( MDB_IDL *idp, MDB_IDL app );
122 
129 int mdb_midl_append_range( MDB_IDL *idp, MDB_ID id, unsigned n );
130 
134 void mdb_midl_sort( MDB_IDL ids );
135 
138 typedef struct MDB_ID2 {
139  MDB_ID mid;
140  void *mptr;
141 } MDB_ID2;
142 
148 typedef MDB_ID2 *MDB_ID2L;
149 
155 unsigned mdb_mid2l_search( MDB_ID2L ids, MDB_ID id );
156 
157 
163 int mdb_mid2l_insert( MDB_ID2L ids, MDB_ID2 *id );
164 
170 int mdb_mid2l_append( MDB_ID2L ids, MDB_ID2 *id );
171 
174 #ifdef __cplusplus
175 }
176 #endif
177 #endif /* _MDB_MIDL_H_ */
MDB_ID2 * MDB_ID2L
Definition: midl.h:148
void * mptr
Definition: midl.h:140
size_t MDB_ID
Definition: midl.h:45
int mdb_mid2l_append(MDB_ID2L ids, MDB_ID2 *id)
Definition: midl.c:334
int mdb_midl_shrink(MDB_IDL *idp)
Definition: midl.c:119
unsigned mdb_midl_search(MDB_IDL ids, MDB_ID id)
Definition: midl.c:33
Definition: midl.h:138
int mdb_midl_append_list(MDB_IDL *idp, MDB_IDL app)
Definition: midl.c:172
unsigned mdb_mid2l_search(MDB_ID2L ids, MDB_ID id)
Definition: midl.c:268
int mdb_mid2l_insert(MDB_ID2L ids, MDB_ID2 *id)
Definition: midl.c:303
MDB_IDL mdb_midl_alloc(int num)
Definition: midl.c:103
MDB_ID mid
Definition: midl.h:139
MDB_ID * MDB_IDL
Definition: midl.h:53
void mdb_midl_free(MDB_IDL ids)
Definition: midl.c:113
int mdb_midl_append_range(MDB_IDL *idp, MDB_ID id, unsigned n)
Definition: midl.c:186
void mdb_midl_sort(MDB_IDL ids)
Definition: midl.c:208
int mdb_midl_need(MDB_IDL *idp, unsigned num)
Definition: midl.c:144
int mdb_midl_append(MDB_IDL *idp, MDB_ID id)
Definition: midl.c:158