Last change
on this file since 1687 was
686,
checked in by sam, 10 years ago
|
Put everything in the "lol" namespace. Better late than never.
|
-
Property svn:keywords set to
Id
|
File size:
1.2 KB
|
Line | |
---|
1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include "core.h" |
---|
16 | |
---|
17 | namespace lol |
---|
18 | { |
---|
19 | |
---|
20 | /* |
---|
21 | * Hash implementation class |
---|
22 | */ |
---|
23 | |
---|
24 | static class HashData |
---|
25 | { |
---|
26 | friend class Hash; |
---|
27 | |
---|
28 | public: |
---|
29 | HashData() |
---|
30 | { |
---|
31 | /* Initialise CRC32 table */ |
---|
32 | for (int i = 0; i < 256; i++) |
---|
33 | { |
---|
34 | uint32_t tmp = i; |
---|
35 | for (int j = 8; j--; ) |
---|
36 | tmp = (tmp >> 1) ^ ((tmp & 1) ? 0xedb88320 : 0); |
---|
37 | crc32_table[i] = tmp; |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | private: |
---|
42 | uint32_t crc32_table[256]; |
---|
43 | } |
---|
44 | hashdata; |
---|
45 | |
---|
46 | static HashData * const data = &hashdata; |
---|
47 | |
---|
48 | /* |
---|
49 | * Public Hash class |
---|
50 | */ |
---|
51 | |
---|
52 | uint32_t Hash::Crc32(char const *str) |
---|
53 | { |
---|
54 | uint32_t ret = 0xffffffff, ch; |
---|
55 | |
---|
56 | while ((ch = (uint8_t)*str++)) |
---|
57 | ret = data->crc32_table[(uint8_t)(ret ^ ch)] ^ (ret >> 8); |
---|
58 | |
---|
59 | return ret ^ 0xffffffff; |
---|
60 | } |
---|
61 | |
---|
62 | } /* namespace lol */ |
---|
63 | |
---|
Note: See
TracBrowser
for help on using the repository browser.