tac0S
Template Affectional Command Operating System
Public Member Functions | List of all members
BitMap Class Reference

The following class defines a "bitmap" – an array of bits, each of which can be independently set, cleared, and tested. More...

#include <bitmap.h>

Public Member Functions

 BitMap (int nitems)
 Initialize a bitmap, with "nitems" bits. More...
 
 ~BitMap ()
 initially, all bits are cleared. More...
 
void Mark (int which)
 Set the "nth" bit. More...
 
void Clear (int which)
 Clear the "nth" bit. More...
 
bool Test (int which)
 Is the "nth" bit set? More...
 
int Find ()
 Return the # of a clear bit, and as a side. More...
 
int NumClear ()
 Return the number of clear bits. More...
 
void Print ()
 Print contents of bitmap. More...
 
void FetchFrom (OpenFile *file)
 fetch contents from disk More...
 
void WriteBack (OpenFile *file)
 write contents to disk More...
 

Detailed Description

The following class defines a "bitmap" – an array of bits, each of which can be independently set, cleared, and tested.

Most useful for managing the allocation of the elements of an array – for instance, disk sectors, or main memory pages. Each bit represents whether the corresponding sector or page is in use or free.

Constructor & Destructor Documentation

BitMap::BitMap ( int  nitems)

Initialize a bitmap, with "nitems" bits.

BitMap::BitMap Initialize a bitmap with "nitems" bits, so that every bit is clear. it can be added somewhere on a list.

Parameters
[in]nitemsis the number of bits in the bitmap.
BitMap::~BitMap ( )

initially, all bits are cleared.

BitMap::~BitMap De-allocate a bitmap.

Member Function Documentation

void BitMap::Clear ( int  which)

Clear the "nth" bit.

BitMap::Clear Clear the "nth" bit in a bitmap.

Parameters
[in]whichis the number of the bit to be cleared.
void BitMap::FetchFrom ( OpenFile file)

fetch contents from disk

BitMap::FetchFromFile Initialize the contents of a bitmap from a Nachos file.

Parameters
[in]fileis the place to read the bitmap from
int BitMap::Find ( )

Return the # of a clear bit, and as a side.

BitMap::Find Return the number of the first bit which is clear. As a side effect, set the bit (mark it as in use). (In other words, find and allocate a bit.)

If no bits are clear, return -1.

void BitMap::Mark ( int  which)

Set the "nth" bit.

BitMap::Set Set the "nth" bit in a bitmap.

Parameters
[in]whichis the number of the bit to be set.
int BitMap::NumClear ( )

Return the number of clear bits.

BitMap::NumClear.

Returns
Return the number of clear bits in the bitmap. (In other words, how many bits are unallocated?)
void BitMap::Print ( )

Print contents of bitmap.

BitMap::Print Print the contents of the bitmap, for debugging.

Could be done in a number of ways, but we just print the #'s of all the bits that are set in the bitmap.

bool BitMap::Test ( int  which)

Is the "nth" bit set?

BitMap::Test Return TRUE if the "nth" bit is set.

Parameters
[in]whichis the number of the bit to be tested.
void BitMap::WriteBack ( OpenFile file)

write contents to disk

BitMap::WriteBack Store the contents of a bitmap to a Nachos file.

Parameters
fileis the place to write the bitmap to

The documentation for this class was generated from the following files: