-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconstants.cpp
More file actions
94 lines (67 loc) · 1.75 KB
/
constants.cpp
File metadata and controls
94 lines (67 loc) · 1.75 KB
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
91
92
93
94
/*
This is constants.cpp
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#include "constants.h"
namespace constants {
Ulong *lmask;
Ulong *leqmask;
unsigned *firstbit;
unsigned *lastbit;
};
/****************************************************************************
This module provides some basic constants that will be used elsewhere
in the program. The idea is that the call to initConstants() should be
the very first one in the program; therefore this module should not
depend on anything else.
****************************************************************************/
namespace constants {
void initConstants()
{
static Ulong d_lmask[BITS(Ulong)];
static Ulong d_leqmask[BITS(Ulong)];
lmask = d_lmask;
leqmask = d_leqmask;
leqmask[0] = 1L;
lmask[0] = 1L;
for (Ulong j = 1; j < BITS(Ulong); j++)
{
lmask[j] = lmask[j-1] << 1;
leqmask[j] = leqmask[j-1] + lmask[j];
}
static unsigned d_firstbit[1<<CHAR_BIT];
firstbit = d_firstbit;
for (Ulong j = 1; j < (1 << CHAR_BIT-1); ++j)
firstbit[2*j] = firstbit[j]+1;
firstbit[0] = CHAR_BIT;
static unsigned d_lastbit[1<<CHAR_BIT];
lastbit = d_lastbit;
lastbit[0] = CHAR_BIT;
for (Ulong j = 2; j < (1 << CHAR_BIT); ++j)
lastbit[j] = lastbit[j>>1]+1;
return;
}
unsigned firstBit(Ulong f)
/*
Returns the bit position of the first set bit in f.
*/
{
if (f == 0)
return BITS(Ulong);
if (f&CHARFLAGS)
return firstbit[f&CHARFLAGS];
else
return firstBit(f>>CHAR_BIT)+CHAR_BIT;
}
unsigned lastBit(Ulong f)
/*
Returns the bit position of the last set bit in f.
*/
{
if (f >> CHAR_BIT)
return lastBit(f>>CHAR_BIT)+CHAR_BIT;
else
return lastbit[f];
}
};