Mercurial > hg > Members > masakoha > testcode
comparison c/regexParser/bitVector.cc @ 117:166136236891 pairPro
add header files
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 25 Nov 2015 14:58:03 +0900 |
parents | 66c633575b53 |
children | c292c67b3100 |
comparison
equal
deleted
inserted
replaced
116:66c633575b53 | 117:166136236891 |
---|---|
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <string.h> | 3 #include <string.h> |
4 #include "bitVector.h" | 4 #include "bitVector.h" |
5 extern BitVectorListPtr allocateBitVectorList(); | 5 extern BitVectorListPtr allocateBitVectorList(); |
6 const BitVectorPtr allocateBitVector(); | 6 const BitVectorPtr allocateBitVector(); |
7 | |
8 int bitBlock = sizeof(unsigned long) * 8; | |
9 | 7 |
10 BitVectorListPtr createBitVector(NodePtr n,BitVectorListPtr bvl) { | 8 BitVectorListPtr createBitVector(NodePtr n,BitVectorListPtr bvl) { |
11 BitVectorListPtr nextBvl = allocateBitVectorList(); | 9 BitVectorListPtr nextBvl = allocateBitVectorList(); |
12 nextBvl->bi = bitSet(n->nodeNumber); | 10 nextBvl->bi = bitSet(n->nodeNumber); |
13 return nextBvl; | 11 return nextBvl; |
36 | 34 |
37 BitVectorPtr bitSet(int bitSetPosition) { | 35 BitVectorPtr bitSet(int bitSetPosition) { |
38 | 36 |
39 BitVectorPtr bi = allocateBitVector(); | 37 BitVectorPtr bi = allocateBitVector(); |
40 | 38 |
41 bi->arrayNum = (bitSetPosition + bitBlock) / bitBlock; | 39 bi->arrayNum = (bitSetPosition + BITBLOCK) / BITBLOCK; |
42 | 40 |
43 int arrayPosition = bitSetPosition / bitBlock; | 41 int arrayPosition = bitSetPosition / BITBLOCK; |
44 | 42 |
45 unsigned long tmp = 1 << (bitSetPosition % bitBlock); | 43 unsigned long tmp = 1 << (bitSetPosition % BITBLOCK); |
46 bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; | 44 bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; |
47 | 45 |
48 return bi; | 46 return bi; |
49 } | 47 } |
50 | 48 |
51 void bitPrint(BitVectorPtr bi) { | 49 void bitPrint(BitVectorPtr bi) { |
52 for (int i = 0; i < bi->arrayNum ; i++) { | 50 for (int i = 0; i < bi->arrayNum ; i++) { |
53 unsigned long vec = bi->bitContainer[i]; | 51 unsigned long vec = bi->bitContainer[i]; |
54 for (int j = 0; j < bitBlock; j++) { | 52 for (int j = 0; j < BITBLOCK; j++) { |
55 printf( "%lu", vec & 1 ); | 53 printf( "%lu", vec & 1 ); |
56 vec >>= 1; | 54 vec >>= 1; |
57 } | 55 } |
58 printf(" "); | 56 printf(" "); |
59 } | 57 } |