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... | |
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.
moab::BitPage::BitPage | ( | int | bits_per_ent, |
unsigned char | init_val | ||
) |
Initialize memory.
bits_per_ent | Number of bits in each tag value. MUST BE A POWER OF TWO. |
init_val | The 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.
|
inline |
Get tag value.
Get one tag value.
offset | Offset 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_ent | Number of bits composing each tag value. NOTE: Must be a power of two. |
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.
|
inline |
Get tag values.
Get 'count' tag values, beginning with the one at 'offset'.
offset | Offset 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. |
count | Number of consecutive tag values to get. |
bits_per_ent | Number of bits composing each tag value. NOTE: Must be a power of two. |
data | Memory 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().
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.
value | The value to look for |
offset | The offset at which to begin searching |
count | The number of values to search |
bits_per_ent | Number of bits composing each tag value. |
results | Result list. |
start | The 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().
|
inline |
Set tag value.
Set tag value.
offset | Offset 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_ent | Number of bits composing each tag value. NOTE: Must be a power of two. |
value | The 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.
|
inline |
Set tag values.
Set 'count' tag values, beginning with the one at 'offset'.
offset | Offset 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. |
count | Number of consecutive tag values to set. |
bits_per_ent | Number of bits composing each tag value. NOTE: Must be a power of two. |
data | Memory 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().
|
inline |
Set several tag values to the same value.
Set 'count' tag values to specified value.
offset | Offset 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. |
count | Number of consecutive tag values to set. |
bits_per_ent | Number of bits composing each tag value. NOTE: Must be a power of two. |
value | The 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().
|
private |
The actual array of bytes.
Definition at line 124 of file BitPage.hpp.
Referenced by BitPage(), get_bits(), and set_bits().