Main Page   Compound List   File List   Compound Members   File Members  

BitMap Class Reference

#include <bitmap.h>

List of all members.

Public Methods

 BitMap (int nitems)
 ~BitMap ()
void Mark (int which)
void Clear (int which)
bool Test (int which)
int Find ()
int NumClear ()
void Print ()
void FetchFrom (OpenFile *file)
void WriteBack (OpenFile *file)

Private Attributes

int numBits
int numWords
unsigned int * map


Constructor & Destructor Documentation

BitMap::BitMap int    nitems
 

Definition at line 20 of file bitmap.cc.

References BitsInWord, Clear, divRoundUp, map, numBits, and numWords.

00021 { 
00022     numBits = nitems;
00023     numWords = divRoundUp(numBits, BitsInWord);
00024     map = new unsigned int[numWords];
00025     for (int i = 0; i < numBits; i++) 
00026         Clear(i);
00027 }

BitMap::~BitMap  
 

Definition at line 34 of file bitmap.cc.

References map.

00035 { 
00036     delete map;
00037 }


Member Function Documentation

void BitMap::Clear int    which
 

Definition at line 61 of file bitmap.cc.

References ASSERT, BitsInWord, map, and numBits.

Referenced by BitMap, FileHeader::Deallocate, and FileSystem::Remove.

00062 {
00063     ASSERT(which >= 0 && which < numBits);
00064     map[which / BitsInWord] &= ~(1 << (which % BitsInWord));
00065 }

void BitMap::FetchFrom OpenFile   file
 

Definition at line 149 of file bitmap.cc.

References map, numWords, and OpenFile::ReadAt.

Referenced by FileSystem::Create, FileSystem::Print, and FileSystem::Remove.

00150 {
00151     file->ReadAt((char *)map, numWords * sizeof(unsigned), 0);
00152 }

int BitMap::Find  
 

Definition at line 95 of file bitmap.cc.

References Mark, numBits, and Test.

Referenced by FileHeader::Allocate, and FileSystem::Create.

00096 {
00097     for (int i = 0; i < numBits; i++)
00098         if (!Test(i)) {
00099             Mark(i);
00100             return i;
00101         }
00102     return -1;
00103 }

void BitMap::Mark int    which
 

Definition at line 47 of file bitmap.cc.

References ASSERT, BitsInWord, map, and numBits.

Referenced by FileSystem::FileSystem, and Find.

00048 { 
00049     ASSERT(which >= 0 && which < numBits);
00050     map[which / BitsInWord] |= 1 << (which % BitsInWord);
00051 }

int BitMap::NumClear  
 

Definition at line 112 of file bitmap.cc.

References numBits, and Test.

Referenced by FileHeader::Allocate.

00113 {
00114     int count = 0;
00115 
00116     for (int i = 0; i < numBits; i++)
00117         if (!Test(i)) count++;
00118     return count;
00119 }

void BitMap::Print  
 

Definition at line 130 of file bitmap.cc.

References numBits, and Test.

Referenced by FileSystem::FileSystem, and FileSystem::Print.

00131 {
00132     printf("Bitmap set:\n"); 
00133     for (int i = 0; i < numBits; i++)
00134         if (Test(i))
00135             printf("%d, ", i);
00136     printf("\n"); 
00137 }

bool BitMap::Test int    which
 

Definition at line 75 of file bitmap.cc.

References ASSERT, BitsInWord, FALSE, map, numBits, and TRUE.

Referenced by FileHeader::Deallocate, Find, NumClear, and Print.

00076 {
00077     ASSERT(which >= 0 && which < numBits);
00078     
00079     if (map[which / BitsInWord] & (1 << (which % BitsInWord)))
00080         return TRUE;
00081     else
00082         return FALSE;
00083 }

void BitMap::WriteBack OpenFile   file
 

Definition at line 162 of file bitmap.cc.

References map, numWords, and OpenFile::WriteAt.

Referenced by FileSystem::Create, FileSystem::FileSystem, and FileSystem::Remove.

00163 {
00164    file->WriteAt((char *)map, numWords * sizeof(unsigned), 0);
00165 }


Member Data Documentation

unsigned int* BitMap::map [private]
 

Definition at line 61 of file bitmap.h.

Referenced by BitMap, Clear, FetchFrom, Mark, Test, WriteBack, and ~BitMap.

int BitMap::numBits [private]
 

Definition at line 56 of file bitmap.h.

Referenced by BitMap, Clear, Find, Mark, NumClear, Print, and Test.

int BitMap::numWords [private]
 

Definition at line 57 of file bitmap.h.

Referenced by BitMap, FetchFrom, and WriteBack.


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 09:54:53 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees