Changeset ,98

Show
Ignore:
Timestamp:
11/07/2008 04:21:27 PM (2 months ago)
Author:
Berkus <berkus@madfire.net>
branch-nick:
bzr
Message:

Clean up BitArray? and add unit-tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • vesper/src/lib/BitArray.h

    r94 r98  
    88 
    99#include "Types.h" 
     10#include "Macros.h" 
    1011 
    1112/** 
    12   An unordered array that holds its contents internally as bits. Therefore, 
    13   each element can only be of boolean type. 
    14  
    15   Unit tested: 24 Jul 07 
    16 **/ 
    17  
     13 * An unordered array that holds its contents internally as bits. Therefore, 
     14 * each element can only be of boolean type. 
     15 */ 
    1816class BitArray 
    1917{ 
    2018public: 
    21         inline static uint32_t INDEX_TO_BIT(int a)    { return a * (8*4); } 
    22         inline static uint32_t INDEX_FROM_BIT(int a)  { return a / (8*4); } 
     19    // Array dword position to bit index. 
     20    inline static uint32_t INDEX_TO_BIT(int a)    { return a * (8*4); } 
     21    // Bit to dword position in array. 
     22    inline static uint32_t INDEX_FROM_BIT(int a)  { return a / (8*4); } 
     23    // Bit to offset within dword. 
    2324        inline static uint32_t OFFSET_FROM_BIT(int a) { return a % (8*4); } 
    2425 
     
    2829        BitArray(uint32_t nbits) : N(nbits) 
    2930        { 
     31        ASSERT(N >= 32); 
    3032                table = new uint32_t [INDEX_FROM_BIT(N)]; 
    31                 clearAll(); 
     33                clear_all(); 
    3234        } 
     35 
     36    ~BitArray() 
     37    { 
     38        delete [] table; 
     39    } 
    3340 
    3441        /** 
    3542         * Clears the value of all bits in the bitmap. 
    3643         */ 
    37         void clearAll() 
     44        void clear_all() 
    3845        { 
    3946                for (uint32_t i = 0; i < INDEX_FROM_BIT(N); i++) 
     
    8087         * just looping and calling test(). 
    8188         */ 
    82         uint32_t firstClear() 
     89        uint32_t first_clear() 
    8390        { 
    8491                for (uint32_t i = 0; i < INDEX_FROM_BIT(N); i++) 
     
    104111         * just looping and calling test(). 
    105112         */ 
    106         uint32_t firstSet() 
     113        uint32_t first_set() 
    107114        { 
    108115                for (uint32_t i = 0; i < INDEX_FROM_BIT(N); i++)