ATLAS Offline Software
|
An array of unsigned values of some bit size, packed tightly. More...
#include <PackedArray.h>
Classes | |
class | proxy |
proxy class for representing an lvalue to an element of PackedArray . More... | |
Public Types | |
typedef size_t | size_type |
typedef unsigned int | value_type |
typedef basetype::allocator_type | allocator_type |
Public Member Functions | |
PackedArray (int bitsize=8, const allocator_type &allocator=allocator_type()) | |
Constructor. More... | |
PackedArray (int bitsize, size_type n, value_type val=0, const allocator_type &allocator=allocator_type()) | |
Constructor. More... | |
void | assign (size_type n, value_type u) |
Set the container to multiple copies of the same value. More... | |
allocator_type | get_allocator () const |
Returns the allocator of the underlying vector. More... | |
size_type | size () const |
Returns the number of elements in the collection. More... | |
size_type | max_size () const |
Returns the size() of the largest possible collection. More... | |
size_type | capacity () const |
Returns the total number of elements that the collection can hold before needing to allocate more memory. More... | |
void | resize (size_type sz, value_type c=0) |
Resizes the collection to the specified number of elements. More... | |
bool | empty () const |
Returns true if the collection is empty. More... | |
void | reserve (size_type n) |
Attempt to preallocate enough memory for a specified number of elements. More... | |
value_type | get (size_type n) const |
Return the entry at index n . More... | |
void | set (size_type n, value_type val) |
Set the entry at index n . More... | |
value_type | operator[] (size_type n) const |
Access an element, as an rvalue. More... | |
proxy | operator[] (size_type n) |
Access an element, as an lvalue. More... | |
value_type | at (size_type n) const |
Access an element, as an rvalue. More... | |
proxy | at (size_type n) |
Access an element, as an lvalue. More... | |
value_type | front () const |
Access the first element in the collection as an rvalue. More... | |
value_type | back () const |
Access the last element in the collection as an rvalue. More... | |
proxy | front () |
Access the first element in the collection as an lvalue. More... | |
proxy | back () |
Access the last element in the collection as an lvalue. More... | |
void | push_back (value_type x) |
Add an element to the end of the collection. More... | |
void | pop_back () |
Remove the last element from the collection. More... | |
void | swap (PackedArray &other) |
Swap this collection with another. More... | |
void | clear () |
Erase all the elements in the collection. More... | |
void | set_bitsize (int bitsize) |
Change the bitsize of the container. More... | |
int | bitsize () const |
Return the bitsize of the container. More... | |
Private Types | |
typedef std::vector< unsigned int > | basetype |
Private Member Functions | |
size_t | nbase (size_type n) const |
Calculate the number of entries in the base vector needed to hold entries with the current bitsize. More... | |
size_t | tondx (size_type n) const |
Find the index in the base vector where entry starts. More... | |
int | tooff (size_type n) const |
Find the bit offset of entry within its entry in the base vector. More... | |
value_type | doget (size_type ndx, int off) const |
Return the entry at base index ndx/offset off . More... | |
void | doset (size_type ndx, int off, value_type v) |
Set the entry at base index ndx/offset off to v . More... | |
void | range_check (size_type n) const |
Check that n is in range and throw out_of_range if not. More... | |
Private Attributes | |
int | m_bitsize |
The current bitsize of the container. More... | |
size_type | m_size |
The current number of entries in the container. More... | |
value_type | m_mask |
Mask with m_bitsize bits set. More... | |
basetype | m_vec |
Underlying vector holding the data. More... | |
An array of unsigned values of some bit size, packed tightly.
When creating an instance of this class, specify the bit size of the entries. The entries will be packed so that each takes exactly that many bits. For example, if the bit size is 10, 16 entries will be packed into 5 32-bit words. The bitsize may be changed, but only if the container is empty.
Any values assigned to the array that are too large to be represented in the specified number of bits will have the high bits silently dropped.
The interface is modeled after std::vector
, except that there are no iterators. They could be added if there is a need for them.
Definition at line 41 of file PackedArray.h.
typedef basetype::allocator_type CxxUtils::PackedArray::allocator_type |
Definition at line 51 of file PackedArray.h.
|
private |
Definition at line 45 of file PackedArray.h.
typedef size_t CxxUtils::PackedArray::size_type |
Definition at line 49 of file PackedArray.h.
typedef unsigned int CxxUtils::PackedArray::value_type |
Definition at line 50 of file PackedArray.h.
CxxUtils::PackedArray::PackedArray | ( | int | bitsize = 8 , |
const allocator_type & | allocator = allocator_type() |
||
) |
Constructor.
bitsize | The size, in bits, of each element. Must be greater than zero, and not larger than the size of an unsigned int. |
allocator | Allocator for the underlying vector. |
Definition at line 143 of file PackedArray.cxx.
CxxUtils::PackedArray::PackedArray | ( | int | bitsize, |
size_type | n, | ||
value_type | val = 0 , |
||
const allocator_type & | allocator = allocator_type() |
||
) |
Constructor.
bitsize | The size, in bits, of each element. Must be greater than zero, and not larger than the size of an unsigned int. |
n | Initial number of entries in the container. |
val | Value to which the initial entries are to be set. |
allocator | Allocator for the underlying vector. |
Definition at line 163 of file PackedArray.cxx.
void CxxUtils::PackedArray::assign | ( | size_type | n, |
value_type | u | ||
) |
Set the container to multiple copies of the same value.
n | Number of entries to which the container is to be set. |
u | Value to which the entries are to be set. |
n | Number of entries to which the container is to be set. |
val | Value to which the entries are to be set. |
Definition at line 185 of file PackedArray.cxx.
PackedArray::proxy CxxUtils::PackedArray::at | ( | size_type | n | ) |
Access an element, as an lvalue.
n | Array index to access. |
Will raise std::out_of_range
if the index is out-of-bounds. Note that we return a proxy object rather than a reference.
Definition at line 360 of file PackedArray.cxx.
PackedArray::value_type CxxUtils::PackedArray::at | ( | size_type | n | ) | const |
Access an element, as an rvalue.
n | Array index to access. |
Will raise std::out_of_range
if the index is out-of-bounds. Note that we return a value_type
rather than a reference.
Definition at line 345 of file PackedArray.cxx.
PackedArray::proxy CxxUtils::PackedArray::back | ( | ) |
Access the last element in the collection as an lvalue.
No checking is done to ensure that the container is not empty. Note that we return a proxy object rather than a reference.
Definition at line 413 of file PackedArray.cxx.
PackedArray::value_type CxxUtils::PackedArray::back | ( | ) | const |
Access the last element in the collection as an rvalue.
No checking is done to ensure that the container is not empty. Note that we return a value_type
rather than a reference.
Definition at line 387 of file PackedArray.cxx.
int CxxUtils::PackedArray::bitsize | ( | ) | const |
Return the bitsize of the container.
Definition at line 486 of file PackedArray.cxx.
PackedArray::size_type CxxUtils::PackedArray::capacity | ( | ) | const |
Returns the total number of elements that the collection can hold before needing to allocate more memory.
Definition at line 228 of file PackedArray.cxx.
void CxxUtils::PackedArray::clear | ( | ) |
Erase all the elements in the collection.
Definition at line 461 of file PackedArray.cxx.
|
inlineprivate |
Return the entry at base index ndx/offset
off
.
ndx | Index of the entry in the base vector at which the packed entry starts. |
off | Bit offset within that entry where the packed entry starts. |
Definition at line 83 of file PackedArray.cxx.
|
inlineprivate |
Set the entry at base index ndx/offset
off
to v
.
Set the entry at base index ndx/offset
off
.
ndx | Index of the entry in the base vector at which the packed entry starts. |
off | Bit offset within that entry where the packed entry starts. |
v | Value to which the entry should be set. |
Definition at line 110 of file PackedArray.cxx.
bool CxxUtils::PackedArray::empty | ( | ) | const |
Returns true
if the collection is empty.
Definition at line 271 of file PackedArray.cxx.
PackedArray::proxy CxxUtils::PackedArray::front | ( | ) |
Access the first element in the collection as an lvalue.
No checking is done to ensure that the container is not empty. Note that we return a proxy object rather than a reference.
Definition at line 400 of file PackedArray.cxx.
PackedArray::value_type CxxUtils::PackedArray::front | ( | ) | const |
Access the first element in the collection as an rvalue.
No checking is done to ensure that the container is not empty. Note that we return a value_type
rather than a reference.
Definition at line 374 of file PackedArray.cxx.
PackedArray::value_type CxxUtils::PackedArray::get | ( | size_type | n | ) | const |
PackedArray::allocator_type CxxUtils::PackedArray::get_allocator | ( | ) | const |
Returns the allocator of the underlying vector.
Definition at line 200 of file PackedArray.cxx.
PackedArray::size_type CxxUtils::PackedArray::max_size | ( | ) | const |
Returns the size()
of the largest possible collection.
Definition at line 218 of file PackedArray.cxx.
|
inlineprivate |
Calculate the number of entries in the base vector needed to hold
entries with the current bitsize.
n | Number of packed entries desired. |
Definition at line 48 of file PackedArray.cxx.
PackedArray::proxy CxxUtils::PackedArray::operator[] | ( | size_type | n | ) |
Access an element, as an lvalue.
n | Array index to access. |
No bounds checking is done. Note that we return a proxy object rather than a reference.
Definition at line 331 of file PackedArray.cxx.
PackedArray::value_type CxxUtils::PackedArray::operator[] | ( | size_type | n | ) | const |
Access an element, as an rvalue.
n | Array index to access. |
No bounds checking is done. Note that we return a value_type
rather than a reference.
Definition at line 317 of file PackedArray.cxx.
void CxxUtils::PackedArray::pop_back | ( | ) |
void CxxUtils::PackedArray::push_back | ( | value_type | x | ) |
Add an element to the end of the collection.
x | The element to add to the collection. |
Definition at line 423 of file PackedArray.cxx.
|
private |
Check that n
is in range and throw out_of_range
if not.
n | Index to check. |
Definition at line 128 of file PackedArray.cxx.
void CxxUtils::PackedArray::reserve | ( | size_type | n | ) |
Attempt to preallocate enough memory for a specified number of elements.
n | Number of elements required. |
Definition at line 282 of file PackedArray.cxx.
void CxxUtils::PackedArray::resize | ( | size_type | sz, |
value_type | c = 0 |
||
) |
Resizes the collection to the specified number of elements.
sz | The new size of the collection. |
c | Value to which any new elements are to be set. |
Definition at line 239 of file PackedArray.cxx.
void CxxUtils::PackedArray::set | ( | size_type | n, |
value_type | val | ||
) |
void CxxUtils::PackedArray::set_bitsize | ( | int | bitsize | ) |
Change the bitsize of the container.
bitsize The new bitsize.
This method may only be called when the container is empty.
Definition at line 474 of file PackedArray.cxx.
PackedArray::size_type CxxUtils::PackedArray::size | ( | ) | const |
Returns the number of elements in the collection.
Definition at line 209 of file PackedArray.cxx.
void CxxUtils::PackedArray::swap | ( | PackedArray & | other | ) |
Swap this collection with another.
other | The collection with which to swap. |
Definition at line 449 of file PackedArray.cxx.
|
inlineprivate |
Find the index in the base vector where entry
starts.
n | Packed entry desired. |
Definition at line 59 of file PackedArray.cxx.
|
inlineprivate |
Find the bit offset of entry
within its entry in the base vector.
n | Packed entry desired. |
Definition at line 70 of file PackedArray.cxx.
|
private |
The current bitsize of the container.
Definition at line 276 of file PackedArray.h.
|
private |
Mask with m_bitsize bits set.
Definition at line 282 of file PackedArray.h.
|
private |
The current number of entries in the container.
Definition at line 279 of file PackedArray.h.
|
private |
Underlying vector holding the data.
Definition at line 285 of file PackedArray.h.