PKUOS - Pintos
Pintos source browser for PKU Operating System 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. */
11struct bitmap *bitmap_create (size_t bit_cnt);
12struct bitmap *bitmap_create_in_buf (size_t bit_cnt, void *, size_t byte_cnt);
13size_t bitmap_buf_size (size_t bit_cnt);
14void bitmap_destroy (struct bitmap *);
15
16/** Bitmap size. */
17size_t bitmap_size (const struct bitmap *);
18
19/** Setting and testing single bits. */
20void bitmap_set (struct bitmap *, size_t idx, bool);
21void bitmap_mark (struct bitmap *, size_t idx);
22void bitmap_reset (struct bitmap *, size_t idx);
23void bitmap_flip (struct bitmap *, size_t idx);
24bool bitmap_test (const struct bitmap *, size_t idx);
25
26/** Setting and testing multiple bits. */
27void bitmap_set_all (struct bitmap *, bool);
28void bitmap_set_multiple (struct bitmap *, size_t start, size_t cnt, bool);
29size_t bitmap_count (const struct bitmap *, size_t start, size_t cnt, bool);
30bool bitmap_contains (const struct bitmap *, size_t start, size_t cnt, bool);
31bool bitmap_any (const struct bitmap *, size_t start, size_t cnt);
32bool bitmap_none (const struct bitmap *, size_t start, size_t cnt);
33bool bitmap_all (const struct bitmap *, size_t start, size_t cnt);
34
35/** Finding set or unset bits. */
36#define BITMAP_ERROR SIZE_MAX
37size_t bitmap_scan (const struct bitmap *, size_t start, size_t cnt, bool);
38size_t bitmap_scan_and_flip (struct bitmap *, size_t start, size_t cnt, bool);
39
40/** File input and output. */
41#ifdef FILESYS
42struct file;
43size_t bitmap_file_size (const struct bitmap *);
44bool bitmap_read (struct bitmap *, struct file *);
45bool bitmap_write (const struct bitmap *, struct file *);
46#endif
47
48/** Debugging. */
49void bitmap_dump (const struct bitmap *);
50
51#endif /**< lib/kernel/bitmap.h */
static size_t byte_cnt(size_t bit_cnt)
Returns the number of bytes required for BIT_CNT bits.
Definition: bitmap.c:58
struct bitmap * bitmap_create_in_buf(size_t bit_cnt, void *, size_t byte_cnt)
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
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
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
void bitmap_destroy(struct bitmap *)
Destroys bitmap B, freeing its storage.
Definition: bitmap.c:123
size_t bitmap_scan(const struct bitmap *, size_t start, size_t cnt, bool)
Finding set or unset bits.
Definition: bitmap.c:296
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
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
size_t bitmap_size(const struct bitmap *)
Bitmap size.
Definition: bitmap.c:136
void bitmap_reset(struct bitmap *, size_t idx)
Atomically sets the bit numbered BIT_IDX in B to false.
Definition: bitmap.c:170
void bitmap_set(struct bitmap *, size_t idx, bool)
Setting and testing single bits.
Definition: bitmap.c:145
void bitmap_mark(struct bitmap *, size_t idx)
Atomically sets the bit numbered BIT_IDX in B to true.
Definition: bitmap.c:157
void bitmap_set_all(struct bitmap *, bool)
Setting and testing multiple bits.
Definition: bitmap.c:209
void bitmap_dump(const struct bitmap *)
File input and output.
Definition: bitmap.c:367
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
bool bitmap_test(const struct bitmap *, size_t idx)
Returns the value of the bit numbered IDX in B.
Definition: bitmap.c:198
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
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
struct bitmap * bitmap_create(size_t bit_cnt)
Bitmap abstract data type.
Definition: bitmap.c:79
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
char * start[]
Insult.c.
Definition: insult.c:13
From the outside, a bitmap is an array of bits.
Definition: bitmap.c:28
size_t bit_cnt
Number of bits.
Definition: bitmap.c:29
An open file.
Definition: file.c:8