|
2
|
1 |
/* $Id: internal.h 616 2005-08-19 20:11:01Z bruce $ */
|
|
0
|
2 |
// Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca>
|
|
|
3 |
//
|
|
|
4 |
// This program is free software; you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation; either version 2 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// This program is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with this program; if not, write to the Free Software
|
|
|
16 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
17 |
|
|
|
18 |
#ifndef CDBXX__INTERNAL__H__
|
|
|
19 |
#define CDBXX__INTERNAL__H__
|
|
|
20 |
|
|
|
21 |
#include "cdb++.h"
|
|
|
22 |
|
|
|
23 |
#define CDB_HASHSTART ((uint32) 5381)
|
|
|
24 |
|
|
|
25 |
inline void pack(unsigned char* buf, uint32 num)
|
|
|
26 |
{
|
|
|
27 |
*buf++ = num; num >>= 8;
|
|
|
28 |
*buf++ = num; num >>= 8;
|
|
|
29 |
*buf++ = num; num >>= 8;
|
|
|
30 |
*buf = num;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
inline uint32 unpack(const unsigned char* p)
|
|
|
34 |
{
|
|
|
35 |
return uint32(p[0]) |
|
|
|
36 |
uint32(p[1]) << 8 |
|
|
|
37 |
uint32(p[2]) << 16 |
|
|
|
38 |
uint32(p[3]) << 24;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
inline uint32 hash(const mystring& s)
|
|
|
42 |
{
|
|
|
43 |
uint32 h = CDB_HASHSTART;
|
|
|
44 |
const char* p = s.c_str();
|
|
|
45 |
for(unsigned len = s.length(); len > 0; len--)
|
|
|
46 |
h = ((h << 5) + h) ^ *p++;
|
|
|
47 |
return h;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
#endif
|