1/*	$NetBSD$	*/
2
3/* idl.h - ldap bdb back-end ID list header file */
4/* OpenLDAP: pkg/ldap/servers/slapd/back-bdb/idl.h,v 1.19.2.5 2010/04/13 20:23:25 kurt Exp */
5/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2000-2010 The OpenLDAP Foundation.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
12 * Public License.
13 *
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
17 */
18
19#ifndef _BDB_IDL_H_
20#define _BDB_IDL_H_
21
22/* IDL sizes - likely should be even bigger
23 *   limiting factors: sizeof(ID), thread stack size
24 */
25#define	BDB_IDL_LOGN	16	/* DB_SIZE is 2^16, UM_SIZE is 2^17 */
26#define BDB_IDL_DB_SIZE		(1<<BDB_IDL_LOGN)
27#define BDB_IDL_UM_SIZE		(1<<(BDB_IDL_LOGN+1))
28#define BDB_IDL_UM_SIZEOF	(BDB_IDL_UM_SIZE * sizeof(ID))
29
30#define BDB_IDL_DB_MAX		(BDB_IDL_DB_SIZE-1)
31
32#define BDB_IDL_UM_MAX		(BDB_IDL_UM_SIZE-1)
33
34#define BDB_IDL_IS_RANGE(ids)	((ids)[0] == NOID)
35#define BDB_IDL_RANGE_SIZE		(3)
36#define BDB_IDL_RANGE_SIZEOF	(BDB_IDL_RANGE_SIZE * sizeof(ID))
37#define BDB_IDL_SIZEOF(ids)		((BDB_IDL_IS_RANGE(ids) \
38	? BDB_IDL_RANGE_SIZE : ((ids)[0]+1)) * sizeof(ID))
39
40#define BDB_IDL_RANGE_FIRST(ids)	((ids)[1])
41#define BDB_IDL_RANGE_LAST(ids)		((ids)[2])
42
43#define BDB_IDL_RANGE( ids, f, l ) \
44	do { \
45		(ids)[0] = NOID; \
46		(ids)[1] = (f);  \
47		(ids)[2] = (l);  \
48	} while(0)
49
50#define BDB_IDL_ZERO(ids) \
51	do { \
52		(ids)[0] = 0; \
53		(ids)[1] = 0; \
54		(ids)[2] = 0; \
55	} while(0)
56
57#define BDB_IDL_IS_ZERO(ids) ( (ids)[0] == 0 )
58#define BDB_IDL_IS_ALL( range, ids ) ( (ids)[0] == NOID \
59	&& (ids)[1] <= (range)[1] && (range)[2] <= (ids)[2] )
60
61#define BDB_IDL_CPY( dst, src ) (AC_MEMCPY( dst, src, BDB_IDL_SIZEOF( src ) ))
62
63#define BDB_IDL_ID( bdb, ids, id ) BDB_IDL_RANGE( ids, id, ((bdb)->bi_lastid) )
64#define BDB_IDL_ALL( bdb, ids ) BDB_IDL_RANGE( ids, 1, ((bdb)->bi_lastid) )
65
66#define BDB_IDL_FIRST( ids )	( ids[1] )
67#define BDB_IDL_LAST( ids )		( BDB_IDL_IS_RANGE(ids) \
68	? ids[2] : ids[ids[0]] )
69
70#define BDB_IDL_N( ids )		( BDB_IDL_IS_RANGE(ids) \
71	? (ids[2]-ids[1])+1 : ids[0] )
72
73LDAP_BEGIN_DECL
74LDAP_END_DECL
75
76#endif
77