Mercurial > hg > Members > masakoha > testcode
changeset 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 | 23e796173c91 |
children | 1cdad0468484 |
files | c/regexParser/bitVector.cc c/regexParser/bitVector.h |
diffstat | 2 files changed, 19 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/bitVector.cc Tue Oct 27 19:29:26 2015 +0900 +++ b/c/regexParser/bitVector.cc Mon Nov 09 12:26:07 2015 +0900 @@ -3,10 +3,24 @@ #include <string.h> #include "bitVector.h" +void bitPrint(BitVectorPtr bi); + int bitBlock = sizeof(unsigned long) * 8; -void bitSet(BitVectorPtr bi, int bitSetPosition) { +BitVectorPtr bitSet(int bitSetPosition) { + + BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector)); + bi->bitContainer = (unsigned long*)malloc(sizeof(unsigned long)*bi->arrayNum); + bi->arrayNum = (bitSetPosition + 1) / bitBlock; + if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++; + + printf("Array Num : %d\n",bi->arrayNum); + + + for (int i = 0; i < bi->arrayNum; i++) { + bi->bitContainer[i] = 0; + } unsigned long tmp = 1; int arrayPosition = 0; @@ -15,6 +29,8 @@ tmp = tmp << (bitBlock - 1 - bitSetPosition); bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; + + return bi; } void bitPrint(BitVectorPtr bi) { @@ -26,31 +42,3 @@ } puts(""); } -/* -int main(int argc, char **argv) { - - BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector)); - int bitSetPosition = 0; - - for (int i = 1; i < argc ; i++) { - if (strcmp(argv[i],"-n") == 0) { - bitSetPosition = atoi(argv[i+1]); - } - } - - bi->arrayNum = (bitSetPosition + 1) / bitBlock; - if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++; - - printf("Array Num : %d\n",bi->arrayNum); - - unsigned long bitContainer[bi->arrayNum]; - for (int i = 0; i < bi->arrayNum; i++) { - bitContainer[i] = 0; - } - - bi->bitContainer = bitContainer; - bitSet(bi,bitSetPosition); - bitPrint(bi); - return 0; -} -*/
--- a/c/regexParser/bitVector.h Tue Oct 27 19:29:26 2015 +0900 +++ b/c/regexParser/bitVector.h Mon Nov 09 12:26:07 2015 +0900 @@ -4,6 +4,6 @@ }BitVector,*BitVectorPtr; typedef struct bitVectorList { - BitVector bi; - BitVectorPtr next[256]; + BitVectorPtr bi; + bitVectorList* next[256]; }BitVectorList, *BitVectorListPtr;