]> git.sur5r.net Git - openldap/blob - libraries/liblmdb/midl.h
Drop unused liblmdb MIDL-range support.
[openldap] / libraries / liblmdb / midl.h
1 /**     @file midl.h
2  *      @brief mdb ID List header file.
3  *
4  *      This file was originally part of back-bdb but has been
5  *      modified for use in libmdb. Most of the macros defined
6  *      in this file are unused, just left over from the original.
7  *
8  *      This file is only used internally in libmdb and its definitions
9  *      are not exposed publicly.
10  */
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
35 /** @defgroup internal  MDB Internals
36  *      @{
37  */
38
39 /** @defgroup idls      ID List Management
40  *      @{
41  */
42         /** A generic ID number. These were entryIDs in back-bdb.
43          *      Preferably it should have the same size as a pointer.
44          */
45 typedef size_t MDB_ID;
46
47         /** An IDL is an ID List, a sorted array of IDs. The first
48          * element of the array is a counter for how many actual
49          * IDs are in the list. In the original back-bdb code, IDLs are
50          * sorted in ascending order. For libmdb IDLs are sorted in
51          * descending order.
52          */
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
71 #if 0   /* superseded by append/sort */
72         /** Insert an ID into an IDL.
73          * @param[in,out] ids   The IDL to insert into.
74          * @param[in] id        The ID to insert.
75          * @return      0 on success, -1 if ID was already present, -2 on error.
76          */
77 int mdb_midl_insert( MDB_IDL ids, MDB_ID id );
78 #endif
79
80         /** Allocate an IDL.
81          * Allocates memory for an IDL of the given size.
82          * @return      IDL on success, NULL on failure.
83          */
84 MDB_IDL mdb_midl_alloc(int num);
85
86         /** Free an IDL.
87          * @param[in] ids       The IDL to free.
88          */
89 void mdb_midl_free(MDB_IDL ids);
90
91         /** Shrink an IDL.
92          * Return the IDL to the default size if it has grown larger.
93          * @param[in,out] idp   Address of the IDL to shrink.
94          * @return      0 on no change, non-zero if shrunk.
95          */
96 int mdb_midl_shrink(MDB_IDL *idp);
97
98         /** Grow an IDL.
99          * Add room for num additional elements.
100          * @param[in,out] idp   Address of the IDL to grow.
101          * @param[in] num       Number of elements to add.
102          * @return      0 on success, -1 on failure.
103          */
104 int mdb_midl_grow(MDB_IDL *idp, int num);
105
106         /** Append an ID onto an IDL.
107          * @param[in,out] idp   Address of the IDL to append to.
108          * @param[in] id        The ID to append.
109          * @return      0 on success, -1 if the IDL is too large.
110          */
111 int mdb_midl_append( MDB_IDL *idp, MDB_ID id );
112
113         /** Append an IDL onto an IDL.
114          * @param[in,out] idp   Address of the IDL to append to.
115          * @param[in] app       The IDL to append.
116          * @return      0 on success, -1 if the IDL is too large.
117          */
118 int mdb_midl_append_list( MDB_IDL *idp, MDB_IDL app );
119
120         /** Sort an IDL.
121          * @param[in,out] ids   The IDL to sort.
122          */
123 void mdb_midl_sort( MDB_IDL ids );
124
125         /** An ID2 is an ID/pointer pair.
126          */
127 typedef struct MDB_ID2 {
128         MDB_ID mid;             /**< The ID */
129         void *mptr;             /**< The pointer */
130 } MDB_ID2;
131
132         /** An ID2L is an ID2 List, a sorted array of ID2s.
133          * The first element's \b mid member is a count of how many actual
134          * elements are in the array. The \b mptr member of the first element is unused.
135          * The array is sorted in ascending order by \b mid.
136          */
137 typedef MDB_ID2 *MDB_ID2L;
138
139         /** Search for an ID in an ID2L.
140          * @param[in] ids       The ID2L to search.
141          * @param[in] id        The ID to search for.
142          * @return      The index of the first ID2 whose \b mid member is greater than or equal to \b id.
143          */
144 unsigned mdb_mid2l_search( MDB_ID2L ids, MDB_ID id );
145
146
147         /** Insert an ID2 into a ID2L.
148          * @param[in,out] ids   The ID2L to insert into.
149          * @param[in] id        The ID2 to insert.
150          * @return      0 on success, -1 if the ID was already present in the ID2L.
151          */
152 int mdb_mid2l_insert( MDB_ID2L ids, MDB_ID2 *id );
153
154         /** Append an ID2 into a ID2L.
155          * @param[in,out] ids   The ID2L to append into.
156          * @param[in] id        The ID2 to append.
157          * @return      0 on success, -2 if the ID2L is too big.
158          */
159 int mdb_mid2l_append( MDB_ID2L ids, MDB_ID2 *id );
160
161 /** @} */
162 /** @} */
163 #ifdef __cplusplus
164 }
165 #endif
166 #endif  /* _MDB_MIDL_H_ */