Back to index

lightning-sunbird  0.9+nobinonly
page.h
Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1990, 1993, 1994
00003  *     The Regents of the University of California.  All rights reserved.
00004  *
00005  * This code is derived from software contributed to Berkeley by
00006  * Margo Seltzer.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. ***REMOVED*** - see 
00017  *    ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
00018  * 4. Neither the name of the University nor the names of its contributors
00019  *    may be used to endorse or promote products derived from this software
00020  *    without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  *     @(#)page.h    8.2 (Berkeley) 5/31/94
00035  */
00036 
00037 /*
00038  * Definitions for hashing page file format.
00039  */
00040 
00041 /*
00042  * routines dealing with a data page
00043  *
00044  * page format:
00045  *     +------------------------------+
00046  * p   | n | keyoff | datoff | keyoff |
00047  *     +------------+--------+--------+
00048  *     | datoff | free  |  ptr  | --> |
00049  *     +--------+---------------------+
00050  *     |       F R E E A R E A       |
00051  *     +--------------+---------------+
00052  *     |  <---- - - - | data          |
00053  *     +--------+-----+----+----------+
00054  *     |  key   | data     | key      |
00055  *     +--------+----------+----------+
00056  *
00057  * Pointer to the free space is always:  p[p[0] + 2]
00058  * Amount of free space on the page is:  p[p[0] + 1]
00059  */
00060 
00061 /*
00062  * How many bytes required for this pair?
00063  *     2 shorts in the table at the top of the page + room for the
00064  *     key and room for the data
00065  *
00066  * We prohibit entering a pair on a page unless there is also room to append
00067  * an overflow page. The reason for this it that you can get in a situation
00068  * where a single key/data pair fits on a page, but you can't append an
00069  * overflow page and later you'd have to split the key/data and handle like
00070  * a big pair.
00071  * You might as well do this up front.
00072  */
00073 #ifndef PAGE_H
00074 #define PAGE_H
00075 
00076 #define       PAIRSIZE(K,D) (2*sizeof(uint16) + (K)->size + (D)->size)
00077 #define BIGOVERHEAD  (4*sizeof(uint16))
00078 #define KEYSIZE(K)   (4*sizeof(uint16) + (K)->size);
00079 #define OVFLSIZE     (2*sizeof(uint16))
00080 #define FREESPACE(P) ((P)[(P)[0]+1])
00081 #define       OFFSET(P)     ((P)[(P)[0]+2])
00082 #define PAIRFITS(P,K,D) \
00083        (((P)[2] >= REAL_KEY) && \
00084            (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P)))
00085 #define PAGE_META(N) (((N)+3) * sizeof(uint16))
00086 
00087 typedef struct {
00088        BUFHEAD *newp;
00089        BUFHEAD *oldp;
00090        BUFHEAD *nextp;
00091        uint16 next_addr;
00092 }       SPLIT_RETURN;
00093 #endif
00094