CS318 - Pintos
Pintos source browser for JHU CS318 course
bitmap.h
Go to the documentation of this file.
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 */
bitmap_dump
void bitmap_dump(const struct bitmap *)
File input and output.
Definition: bitmap.c:367
bitmap_set_multiple
void bitmap_set_multiple(struct bitmap *, size_t start, size_t cnt, bool)
Sets the CNT bits starting at START in B to VALUE.
Definition: bitmap.c:218
start
char * start[]
Insult.c.
Definition: insult.c:13
bitmap_mark
void bitmap_mark(struct bitmap *, size_t idx)
Atomically sets the bit numbered BIT_IDX in B to true.
Definition: bitmap.c:157
bitmap_create
struct bitmap * bitmap_create(size_t bit_cnt)
Bitmap abstract data type.
Definition: bitmap.c:79
bitmap_size
size_t bitmap_size(const struct bitmap *)
Bitmap size.
Definition: bitmap.c:136
file
An open file.
Definition: file.c:7
bitmap_any
bool bitmap_any(const struct bitmap *, size_t start, size_t cnt)
Returns true if any bits in B between START and START + CNT, exclusive, are set to true,...
Definition: bitmap.c:268
stdbool.h
bitmap_flip
void bitmap_flip(struct bitmap *, size_t idx)
Atomically toggles the bit numbered IDX in B; that is, if it is true, makes it false,...
Definition: bitmap.c:185
bitmap_destroy
void bitmap_destroy(struct bitmap *)
Destroys bitmap B, freeing its storage.
Definition: bitmap.c:123
byte_cnt
static size_t byte_cnt(size_t bit_cnt)
Returns the number of bytes required for BIT_CNT bits.
Definition: bitmap.c:58
bitmap::bit_cnt
size_t bit_cnt
Number of bits.
Definition: bitmap.c:29
bitmap_buf_size
size_t bitmap_buf_size(size_t bit_cnt)
Returns the number of bytes required to accomodate a bitmap with BIT_CNT bits (for use with bitmap_cr...
Definition: bitmap.c:115
bitmap_count
size_t bitmap_count(const struct bitmap *, size_t start, size_t cnt, bool)
Returns the number of bits in B between START and START + CNT, exclusive, that are set to VALUE.
Definition: bitmap.c:233
bitmap_scan_and_flip
size_t bitmap_scan_and_flip(struct bitmap *, size_t start, size_t cnt, bool)
Finds the first group of CNT consecutive bits in B at or after START that are all set to VALUE,...
Definition: bitmap.c:320
bitmap_set_all
void bitmap_set_all(struct bitmap *, bool)
Setting and testing multiple bits.
Definition: bitmap.c:209
bitmap_create_in_buf
struct bitmap * bitmap_create_in_buf(size_t bit_cnt, void *, size_t byte_cnt)
bitmap
From the outside, a bitmap is an array of bits.
Definition: bitmap.c:27
bitmap_contains
bool bitmap_contains(const struct bitmap *, size_t start, size_t cnt, bool)
Returns true if any bits in B between START and START + CNT, exclusive, are set to VALUE,...
Definition: bitmap.c:251
bitmap_scan
size_t bitmap_scan(const struct bitmap *, size_t start, size_t cnt, bool)
Finding set or unset bits.
Definition: bitmap.c:296
bitmap_reset
void bitmap_reset(struct bitmap *, size_t idx)
Atomically sets the bit numbered BIT_IDX in B to false.
Definition: bitmap.c:170
bitmap_all
bool bitmap_all(const struct bitmap *, size_t start, size_t cnt)
Returns true if every bit in B between START and START + CNT, exclusive, is set to true,...
Definition: bitmap.c:284
inttypes.h
stddef.h
bitmap_test
bool bitmap_test(const struct bitmap *, size_t idx)
Returns the value of the bit numbered IDX in B.
Definition: bitmap.c:198
bitmap_set
void bitmap_set(struct bitmap *, size_t idx, bool)
Setting and testing single bits.
Definition: bitmap.c:145
bitmap_none
bool bitmap_none(const struct bitmap *, size_t start, size_t cnt)
Returns true if no bits in B between START and START + CNT, exclusive, are set to true,...
Definition: bitmap.c:276