backends/flint/flint_btreeutil.h

Go to the documentation of this file.
00001 /* flint_btreeutil.h: common macros/functions in the Btree implementation.
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002,2004,2008 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00019  * USA
00020  */
00021 
00022 #ifndef OM_HGUARD_FLINT_BTREEUTIL_H
00023 #define OM_HGUARD_FLINT_BTREEUTIL_H
00024 
00025 #include "flint_types.h"
00026 #include "omassert.h"
00027 
00028 #include <string.h>  /* memset */
00029 
00030 /* The unit of access into the DB files is an unsigned char, which is defined
00031    as 'byte' with a typedef in flint_types.h.
00032 
00033    Other integer values are built up from these bytes, either in pairs or fours.
00034    The code here currently assumes that int is at least a 32-bit type.
00035 */
00036 
00037 // FIXME: 65536 in Asserts below should really be block_size
00038 inline int
00039 getint1(const byte *p, int c)
00040 {
00041     Assert(c >= 0);
00042     Assert(c < 65536);
00043     return p[c];
00044 }
00045 
00046 inline void
00047 setint1(byte *p, int c, int x)
00048 {
00049     Assert(c >= 0);
00050     Assert(c < 65536);
00051     p[c] = x;
00052 }
00053 
00054 inline int
00055 getint2(const byte *p, int c)
00056 {
00057     Assert(c >= 0);
00058     Assert(c < 65536 - 1);
00059     return p[c] << 8 | p[c + 1];
00060 }
00061 
00062 inline void
00063 setint2(byte *p, int c, int x)
00064 {
00065     Assert(c >= 0);
00066     Assert(c < 65536 - 1);
00067     p[c] = x >> 8;
00068     p[c + 1] = x;
00069 }
00070 
00071 inline int
00072 getint4(const byte *p, int c)
00073 {
00074     Assert(c >= 0);
00075     Assert(c < 65536 - 3);
00076     return p[c] << 24 | p[c + 1] << 16 | p[c + 2] << 8 | p[c + 3];
00077 }
00078 
00079 inline void
00080 setint4(byte *p, int c, int x)
00081 {
00082     Assert(c >= 0);
00083     Assert(c < 65536 - 3);
00084     p[c] = x >> 24;
00085     p[c + 1] = x >> 16;
00086     p[c + 2] = x >> 8;
00087     p[c + 3] = x;
00088 }
00089 
00090 #endif /* OM_HGUARD_FLINT_BTREEUTIL_H */

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.