Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / lib / kernel / bitmap.h
1 #ifndef __LIB_KERNEL_BITMAP_H
2 #define __LIB_KERNEL_BITMAP_H
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <inttypes.h>
7
8 /* Bitmap abstract data type. */
9
10 /* Creation and destruction. */
11 struct bitmap *bitmap_create (size_t bit_cnt);
12 struct bitmap *bitmap_create_in_buf (size_t bit_cnt, void *, size_t byte_cnt);
13 size_t bitmap_buf_size (size_t bit_cnt);
14 void bitmap_destroy (struct bitmap *);
15
16 /* Bitmap size. */
17 size_t bitmap_size (const struct bitmap *);
18
19 /* Setting and testing single bits. */
20 void bitmap_set (struct bitmap *, size_t idx, bool);
21 void bitmap_mark (struct bitmap *, size_t idx);
22 void bitmap_reset (struct bitmap *, size_t idx);
23 void bitmap_flip (struct bitmap *, size_t idx);
24 bool bitmap_test (const struct bitmap *, size_t idx);
25
26 /* Setting and testing multiple bits. */
27 void bitmap_set_all (struct bitmap *, bool);
28 void bitmap_set_multiple (struct bitmap *, size_t start, size_t cnt, bool);
29 size_t bitmap_count (const struct bitmap *, size_t start, size_t cnt, bool);
30 bool bitmap_contains (const struct bitmap *, size_t start, size_t cnt, bool);
31 bool bitmap_any (const struct bitmap *, size_t start, size_t cnt);
32 bool bitmap_none (const struct bitmap *, size_t start, size_t cnt);
33 bool bitmap_all (const struct bitmap *, size_t start, size_t cnt);
34
35 /* Finding set or unset bits. */
36 #define BITMAP_ERROR SIZE_MAX
37 size_t bitmap_scan (const struct bitmap *, size_t start, size_t cnt, bool);
38 size_t bitmap_scan_and_flip (struct bitmap *, size_t start, size_t cnt, bool);
39
40 /* File input and output. */
41 #ifdef FILESYS
42 struct file;
43 size_t bitmap_file_size (const struct bitmap *);
44 bool bitmap_read (struct bitmap *, struct file *);
45 bool bitmap_write (const struct bitmap *, struct file *);
46 #endif
47
48 /* Debugging. */
49 void bitmap_dump (const struct bitmap *);
50
51 #endif /* lib/kernel/bitmap.h */