view regexParser/bitVector.cc @ 167:3bf2c6d6d53e pairPro

move regexparser dir
author masa
date Sat, 19 Dec 2015 15:38:45 +0900
parents c/regexParser/bitVector.cc@84a2a5209d3a
children dbe004d03ef0
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bitVector.h"

BitVectorPtr createBitVector(NodePtr n) {
    BitVectorPtr bi = allocateBitVector();
    bitSet(bi,n->nodeNumber);
    return bi;
}

const BitVectorPtr allocateBitVector() {
    BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector));
    bi->bitContainer = 0;
    return bi;
}

void bitSet(BitVectorPtr bi, int bitSetPosition) {
    unsigned long tmp = 1 << (bitSetPosition % BITBLOCK);
    bi->bitContainer = bi->bitContainer | tmp;
    return;
}

void bitPrint(BitVectorPtr bi) {
    unsigned long vec = bi->bitContainer;
    for (int j = 0; j < BITBLOCK; j++) {
        putchar((vec & 1) ? '1':'0');
        vec >>= 1;
    }
    printf("\n");
}