Mercurial > hg > Applications > Grep
view c/regexParser/bitVector.cc @ 112:ec485345daf9 pairPro
some function use static
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Nov 2015 15:54:19 +0900 |
parents | a3adc5c24e19 |
children | ca30f8334741 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "bitVector.h" void bitPrint(BitVectorPtr bi); int bitBlock = sizeof(unsigned long) * 8; BitVectorListPtr createBitVector(NodePtr n,BitVectorListPtr bvl) { BitVectorListPtr nextBvl = allocateBitVectorList(); nextBvl->bi = bitSet(n->nodeNumber); nextBvl->initBvl = initBvl; return nextBvl; } BitVectorPtr createBitVector(int bitSetPosition) { BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector)); if (bi == NULL) { fprintf(stderr, "Failed to allocate memory.\n"); exit(-1); } bi->bitContainer = (unsigned long*)malloc(sizeof(unsigned long)*bi->arrayNum); if (bi->bitContainer == NULL) { fprintf(stderr, "Failed to allocate memory.\n"); exit(-1); } for (int i = 0; i < bi->arrayNum; i++) { bi->bitContainer[i] = 0; } return bi; } BitVectorPtr bitSet(BitVectorPtr bi, int bitSetPosition) { bi->arrayNum = (bitSetPosition + bitBlock - 1) / bitBlock; int arrayPosition = bitSetPosition / bitBlock; unsigned long tmp = 1 << (bitSetPosition % bitBlock); bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; return bi; } void bitPrint(BitVectorPtr bi) { for (int i = 0; i < bi->arrayNum ; i++) { unsigned long vec = bi->bitContainer[i]; for (int j = 0; j < bitBlock; j++) { printf( "%lu", vec & 1 ); vec >>= 1; } printf(" "); } puts(""); }