1 /* 2 This is constants.cpp 3 4 Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux 5 See file main.cpp for full copyright notice 6 */ 7 8 #include "constants.h" 9 10 namespace constants { 11 Ulong *lmask; 12 Ulong *leqmask; 13 unsigned *firstbit; 14 unsigned *lastbit; 15 }; 16 17 /**************************************************************************** 18 19 This module provides some basic constants that will be used elsewhere 20 in the program. The idea is that the call to initConstants() should be 21 the very first one in the program; therefore this module should not 22 depend on anything else. 23 24 ****************************************************************************/ 25 26 namespace constants { 27 initConstants()28void initConstants() 29 30 { 31 static Ulong d_lmask[BITS(Ulong)]; 32 static Ulong d_leqmask[BITS(Ulong)]; 33 34 lmask = d_lmask; 35 leqmask = d_leqmask; 36 37 leqmask[0] = 1L; 38 lmask[0] = 1L; 39 40 for (Ulong j = 1; j < BITS(Ulong); j++) 41 { 42 lmask[j] = lmask[j-1] << 1; 43 leqmask[j] = leqmask[j-1] + lmask[j]; 44 } 45 46 static unsigned d_firstbit[1<<CHAR_BIT]; 47 firstbit = d_firstbit; 48 49 for (Ulong j = 1; j < (1 << CHAR_BIT-1); ++j) 50 firstbit[2*j] = firstbit[j]+1; 51 52 firstbit[0] = CHAR_BIT; 53 54 static unsigned d_lastbit[1<<CHAR_BIT]; 55 lastbit = d_lastbit; 56 lastbit[0] = CHAR_BIT; 57 58 for (Ulong j = 2; j < (1 << CHAR_BIT); ++j) 59 lastbit[j] = lastbit[j>>1]+1; 60 61 return; 62 } 63 firstBit(Ulong f)64unsigned firstBit(Ulong f) 65 66 /* 67 Returns the bit position of the first set bit in f. 68 */ 69 70 { 71 if (f == 0) 72 return BITS(Ulong); 73 74 if (f&CHARFLAGS) 75 return firstbit[f&CHARFLAGS]; 76 else 77 return firstBit(f>>CHAR_BIT)+CHAR_BIT; 78 } 79 80 lastBit(Ulong f)81unsigned lastBit(Ulong f) 82 83 /* 84 Returns the bit position of the last set bit in f. 85 */ 86 87 { 88 if (f >> CHAR_BIT) 89 return lastBit(f>>CHAR_BIT)+CHAR_BIT; 90 else 91 return lastbit[f]; 92 } 93 94 }; 95