comparison regexParser/bitVector.cc @ 182:dbe004d03ef0 pairPro

implement stateAllocate()
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Thu, 24 Dec 2015 19:14:49 +0900
parents 3bf2c6d6d53e
children ef798db705e9
comparison
equal deleted inserted replaced
181:3c4db09b8581 182:dbe004d03ef0
1 #include <stdio.h> 1 #include <stdio.h>
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 5
6 BitVectorPtr createBitVector(NodePtr n) { 6 BitVector createBitvector(int state) {
7 BitVectorPtr bi = allocateBitVector(); 7 unsigned long tmp = 1 << bitSetPosition;
8 bitSet(bi,n->nodeNumber); 8 BitVector bi1 = (struct BitVector){.bitContainer = tmp};
9 return bi; 9 return bi1;
10 } 10 }
11 11
12 const BitVectorPtr allocateBitVector() { 12 BitVector bitSet(BitVector bi, int bitSetPosition) {
13 BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector)); 13 unsigned long tmp = 1 << bitSetPosition;
14 bi->bitContainer = 0; 14 BitVector bi1 = (struct BitVector){.bitContainer = bi.bitContainer | tmp};
15 return bi; 15 return bi1;
16 } 16 }
17 17
18 void bitSet(BitVectorPtr bi, int bitSetPosition) { 18 void bitPrint(BitVector bi) {
19 unsigned long tmp = 1 << (bitSetPosition % BITBLOCK); 19 unsigned long vec = bi.bitContainer;
20 bi->bitContainer = bi->bitContainer | tmp;
21 return;
22 }
23
24 void bitPrint(BitVectorPtr bi) {
25 unsigned long vec = bi->bitContainer;
26 for (int j = 0; j < BITBLOCK; j++) { 20 for (int j = 0; j < BITBLOCK; j++) {
27 putchar((vec & 1) ? '1':'0'); 21 putchar((vec & 1) ? '1':'0');
28 vec >>= 1; 22 vec >>= 1;
29 } 23 }
30 printf("\n"); 24 printf("\n");