Mercurial > hg > Members > masakoha > testcode
comparison c/regexParser/bitVector.cc @ 94:43b807f88961 impl-bitvector
implement bitvector (suspend)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 Nov 2015 12:26:07 +0900 |
parents | 1d7ca366b199 |
children | d0d2262d4edf |
comparison
equal
deleted
inserted
replaced
93:23e796173c91 | 94:43b807f88961 |
---|---|
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 void bitPrint(BitVectorPtr bi); | |
7 | |
6 int bitBlock = sizeof(unsigned long) * 8; | 8 int bitBlock = sizeof(unsigned long) * 8; |
7 | 9 |
8 void bitSet(BitVectorPtr bi, int bitSetPosition) { | 10 BitVectorPtr bitSet(int bitSetPosition) { |
9 | 11 |
12 BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector)); | |
13 bi->bitContainer = (unsigned long*)malloc(sizeof(unsigned long)*bi->arrayNum); | |
14 | |
15 bi->arrayNum = (bitSetPosition + 1) / bitBlock; | |
16 if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++; | |
17 | |
18 printf("Array Num : %d\n",bi->arrayNum); | |
19 | |
20 | |
21 for (int i = 0; i < bi->arrayNum; i++) { | |
22 bi->bitContainer[i] = 0; | |
23 } | |
10 unsigned long tmp = 1; | 24 unsigned long tmp = 1; |
11 int arrayPosition = 0; | 25 int arrayPosition = 0; |
12 | 26 |
13 arrayPosition = bitSetPosition / bitBlock; | 27 arrayPosition = bitSetPosition / bitBlock; |
14 bitSetPosition = bitSetPosition % bitBlock; | 28 bitSetPosition = bitSetPosition % bitBlock; |
15 | 29 |
16 tmp = tmp << (bitBlock - 1 - bitSetPosition); | 30 tmp = tmp << (bitBlock - 1 - bitSetPosition); |
17 bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; | 31 bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; |
32 | |
33 return bi; | |
18 } | 34 } |
19 | 35 |
20 void bitPrint(BitVectorPtr bi) { | 36 void bitPrint(BitVectorPtr bi) { |
21 for (int i = 0; i < bi->arrayNum ; i++) { | 37 for (int i = 0; i < bi->arrayNum ; i++) { |
22 for (int j = bitBlock - 1; j >= 0; j--) { | 38 for (int j = bitBlock - 1; j >= 0; j--) { |
24 } | 40 } |
25 printf(" "); | 41 printf(" "); |
26 } | 42 } |
27 puts(""); | 43 puts(""); |
28 } | 44 } |
29 /* | |
30 int main(int argc, char **argv) { | |
31 | |
32 BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector)); | |
33 int bitSetPosition = 0; | |
34 | |
35 for (int i = 1; i < argc ; i++) { | |
36 if (strcmp(argv[i],"-n") == 0) { | |
37 bitSetPosition = atoi(argv[i+1]); | |
38 } | |
39 } | |
40 | |
41 bi->arrayNum = (bitSetPosition + 1) / bitBlock; | |
42 if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++; | |
43 | |
44 printf("Array Num : %d\n",bi->arrayNum); | |
45 | |
46 unsigned long bitContainer[bi->arrayNum]; | |
47 for (int i = 0; i < bi->arrayNum; i++) { | |
48 bitContainer[i] = 0; | |
49 } | |
50 | |
51 bi->bitContainer = bitContainer; | |
52 bitSet(bi,bitSetPosition); | |
53 bitPrint(bi); | |
54 return 0; | |
55 } | |
56 */ |