Mercurial > hg > Members > masakoha > testcode
annotate regexParser/bitVector.cc @ 275:8879eb8c64a8
remove segmentation fault
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 30 Jan 2016 19:06:41 +0900 |
parents | 02031fb73af8 |
children |
rev | line source |
---|---|
86
1d7ca366b199
add bitVector
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdio.h> |
1d7ca366b199
add bitVector
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #include <stdlib.h> |
1d7ca366b199
add bitVector
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include <string.h> |
191
02031fb73af8
remove somefiles and fix header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
188
diff
changeset
|
4 #include "regexParser.h" |
94
43b807f88961
implement bitvector (suspend)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
86
diff
changeset
|
5 |
188
109d22faf7b5
remove errors and warnings
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
187
diff
changeset
|
6 BitVector createBitVector(int state) { |
187
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
7 unsigned long tmp = 1 << state; |
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
8 BitVector bi1 = (BitVector){.bitContainer = tmp}; |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
9 return bi1; |
110 | 10 } |
11 | |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
12 BitVector bitSet(BitVector bi, int bitSetPosition) { |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
13 unsigned long tmp = 1 << bitSetPosition; |
187
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
14 BitVector bi1 = (BitVector){.bitContainer = bi.bitContainer | tmp}; |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
15 return bi1; |
110 | 16 } |
17 | |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
18 void bitPrint(BitVector bi) { |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
19 unsigned long vec = bi.bitContainer; |
137 | 20 for (int j = 0; j < BITBLOCK; j++) { |
138
ea2810db8d87
remove warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
137
diff
changeset
|
21 putchar((vec & 1) ? '1':'0'); |
137 | 22 vec >>= 1; |
86
1d7ca366b199
add bitVector
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 } |
137 | 24 printf("\n"); |
86
1d7ca366b199
add bitVector
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 } |