xref: /original-bsd/lib/libc/db/hash/page.h (revision c3e32dec)
1 /*-
2  * Copyright (c) 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Margo Seltzer.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)page.h	8.1 (Berkeley) 06/06/93
11  */
12 
13 /*
14  * Definitions for hashing page file format.
15  */
16 
17 /*
18  * routines dealing with a data page
19  *
20  * page format:
21  *	+------------------------------+
22  * p	| n | keyoff | datoff | keyoff |
23  * 	+------------+--------+--------+
24  *	| datoff | free  |  ptr  | --> |
25  *	+--------+---------------------+
26  *	|	 F R E E A R E A       |
27  *	+--------------+---------------+
28  *	|  <---- - - - | data          |
29  *	+--------+-----+----+----------+
30  *	|  key   | data     | key      |
31  *	+--------+----------+----------+
32  *
33  * Pointer to the free space is always:  p[p[0] + 2]
34  * Amount of free space on the page is:  p[p[0] + 1]
35  */
36 
37 /*
38  * How many bytes required for this pair?
39  *	2 shorts in the table at the top of the page + room for the
40  *	key and room for the data
41  *
42  * We prohibit entering a pair on a page unless there is also room to append
43  * an overflow page. The reason for this it that you can get in a situation
44  * where a single key/data pair fits on a page, but you can't append an
45  * overflow page and later you'd have to split the key/data and handle like
46  * a big pair.
47  * You might as well do this up front.
48  */
49 
50 #define	PAIRSIZE(K,D)	(2*sizeof(u_short) + (K)->size + (D)->size)
51 #define BIGOVERHEAD	(4*sizeof(u_short))
52 #define KEYSIZE(K)	(4*sizeof(u_short) + (K)->size);
53 #define OVFLSIZE	(2*sizeof(u_short))
54 #define FREESPACE(P)	((P)[(P)[0]+1])
55 #define	OFFSET(P)	((P)[(P)[0]+2])
56 #define PAIRFITS(P,K,D) \
57 	(((P)[2] >= REAL_KEY) && \
58 	    (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P)))
59 #define PAGE_META(N)	(((N)+3) * sizeof(u_short))
60 
61 typedef struct {
62 	BUFHEAD *newp;
63 	BUFHEAD *oldp;
64 	BUFHEAD *nextp;
65 	u_short next_addr;
66 }       SPLIT_RETURN;
67