Example #1
0
/*-----------------------------------------------------------------------------*
| Bit2_new
|       Purpose:   creates an instance of Bit2
|       Arguments: the dimensions of the 2D bit array to be created as ints
|       Returns:   a pointer to a 2D bit array
|       Fail cases:
|               - either of the dimensions passed is not positive
*-----------------------------------------------------------------------------*/
Bit2_T Bit2_new (int dim1, int dim2) {
        assert((dim1 > 0) && (dim2 > 0));
        int length = dim1 * dim2;
        Bit2_T new_bitmap = malloc(sizeof(*new_bitmap));
        new_bitmap->width = dim1;
        new_bitmap->height = dim2;
        new_bitmap->bitmap = Bit_new(length);
        return new_bitmap;
}
Example #2
0
void kernel_init(void) {
    static int init;

    pmap_start = 1;
    if(init) {
        Bit_clear(free_map, 0, XN_NBLOCKS-1);
        return;
    }
    init = 1;
    pages = (void *)malloc(XN_BLOCK_SIZE * (PHYS_MEM+1));
    assert(pages);
    pages = (void *)roundup((unsigned)pages, XN_BLOCK_SIZE);
    demand((unsigned) pages % XN_BLOCK_SIZE == 0, Bogus alignment);

    pmap = Bit_new(PHYS_MEM);
    free_map = Bit_new(XN_NBLOCKS);
    demand(db_isfree(0, 1), should have allocated);
    db_alloc(0, 1);
    demand(!db_isfree(0, 1), should have allocated);
}
Example #3
0
/* checks that each row, column, and 3x3 box has digits 1 through 9*/
void correct_sudoku(UArray2_T uarray2)
{
        Bit_T bit = Bit_new(10);

        UArray2_map_row_major(uarray2, check_setof9, bit);;
        UArray2_map_col_major(uarray2, check_setof9, bit);
        UArray2_map_3x3_box(uarray2, check_setof9, bit);

        Bit_free(&bit);

}
/* 
* Creates the new bit2 with given width and height and size 
*/
extern T Bit2_new(int width, int height)
{
        assert ((height && width >= 0));
        int dimensions = get_dimensions(width , height);
        Bit2_T bit2 = malloc(sizeof(struct Bit2_T));
        bit2->bit_vector = Bit_new(dimensions);
        bit2->width = width;
        bit2->height = height;
        bit2->dimensions = dimensions;
        return bit2;
}
Example #5
0
int main(int argc, char *argv[])
{
    int k, n, i;
    Bit_T bits;

    if (argc != 3)
        usage();

    k = atoi(argv[1]);
    n = atoi(argv[2]);
    srand(time(0));
    bits = Bit_new(n);
    for (i = 0; i < k; i++) {
        int j;
        do {
            j = rand()%n;
        } while (Bit_get(bits, j));
        Bit_put(bits, j, 1);
        printf("%d\n", j);
    }
    Bit_free(&bits);

    return 0;
}