File: flint_btreeutil.h

package info (click to toggle)
xapian-core 1.0.7-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 13,940 kB
  • ctags: 13,203
  • sloc: cpp: 69,340; sh: 9,355; ansic: 7,251; perl: 782; makefile: 471
file content (90 lines) | stat: -rw-r--r-- 2,235 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* flint_btreeutil.h: common macros/functions in the Btree implementation.
 *
 * Copyright 1999,2000,2001 BrightStation PLC
 * Copyright 2002,2004,2008 Olly Betts
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#ifndef OM_HGUARD_FLINT_BTREEUTIL_H
#define OM_HGUARD_FLINT_BTREEUTIL_H

#include "flint_types.h"
#include "omassert.h"

#include <string.h>  /* memset */

/* The unit of access into the DB files is an unsigned char, which is defined
   as 'byte' with a typedef in flint_types.h.

   Other integer values are built up from these bytes, either in pairs or fours.
   The code here currently assumes that int is at least a 32-bit type.
*/

// FIXME: 65536 in Asserts below should really be block_size
inline int
getint1(const byte *p, int c)
{
    Assert(c >= 0);
    Assert(c < 65536);
    return p[c];
}

inline void
setint1(byte *p, int c, int x)
{
    Assert(c >= 0);
    Assert(c < 65536);
    p[c] = x;
}

inline int
getint2(const byte *p, int c)
{
    Assert(c >= 0);
    Assert(c < 65536 - 1);
    return p[c] << 8 | p[c + 1];
}

inline void
setint2(byte *p, int c, int x)
{
    Assert(c >= 0);
    Assert(c < 65536 - 1);
    p[c] = x >> 8;
    p[c + 1] = x;
}

inline int
getint4(const byte *p, int c)
{
    Assert(c >= 0);
    Assert(c < 65536 - 3);
    return p[c] << 24 | p[c + 1] << 16 | p[c + 2] << 8 | p[c + 3];
}

inline void
setint4(byte *p, int c, int x)
{
    Assert(c >= 0);
    Assert(c < 65536 - 3);
    p[c] = x >> 24;
    p[c + 1] = x >> 16;
    p[c + 2] = x >> 8;
    p[c + 3] = x;
}

#endif /* OM_HGUARD_FLINT_BTREEUTIL_H */