#include <FileMap.h>

Collaboration diagram for FileMap:

Public Member Functions

 FileMap ()
 
 ~FileMap ()
 
bool setBit (sfileno num)
 
bool testBit (sfileno num) const
 Test whether the num-th bit in the FileMap is set. More...
 
void clearBit (sfileno num)
 
sfileno allocate (sfileno suggestion)
 
int capacity () const
 return the max number of slots in the FileMap More...
 
int numFilesInMap () const
 return the number of used slots in the FileMap More...
 

Private Member Functions

void grow ()
 grow the FileMap (size is doubled each time, up to 2^24 bits) More...
 
 FileMap (const FileMap &)
 
FileMapoperator= (const FileMap &)
 

Private Attributes

sfileno capacity_
 max number of files which can be tracked in the current store More...
 
unsigned int usedSlots_
 used slots in the map More...
 
unsigned int nwords
 number of "long ints" making up the filemap More...
 
unsigned long * bitmap
 

Detailed Description

A bitmap used for managing UFS StoreEntry "file numbers".

Nth bit represents whether file number N is used. The map automatically grows to hold up to 2^24 bits. New bit is "off" or zero by default, representing unused fileno. TODO: consider using std::bitset instead.

Definition at line 23 of file FileMap.h.

Constructor & Destructor Documentation

◆ FileMap() [1/2]

FileMap::FileMap ( )

Definition at line 35 of file filemap.cc.

References bitmap, capacity_, debugs, nwords, and xcalloc().

◆ ~FileMap()

FileMap::~FileMap ( )

Definition at line 135 of file filemap.cc.

References bitmap, and safe_free.

◆ FileMap() [2/2]

FileMap::FileMap ( const FileMap )
private

Member Function Documentation

◆ allocate()

sfileno FileMap::allocate ( sfileno  suggestion)

locate an unused slot in the FileMap, possibly at or after position suggestion

Obtain the location of an unused slot in the FileMap, growing it if needed. The suggestion is only an advice; there is no guarantee that it will be followed.

Definition at line 104 of file filemap.cc.

References ALL_ONES, allocate(), bitmap, BITS_IN_A_LONG, capacity_, grow(), LONG_BIT_SHIFT, nwords, and testBit().

Referenced by allocate().

◆ capacity()

int FileMap::capacity ( ) const
inline

Definition at line 60 of file FileMap.h.

References capacity_.

◆ clearBit()

void FileMap::clearBit ( sfileno  num)

Clear the num-th bit in the FileMap

Warning
that clearBit doesn't do any bounds checking, nor it checks that the bit is set before clearing. The caller will have to ensure that both are true using testBit before clearing.

Definition at line 84 of file filemap.cc.

References bitmap, LONG_BIT_MASK, LONG_BIT_SHIFT, and usedSlots_.

◆ grow()

void FileMap::grow ( )
private

Definition at line 45 of file filemap.cc.

References assert, bitmap, capacity_, debugs, LONG_BIT_SHIFT, nwords, xcalloc(), and xfree.

Referenced by allocate(), and setBit().

◆ numFilesInMap()

int FileMap::numFilesInMap ( ) const
inline

Definition at line 63 of file FileMap.h.

References usedSlots_.

◆ operator=()

FileMap & FileMap::operator= ( const FileMap )
private

◆ setBit()

bool FileMap::setBit ( sfileno  num)

Set the num-th bit in the FileMap

Warning
FileMap's backing storage will be extended as needed to hold the representation, but if the bit is already set it will break the file number accounting, so the caller must ensure that setBit is only called if the bit is not already set, by using testBit on it before.

Definition at line 62 of file filemap.cc.

References bitmap, capacity_, grow(), LONG_BIT_MASK, LONG_BIT_SHIFT, and usedSlots_.

◆ testBit()

bool FileMap::testBit ( sfileno  num) const

Definition at line 92 of file filemap.cc.

References bitmap, capacity_, LONG_BIT_MASK, and LONG_BIT_SHIFT.

Referenced by allocate().

Member Data Documentation

◆ bitmap

unsigned long* FileMap::bitmap
private

Definition at line 76 of file FileMap.h.

Referenced by FileMap(), ~FileMap(), allocate(), clearBit(), grow(), setBit(), and testBit().

◆ capacity_

sfileno FileMap::capacity_
private

Definition at line 71 of file FileMap.h.

Referenced by FileMap(), allocate(), capacity(), grow(), setBit(), and testBit().

◆ nwords

unsigned int FileMap::nwords
private

Definition at line 75 of file FileMap.h.

Referenced by FileMap(), allocate(), and grow().

◆ usedSlots_

unsigned int FileMap::usedSlots_
private

Definition at line 73 of file FileMap.h.

Referenced by clearBit(), numFilesInMap(), and setBit().


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors