LMDB
 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-2015 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_IDL_ALLOCLEN( ids ) ( (ids)[-1] )
73 
75 #define mdb_midl_xappend(idl, id) do { \
76  MDB_ID *xidl = (idl), xlen = ++(xidl[0]); \
77  xidl[xlen] = (id); \
78  } while (0)
79 
85 unsigned mdb_midl_search( MDB_IDL ids, MDB_ID id );
86 
91 MDB_IDL mdb_midl_alloc(int num);
92 
96 void mdb_midl_free(MDB_IDL ids);
97 
102 void mdb_midl_shrink(MDB_IDL *idp);
103 
109 int mdb_midl_need(MDB_IDL *idp, unsigned num);
110 
116 int mdb_midl_append( MDB_IDL *idp, MDB_ID id );
117 
123 int mdb_midl_append_list( MDB_IDL *idp, MDB_IDL app );
124 
131 int mdb_midl_append_range( MDB_IDL *idp, MDB_ID id, unsigned n );
132 
137 void mdb_midl_xmerge( MDB_IDL idl, MDB_IDL merge );
138 
142 void mdb_midl_sort( MDB_IDL ids );
143 
146 typedef struct MDB_ID2 {
147  MDB_ID mid;
148  void *mptr;
149 } MDB_ID2;
150 
156 typedef MDB_ID2 *MDB_ID2L;
157 
163 unsigned mdb_mid2l_search( MDB_ID2L ids, MDB_ID id );
164 
165 
171 int mdb_mid2l_insert( MDB_ID2L ids, MDB_ID2 *id );
172 
178 int mdb_mid2l_append( MDB_ID2L ids, MDB_ID2 *id );
179 
182 #ifdef __cplusplus
183 }
184 #endif
185 #endif /* _MDB_MIDL_H_ */