root / tags / 1.0.8 / xapian-core / backends / flint / flint_btreeutil.h

Revision 10643, 2.2 kB (checked in by olly, 8 months ago)

Backport change from trunk:
backends/flint/flint_btreeutil.h: Fix some out-of-date comments.
configure.ac: Use AC_CHECK_SIZEOF to define SIZEOF_INT and
SIZEOF_LONG.
backends/flint/flint_types.h: Use SIZEOF_INT and SIZEOF_LONG to
determine the type of uint4 rather than always using unsigned long
(which is 64 bits on most 64 bit Unix platforms). Drop int4 for
the time being, as we don't actually use it.
backends/quartz/quartz_types.h: Adapt flint change for quartz
(required to avoid differing uint4 types which clash in
backends/database.cc).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* flint_btreeutil.h: common macros/functions in the Btree implementation.
2 *
3 * Copyright 1999,2000,2001 BrightStation PLC
4 * Copyright 2002,2004,2008 Olly Betts
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19 * USA
20 */
21
22#ifndef OM_HGUARD_FLINT_BTREEUTIL_H
23#define OM_HGUARD_FLINT_BTREEUTIL_H
24
25#include "flint_types.h"
26#include "omassert.h"
27
28#include <string.h>  /* memset */
29
30/* The unit of access into the DB files is an unsigned char, which is defined
31   as 'byte' with a typedef in flint_types.h.
32
33   Other integer values are built up from these bytes, either in pairs or fours.
34   The code here currently assumes that int is at least a 32-bit type.
35*/
36
37// FIXME: 65536 in Asserts below should really be block_size
38inline int
39getint1(const byte *p, int c)
40{
41    Assert(c >= 0);
42    Assert(c < 65536);
43    return p[c];
44}
45
46inline void
47setint1(byte *p, int c, int x)
48{
49    Assert(c >= 0);
50    Assert(c < 65536);
51    p[c] = x;
52}
53
54inline int
55getint2(const byte *p, int c)
56{
57    Assert(c >= 0);
58    Assert(c < 65536 - 1);
59    return p[c] << 8 | p[c + 1];
60}
61
62inline void
63setint2(byte *p, int c, int x)
64{
65    Assert(c >= 0);
66    Assert(c < 65536 - 1);
67    p[c] = x >> 8;
68    p[c + 1] = x;
69}
70
71inline int
72getint4(const byte *p, int c)
73{
74    Assert(c >= 0);
75    Assert(c < 65536 - 3);
76    return p[c] << 24 | p[c + 1] << 16 | p[c + 2] << 8 | p[c + 3];
77}
78
79inline void
80setint4(byte *p, int c, int x)
81{
82    Assert(c >= 0);
83    Assert(c < 65536 - 3);
84    p[c] = x >> 24;
85    p[c + 1] = x >> 16;
86    p[c + 2] = x >> 8;
87    p[c + 3] = x;
88}
89
90#endif /* OM_HGUARD_FLINT_BTREEUTIL_H */
Note: See TracBrowser for help on using the browser.