Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 74 lines (63 sloc) 2.008 kb
9aa22fe Offered permission to copy under gplv3 license.
cjdelisle authored
1 /*
2 * You may redistribute this program and/or modify it under the terms of
3 * the GNU General Public License as published by the Free Software Foundation,
4 * either version 3 of the License, or (at your option) any later version.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
547f4a3 Cleaned up a bunch of files, added a codestyle validator and some inf…
cjdelisle authored
14 #ifndef Bits_H
15 #define Bits_H
0689af8 Halfway through debugging...
cjdelisle authored
16
d6d5584 Changed metric to favor nodes with shortest path.
cjdelisle authored
17 #include "util/Endian.h"
18
0689af8 Halfway through debugging...
cjdelisle authored
19 #include <stdint.h>
0ae0048 improved key validation, made a distance based NodeCollector used for…
cjdelisle authored
20 #include <stdbool.h>
21 #include <string.h>
0689af8 Halfway through debugging...
cjdelisle authored
22
d6d5584 Changed metric to favor nodes with shortest path.
cjdelisle authored
23 static inline int Bits_log2x64(uint64_t number)
0689af8 Halfway through debugging...
cjdelisle authored
24 {
25 int out = 0;
26 while (number >>= 1) {
27 out++;
28 }
29 return out;
d6d5584 Changed metric to favor nodes with shortest path.
cjdelisle authored
30 }
31
32 static inline int Bits_log2x64_be(uint64_t number)
33 {
d43497c Fixed bug in Bits_log2x64_be() and minor cleanup
cjdelisle authored
34 return Bits_log2x64(Endian_bigEndianToHost64(number));
0689af8 Halfway through debugging...
cjdelisle authored
35 }
36
37 /**
38 * Bitwise reversal of the a number.
39 */
40 static inline uint64_t Bits_bitReverse64(uint64_t toReverse)
41 {
e14c2e5 debugging
cjdelisle authored
42 #define Bits_rotateAndMask(mask, rotateBits) \
43 toReverse = ((toReverse >> rotateBits) & mask) | ((toReverse & mask) << rotateBits)
44
45 Bits_rotateAndMask(0x5555555555555555ull, 1);
46 Bits_rotateAndMask(0x3333333333333333ull, 2);
47 Bits_rotateAndMask(0x0F0F0F0F0F0F0F0Full, 4);
48 Bits_rotateAndMask(0x00FF00FF00FF00FFull, 8);
49 Bits_rotateAndMask(0x0000FFFF0000FFFFull, 16);
50 Bits_rotateAndMask(0x00000000FFFFFFFFull, 32);
51
52 return toReverse;
53
54 #undef Bits_rotateAndMask
0689af8 Halfway through debugging...
cjdelisle authored
55 }
56
0ae0048 improved key validation, made a distance based NodeCollector used for…
cjdelisle authored
57 /**
58 * @param buffer the space of check if it's zero.
59 * @length the nuber of bytes to check for zero'd-ness.
60 * @return true if all bytes checked are zero.
61 */
62 static inline bool Bits_isZero(void* buffer, size_t length)
63 {
64 uint8_t* buff = (uint8_t*) buffer;
65 for (size_t i = 0; i < length; i++) {
66 if (buff[i]) {
67 return false;
68 }
69 }
70 return true;
71 }
72
0689af8 Halfway through debugging...
cjdelisle authored
73 #endif
Something went wrong with that request. Please try again.