8aef186f709a6073c6c445f19b20285f2b114d08
[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
7 /* Bitmap abstract data type. */
8
9 struct bitmap *bitmap_create (size_t bit_cnt);
10 void bitmap_destroy (struct bitmap *);
11
12 size_t bitmap_size (const struct bitmap *);
13
14 void bitmap_set (struct bitmap *, size_t idx, bool);
15 void bitmap_set_all (struct bitmap *, bool);
16
17 void bitmap_mark (struct bitmap *, size_t idx);
18 void bitmap_reset (struct bitmap *, size_t idx);
19 void bitmap_flip (struct bitmap *, size_t idx);
20
21 bool bitmap_test (const struct bitmap *, size_t idx);
22
23 #define BITMAP_ERROR ((size_t) -1)
24 size_t bitmap_scan (const struct bitmap *, bool);
25 size_t bitmap_find_and_set (struct bitmap *);
26 size_t bitmap_find_and_clear (struct bitmap *);
27
28 size_t bitmap_set_cnt (const struct bitmap *);
29 bool bitmap_clear_cnt (const struct bitmap *);
30
31 bool bitmap_any (const struct bitmap *);
32 bool bitmap_none (const struct bitmap *);
33 bool bitmap_all (const struct bitmap *);
34
35 #ifdef FILESYS
36 struct file;
37 size_t bitmap_file_size (const struct bitmap *);
38 void bitmap_read (struct bitmap *, struct file *);
39 void bitmap_write (const struct bitmap *, struct file *);
40 #endif
41
42 void bitmap_dump (const struct bitmap *);
43
44 #endif /* lib/kernel/bitmap.h */