Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
moab::BitPage Class Reference

bit tag data More...

#include <BitPage.hpp>

Public Member Functions

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

Private Attributes

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

Detailed Description

bit tag data

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

Definition at line 17 of file BitPage.hpp.

Constructor & Destructor Documentation

◆ BitPage()

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 22 of file BitPage.cpp.

23 { 24  unsigned char mask = (unsigned char)( 1 << per_ent ) - 1; // 2^per_ent - 1 25  init_val &= (unsigned char)mask; 26  switch( per_ent ) 27  { 28  default: 29  assert( false ); 30  abort(); 31  break; // must be power of two 32  33  // Note: fall through such that all bits in init_val are set, but with odd structure to avoid 34  // fall-through warnings 35  case 1: 36  init_val |= (unsigned char)( init_val << 1 ); 37  // fall through 38  case 2: 39  init_val |= (unsigned char)( init_val << 2 ); 40  // fall through 41  case 4: 42  init_val |= (unsigned char)( init_val << 4 ); 43  // fall through 44  case 8:; 45  } 46  memset( byteArray, init_val, BitTag::PageSize ); 47 }

References byteArray, and moab::BitTag::PageSize.

Member Function Documentation

◆ get_bits() [1/2]

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.

128 { 129  // Assume per_ent is a power of two, which should be guaranteed 130  // by higher-level code. 131  unsigned char mask = (unsigned char)( 1 << per_ent ) - 1; // 2^per_ent - 1 132  int byte = ( offset * per_ent ) >> 3; // shifting 3 is dividing by eight 133  int bit = ( offset * per_ent ) & 7; // masking with 7 is modulo eight 134  assert( byte < BitTag::PageSize ); 135  return (unsigned char)( byteArray[byte] >> bit ) & mask; 136 }

References byteArray, and moab::BitTag::PageSize.

◆ get_bits() [2/2]

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.

150 { 151  unsigned char* end = data + count; 152  while( data != end ) 153  *( data++ ) = get_bits( offset++, per_ent ); 154 }

Referenced by search().

◆ search()

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 9 of file BitPage.cpp.

11 { 12  const int end = offset + count; 13  Range::iterator hint = results.begin(); 14  while( offset != end ) 15  { 16  if( get_bits( offset, per_ent ) == value ) hint = results.insert( hint, start ); 17  ++offset; 18  ++start; 19  } 20 }

References moab::Range::begin(), get_bits(), and moab::Range::insert().

◆ set_bits() [1/3]

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.

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

References byteArray, and moab::BitTag::PageSize.

◆ set_bits() [2/3]

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.

157 { 158  const unsigned char* end = data + count; 159  while( data != end ) 160  set_bits( offset++, per_ent, *( data++ ) ); 161 }

Referenced by set_bits().

◆ set_bits() [3/3]

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.

164 { 165  int end = offset + count; 166  while( offset < end ) 167  set_bits( offset++, per_ent, value ); 168 }

References set_bits().

Member Data Documentation

◆ byteArray

char moab::BitPage::byteArray[BitTag::PageSize]
private

The actual array of bytes.

Definition at line 124 of file BitPage.hpp.

Referenced by BitPage(), get_bits(), and set_bits().


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