Main Page   Compound List   File List   Compound Members   File Members  

bitmap.h

Go to the documentation of this file.
00001 // bitmap.h 
00002 //      Data structures defining a bitmap -- an array of bits each of which
00003 //      can be either on or off.
00004 //
00005 //      Represented as an array of unsigned integers, on which we do
00006 //      modulo arithmetic to find the bit we are interested in.
00007 //
00008 //      The bitmap can be parameterized with with the number of bits being 
00009 //      managed.
00010 //
00011 // Copyright (c) 1992-1993 The Regents of the University of California.
00012 // All rights reserved.  See copyright.h for copyright notice and limitation 
00013 // of liability and disclaimer of warranty provisions.
00014 
00015 #ifndef BITMAP_H
00016 #define BITMAP_H
00017 
00018 #include "copyright.h"
00019 #include "utility.h"
00020 #include "openfile.h"
00021 
00022 // Definitions helpful for representing a bitmap as an array of integers
00023 #define BitsInByte      8
00024 #define BitsInWord      32
00025 
00026 // The following class defines a "bitmap" -- an array of bits,
00027 // each of which can be independently set, cleared, and tested.
00028 //
00029 // Most useful for managing the allocation of the elements of an array --
00030 // for instance, disk sectors, or main memory pages.
00031 // Each bit represents whether the corresponding sector or page is
00032 // in use or free.
00033 
00034 class BitMap {
00035   public:
00036     BitMap(int nitems);         // Initialize a bitmap, with "nitems" bits
00037                                 // initially, all bits are cleared.
00038     ~BitMap();                  // De-allocate bitmap
00039     
00040     void Mark(int which);       // Set the "nth" bit
00041     void Clear(int which);      // Clear the "nth" bit
00042     bool Test(int which);       // Is the "nth" bit set?
00043     int Find();                 // Return the # of a clear bit, and as a side
00044                                 // effect, set the bit. 
00045                                 // If no bits are clear, return -1.
00046     int NumClear();             // Return the number of clear bits
00047 
00048     void Print();               // Print contents of bitmap
00049     
00050     // These aren't needed until FILESYS, when we will need to read and 
00051     // write the bitmap to a file
00052     void FetchFrom(OpenFile *file);     // fetch contents from disk 
00053     void WriteBack(OpenFile *file);     // write contents to disk
00054 
00055   private:
00056     int numBits;                        // number of bits in the bitmap
00057     int numWords;                       // number of words of bitmap storage
00058                                         // (rounded up if numBits is not a
00059                                         //  multiple of the number of bits in
00060                                         //  a word)
00061     unsigned int *map;                  // bit storage
00062 };
00063 
00064 #endif // BITMAP_H

Generated on Mon Feb 10 09:54:44 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