Back to index

openldap  2.4.31
midl.h
Go to the documentation of this file.
00001 
00011 /* $OpenLDAP$ */
00012 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00013  *
00014  * Copyright 2000-2012 The OpenLDAP Foundation.
00015  * All rights reserved.
00016  *
00017  * Redistribution and use in source and binary forms, with or without
00018  * modification, are permitted only as authorized by the OpenLDAP
00019  * Public License.
00020  *
00021  * A copy of this license is available in the file LICENSE in the
00022  * top-level directory of the distribution or, alternatively, at
00023  * <http://www.OpenLDAP.org/license.html>.
00024  */
00025 
00026 #ifndef _MDB_MIDL_H_
00027 #define _MDB_MIDL_H_
00028 
00029 #include <stddef.h>
00030 
00041 typedef size_t ID;
00042 
00049 typedef ID *IDL;
00050 
00051 #define       NOID   (~(ID)0)
00052 
00053 /* IDL sizes - likely should be even bigger
00054  *   limiting factors: sizeof(ID), thread stack size
00055  */
00056 #define       MDB_IDL_LOGN  16     /* DB_SIZE is 2^16, UM_SIZE is 2^17 */
00057 #define MDB_IDL_DB_SIZE            (1<<MDB_IDL_LOGN)
00058 #define MDB_IDL_UM_SIZE            (1<<(MDB_IDL_LOGN+1))
00059 #define MDB_IDL_UM_SIZEOF   (MDB_IDL_UM_SIZE * sizeof(ID))
00060 
00061 #define MDB_IDL_DB_MAX             (MDB_IDL_DB_SIZE-1)
00062 
00063 #define MDB_IDL_UM_MAX             (MDB_IDL_UM_SIZE-1)
00064 
00065 #define MDB_IDL_IS_RANGE(ids)      ((ids)[0] == NOID)
00066 #define MDB_IDL_RANGE_SIZE         (3)
00067 #define MDB_IDL_RANGE_SIZEOF       (MDB_IDL_RANGE_SIZE * sizeof(ID))
00068 #define MDB_IDL_SIZEOF(ids)        ((MDB_IDL_IS_RANGE(ids) \
00069        ? MDB_IDL_RANGE_SIZE : ((ids)[0]+1)) * sizeof(ID))
00070 
00071 #define MDB_IDL_RANGE_FIRST(ids)   ((ids)[1])
00072 #define MDB_IDL_RANGE_LAST(ids)           ((ids)[2])
00073 
00074 #define MDB_IDL_RANGE( ids, f, l ) \
00075        do { \
00076               (ids)[0] = NOID; \
00077               (ids)[1] = (f);  \
00078               (ids)[2] = (l);  \
00079        } while(0)
00080 
00081 #define MDB_IDL_ZERO(ids) \
00082        do { \
00083               (ids)[0] = 0; \
00084               (ids)[1] = 0; \
00085               (ids)[2] = 0; \
00086        } while(0)
00087 
00088 #define MDB_IDL_IS_ZERO(ids) ( (ids)[0] == 0 )
00089 #define MDB_IDL_IS_ALL( range, ids ) ( (ids)[0] == NOID \
00090        && (ids)[1] <= (range)[1] && (range)[2] <= (ids)[2] )
00091 
00092 #define MDB_IDL_CPY( dst, src ) (memcpy( dst, src, MDB_IDL_SIZEOF( src ) ))
00093 
00094 #define MDB_IDL_ID( bdb, ids, id ) MDB_IDL_RANGE( ids, id, ((bdb)->bi_lastid) )
00095 #define MDB_IDL_ALL( bdb, ids ) MDB_IDL_RANGE( ids, 1, ((bdb)->bi_lastid) )
00096 
00097 #define MDB_IDL_FIRST( ids )       ( (ids)[1] )
00098 #define MDB_IDL_LAST( ids )        ( MDB_IDL_IS_RANGE(ids) \
00099        ? (ids)[2] : (ids)[(ids)[0]] )
00100 
00101 #define MDB_IDL_N( ids )           ( MDB_IDL_IS_RANGE(ids) \
00102        ? ((ids)[2]-(ids)[1])+1 : (ids)[0] )
00103 
00104 #if 0  /* superseded by append/sort */
00105 
00110 int mdb_midl_insert( IDL ids, ID id );
00111 #endif
00112 
00117 IDL mdb_midl_alloc();
00118 
00122 void mdb_midl_free(IDL ids);
00123 
00129 int mdb_midl_shrink(IDL *idp);
00130 
00136 int mdb_midl_append( IDL *idp, ID id );
00137 
00143 int mdb_midl_append_list( IDL *idp, IDL app );
00144 
00148 void mdb_midl_sort( IDL ids );
00149 
00152 typedef struct ID2 {
00153        ID mid;                     
00154        void *mptr;          
00155 } ID2;
00156 
00162 typedef ID2 *ID2L;
00163 
00169 unsigned mdb_mid2l_search( ID2L ids, ID id );
00170 
00171 
00177 int mdb_mid2l_insert( ID2L ids, ID2 *id );
00178 
00181 #endif /* _MDB_MIDL_H_ */