(original) (raw)
#include "bitmap.h" #include #include #include #include #include #include // allocates a struct bitmap that is large enough // to hold num_bits bits (possibly with padding) // NOTE: malloc allocates bytes, not bits // must convert num_bits (+ padding) to bytes struct bitmap *allocate_bitmap(uint64_t num_bits) { struct bitmap *bmap = NULL; return bmap; } // frees all memory associated with bmap // hint: make sure you free *bits void free_bitmap(struct bitmap *bmap) { return; } // returns the value of a bit i (0 or 1) // if i is out of the valid range, yields 0 char get_bit(struct bitmap *bmap, uint64_t i) { return 0; } // sets the bit at position i (regardless of whether already set) // post: bit `i` is 1 // if i is out of the valid range, has no effect void set_bit(struct bitmap *bmap, uint64_t i) { return; } // unset the bit at position i (regardless of whether already set) // post: bit `i` is 0 // if i is out of the valid range, has no effect void unset_bit(struct bitmap *bmap, uint64_t i) { return; } // yields the lowest index that has an unset bit // if all valid bits within the bitmap is set, // returns map->n_valid_bits // hint: you will need at least one loop uint64_t first_unset_bit(struct bitmap *bmap) { return 0; } /** * This sample printing statement prints bitmap buckets from left to right, * adding formatting to help you visualize the bits in your bitmap. * DO NOT MODIFY. */ void dump_bitmap(struct bitmap *bmap) { printf("Displaying Bitmap Representation\n"); printf("\tbitmap->n_bytes: %"PRIu64"\n", bmap->n_bytes); printf("\tbitmap->n_valid_bits: %"PRIu64"\n", bmap->n_valid_bits); printf("\tbitmap->bits (8 chars per column):\n"); int line = 0; for (uint64_t i = 0; i < bmap->n_valid_bits; i++) { if (i % 8 == 0) { if (line % 64 == 0) { printf("\n"); printf("%4"PRIu64":", i); line = 0; } printf(" "); } printf("%u", get_bit(bmap, i)); line++; } printf("\n\n"); }