X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flib%2Fkernel%2Fbitmap.h;h=a50593c9f291d56a80ac81c5b5362a17eb1d7b00;hb=615bf3b3d2a8573ed6fb9ddc0055745e163ac999;hp=f70688b28662e70233cef635a2c1dcece495808b;hpb=6916b246f3be8c72d6e77fd98c4a1447fd2c1de7;p=pintos-anon diff --git a/src/lib/kernel/bitmap.h b/src/lib/kernel/bitmap.h index f70688b..a50593c 100644 --- a/src/lib/kernel/bitmap.h +++ b/src/lib/kernel/bitmap.h @@ -3,61 +3,49 @@ #include #include +#include /* Bitmap abstract data type. */ -/* Element type. - - This must be an unsigned integer type at least as wide as int. - - Each bit represents one bit in the bitmap. - If bit 0 in an element represents bit K in the bitmap, - then bit 1 in the element represents bit K+1 in the bitmap, - and so on. */ -typedef unsigned long elem_type; - -/* From the outside, a bitmap is an array of bits. From the - inside, it's an array of elem_type (defined above) that - simulates an array of bits. */ -struct bitmap - { - size_t bit_cnt; /* Number of bits. */ - elem_type *bits; /* Elements that represent bits. */ - }; - -bool bitmap_init (struct bitmap *, size_t bit_cnt); +/* Creation and destruction. */ +struct bitmap *bitmap_create (size_t bit_cnt); +struct bitmap *bitmap_create_in_buf (size_t bit_cnt, void *, size_t byte_cnt); +size_t bitmap_buf_size (size_t bit_cnt); void bitmap_destroy (struct bitmap *); +/* Bitmap size. */ size_t bitmap_size (const struct bitmap *); +/* Setting and testing single bits. */ void bitmap_set (struct bitmap *, size_t idx, bool); -void bitmap_set_all (struct bitmap *, bool); - void bitmap_mark (struct bitmap *, size_t idx); void bitmap_reset (struct bitmap *, size_t idx); void bitmap_flip (struct bitmap *, size_t idx); - bool bitmap_test (const struct bitmap *, size_t idx); -#define BITMAP_ERROR ((size_t) -1) -size_t bitmap_scan (const struct bitmap *, bool); -size_t bitmap_find_and_set (struct bitmap *); -size_t bitmap_find_and_clear (struct bitmap *); - -size_t bitmap_set_cnt (const struct bitmap *); -bool bitmap_clear_cnt (const struct bitmap *); - -bool bitmap_any (const struct bitmap *); -bool bitmap_none (const struct bitmap *); -bool bitmap_all (const struct bitmap *); - +/* Setting and testing multiple bits. */ +void bitmap_set_all (struct bitmap *, bool); +void bitmap_set_multiple (struct bitmap *, size_t start, size_t cnt, bool); +size_t bitmap_count (const struct bitmap *, size_t start, size_t cnt, bool); +bool bitmap_contains (const struct bitmap *, size_t start, size_t cnt, bool); +bool bitmap_any (const struct bitmap *, size_t start, size_t cnt); +bool bitmap_none (const struct bitmap *, size_t start, size_t cnt); +bool bitmap_all (const struct bitmap *, size_t start, size_t cnt); + +/* Finding set or unset bits. */ +#define BITMAP_ERROR SIZE_MAX +size_t bitmap_scan (const struct bitmap *, size_t start, size_t cnt, bool); +size_t bitmap_scan_and_flip (struct bitmap *, size_t start, size_t cnt, bool); + +/* File input and output. */ #ifdef FILESYS struct file; size_t bitmap_file_size (const struct bitmap *); -void bitmap_read (struct bitmap *, struct file *); -void bitmap_write (const struct bitmap *, struct file *); +bool bitmap_read (struct bitmap *, struct file *); +bool bitmap_write (const struct bitmap *, struct file *); #endif +/* Debugging. */ void bitmap_dump (const struct bitmap *); #endif /* lib/kernel/bitmap.h */