moab
moab::BitPage Class Reference

bit tag data More...

#include <BitPage.hpp>

List of all members.

Public Member Functions

 BitPage (int bits_per_ent, unsigned char init_val)
 Initialize memory.
void get_bits (int offset, int count, int bits_per_ent, unsigned char *data) const
 Get tag values.
void set_bits (int offset, int count, int bits_per_ent, const unsigned char *data)
 Set tag values.
void set_bits (int offset, int count, int bits_per_ent, unsigned char value)
 Set several tag values to the same value.
unsigned char get_bits (int offset, int bits_per_ent) const
 Get tag value.
void set_bits (int offset, int bits_per_ent, unsigned char data)
 Set tag value.
void search (unsigned char value, int offset, int count, int bits_per_ent, Range &results, EntityHandle start) const
 Search stored values for specified value.

Private Attributes

char byteArray [BitTag::PageSize]
 The actual array of bytes.

Detailed Description

bit tag data

This class represents a fixed-size block of memory in which bit tag values are stored.

Definition at line 16 of file BitPage.hpp.


Constructor & Destructor Documentation

moab::BitPage::BitPage ( int  bits_per_ent,
unsigned char  init_val 
)

Initialize memory.

Parameters:
bits_per_entNumber of bits in each tag value. MUST BE A POWER OF TWO.
init_valThe lower bits_per_ent bits of this byte are used to initialize each tag value.

Definition at line 21 of file BitPage.cpp.

{
  unsigned char mask = (unsigned char)(1<<per_ent)-1; // 2^per_ent - 1
  init_val &= (unsigned char)mask;
  switch (per_ent) {
    default: assert(false); abort(); break; // must be power of two
      // Note: no breaks. fall through such that all bits in init_val are set
    case 1: init_val |= (unsigned char)(init_val << 1);
    case 2: init_val |= (unsigned char)(init_val << 2);
    case 4: init_val |= (unsigned char)(init_val << 4);
    case 8: ;
  }
  memset( byteArray, init_val, BitTag::PageSize );
}

Member Function Documentation

void moab::BitPage::get_bits ( int  offset,
int  count,
int  bits_per_ent,
unsigned char *  data 
) const [inline]

Get tag values.

Get 'count' tag values, beginning with the one at 'offset'.

Parameters:
offsetOffset into list of values, where a value of zero indicates the first tag value, a value of one indicates the second tag value, etc. NOTE: This is the value offset, not the bit offset.
countNumber of consecutive tag values to get.
bits_per_entNumber of bits composing each tag value. NOTE: Must be a power of two.
dataMemory into which to copy tag values. Each value is copied into a separate byte, such that the lower bits of the bit contain the tag value and any unused higher bits are zero.

Definition at line 149 of file BitPage.hpp.

{
  unsigned char* end = data+count;
  while (data != end)
    *(data++) = get_bits( offset++, per_ent );
}
unsigned char moab::BitPage::get_bits ( int  offset,
int  bits_per_ent 
) const [inline]

Get tag value.

Get one tag value.

Parameters:
offsetOffset into list of values, where a value of zero indicates the first tag value, a value of one indicates the second tag value, etc. NOTE: This is the value offset, not the bit offset.
bits_per_entNumber of bits composing each tag value. NOTE: Must be a power of two.
Returns:
A byte containing the tag value in the lower bits with any unused higher bits zeroed.

Definition at line 127 of file BitPage.hpp.

{
    // Assume per_ent is a power of two, which should be guaranteed
    // by higher-level code.
  unsigned char mask = (unsigned char)(1<<per_ent)-1; // 2^per_ent - 1
  int byte = (offset * per_ent) >> 3; // shifting 3 is dividing by eight
  int bit =  (offset * per_ent) & 7;  // masking with 7 is modulo eight
  assert(byte < BitTag::PageSize);
  return (unsigned char)(byteArray[byte] >> bit) & mask;
} 
void moab::BitPage::search ( unsigned char  value,
int  offset,
int  count,
int  bits_per_ent,
Range results,
EntityHandle  start 
) const

Search stored values for specified value.

Find the offsets n in the data at which the specified value occurs, and for each one insert 'start + n' into the passed Range.

Parameters:
valueThe value to look for
offsetThe offset at which to begin searching
countThe number of values to search
bits_per_entNumber of bits composing each tag value.
resultsResult list.
startThe handle of the entity corresponding to the tag value stored at 'offset'

Definition at line 8 of file BitPage.cpp.

{
  const int end = offset + count;
  Range::iterator hint = results.begin();
  while (offset != end) {
    if (get_bits( offset, per_ent ) == value)
      hint = results.insert( hint, start );
    ++offset;
    ++start;
  }
}
void moab::BitPage::set_bits ( int  offset,
int  count,
int  bits_per_ent,
const unsigned char *  data 
) [inline]

Set tag values.

Set 'count' tag values, beginning with the one at 'offset'.

Parameters:
offsetOffset into list of values, where a value of zero indicates the first tag value, a value of one indicates the second tag value, etc. NOTE: This is the value offset, not the bit offset.
countNumber of consecutive tag values to set.
bits_per_entNumber of bits composing each tag value. NOTE: Must be a power of two.
dataMemory from which to copy tag values. Each value is copied from a separate byte. The lower 'bits_per_ent' of each byte are used as the tag value. Any additional higher bits are ignored.

Definition at line 156 of file BitPage.hpp.

{
  const unsigned char* end = data+count;
  while (data != end)
    set_bits( offset++, per_ent, *(data++) );
}
void moab::BitPage::set_bits ( int  offset,
int  count,
int  bits_per_ent,
unsigned char  value 
) [inline]

Set several tag values to the same value.

Set 'count' tag values to specified value.

Parameters:
offsetOffset into list of values, where a value of zero indicates the first tag value, a value of one indicates the second tag value, etc. NOTE: This is the value offset, not the bit offset.
countNumber of consecutive tag values to set.
bits_per_entNumber of bits composing each tag value. NOTE: Must be a power of two.
valueThe lower 'bits_per_ent' of this byte are used as the tag value. Any additional higher bits are ignored.

Definition at line 163 of file BitPage.hpp.

{
  int end = offset + count;
  while (offset < end)
    set_bits( offset++, per_ent, value );
}
void moab::BitPage::set_bits ( int  offset,
int  bits_per_ent,
unsigned char  data 
) [inline]

Set tag value.

Set tag value.

Parameters:
offsetOffset into list of values, where a value of zero indicates the first tag value, a value of one indicates the second tag value, etc. NOTE: This is the value offset, not the bit offset.
bits_per_entNumber of bits composing each tag value. NOTE: Must be a power of two.
valueThe lower 'bits_per_ent' of this byte are used as the tag value. Any additional higher bits are ignored.

Definition at line 138 of file BitPage.hpp.

{
  int byte = (offset * per_ent) >> 3; // shifting 3 is dividing by eight
  int bit =  (offset * per_ent) & 7;  // masking with 7 is modulo eight
  assert(byte < BitTag::PageSize);
    // Assume per_ent is a power of two, which should be guaranteed
    // by higher-level code.
  unsigned char mask = (unsigned char)((1<<per_ent)-1) << bit;
  byteArray[byte] = (char)((byteArray[byte] & ~mask) | ((bits << bit) & mask));
} 

Member Data Documentation

The actual array of bytes.

Definition at line 124 of file BitPage.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines