Mercurial > hg > Members > masakoha > testcode
changeset 92:9a1bb8f439f5
fix (not correct running)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 26 Oct 2015 18:36:19 +0900 |
parents | 912d7bd51f38 |
children | 23e796173c91 |
files | c/bitVector/main.cc |
diffstat | 1 files changed, 21 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/c/bitVector/main.cc Fri Oct 23 18:53:46 2015 +0900 +++ b/c/bitVector/main.cc Mon Oct 26 18:36:19 2015 +0900 @@ -3,18 +3,37 @@ #include <string.h> #include "bitInfo.h" +void bitPrint(BitInfoPtr bi); + int bitBlock = sizeof(unsigned long) * 8; -void bitSet(BitInfoPtr bi, int bitSetPosition) { +BitInfoPtr bitSet(int bitSetPosition) { + + BitInfoPtr bi = (BitInfoPtr)malloc(sizeof(BitInfo)); + + 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; + } unsigned long tmp = 1; int arrayPosition = 0; arrayPosition = bitSetPosition / bitBlock; bitSetPosition = bitSetPosition % bitBlock; + + bi->bitContainer = bitContainer; tmp = tmp << (bitBlock - 1 - bitSetPosition); bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; + + bitPrint(bi); + + return bi; } void bitPrint(BitInfoPtr bi) { @@ -29,7 +48,6 @@ int main(int argc, char **argv) { - BitInfoPtr bi = (BitInfoPtr)malloc(sizeof(BitInfo)); int bitSetPosition = 0; for (int i = 1; i < argc ; i++) { @@ -38,18 +56,7 @@ } } - 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); + BitInfoPtr bi = bitSet(bitSetPosition); bitPrint(bi); return 0; }