|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.kernel.filesys.BitMap
public class BitMap
This 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. We represent a bitmap as an array of unsigned integers, on which we do modulo arithmetic to find the bit we are interested in. The bitmap can be parameterized by the number of bits being managed. It is also equipped with fetchFrom() and writeBack() methods for reading a bitmap from, and writing a bit map to, a Nachos file.
Field Summary | |
---|---|
(package private) static int |
BitsInByte
Number of bits in a byte. |
private static int |
BitsInWord
Number of bytes in an integer. |
private int[] |
map
Bit storage. |
private int |
numBits
Number of bits in the bitmap. |
private int |
numWords
Number of words of bitmap storage (rounded up if numBits is not a multiple of the number of bits in a word). |
Constructor Summary | |
---|---|
BitMap(int nitems)
Initialize a bitmap with "nitems" bits, so that every bit is clear. |
Method Summary | |
---|---|
void |
clear(int which)
Clear the "nth" bit in a bitmap. |
void |
fetchFrom(OpenFile file)
Initialize the contents of a bitmap from a Nachos file. |
int |
find()
Find the first bit that is clear. |
void |
mark(int which)
Set the "nth" bit in a bitmap. |
int |
numClear()
Return the number of clear bits in the bitmap. |
void |
print()
Print the contents of the bitmap, for debugging. |
boolean |
test(int which)
Test if the "nth" bit is set. |
void |
writeBack(OpenFile file)
Store the contents of a bitmap to a Nachos file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final int BitsInByte
private static final int BitsInWord
private int numBits
private int numWords
private int[] map
Constructor Detail |
---|
public BitMap(int nitems)
nitems
- The number of bits in the bitmap.Method Detail |
---|
public void mark(int which)
which
- The number of the bit to be set.public void clear(int which)
which
- The number of the bit to be cleared.public boolean test(int which)
which
- The number of the bit to be tested.
public int find()
public int numClear()
public void print()
public void fetchFrom(OpenFile file)
file
- The file to read the bitmap from.public void writeBack(OpenFile file)
file
- The file to write the bitmap to.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |