ATLAS Offline Software
Loading...
Searching...
No Matches
PackedArray.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4*/
11
12#ifndef CXXUTILS_PACKEDARRAY_H
13#define CXXUTILS_PACKEDARRAY_H
14
15
16#include <vector>
17#include <cstddef>
18
19
20namespace CxxUtils {
21
22
39{
40private:
41 // Type of the underlying vector holding the data.
42 typedef std::vector<unsigned int> basetype;
43
44public:
45 // Standard STL container typedefs.
46 typedef size_t size_type;
47 typedef unsigned int value_type;
48 typedef basetype::allocator_type allocator_type;
49
54 class proxy
55 {
56 public:
58 proxy (PackedArray& arr, size_type n) : m_arr (arr), m_n (n) {}
59
61 operator value_type() const { return m_arr.get (m_n); }
62
64 proxy& operator= (value_type v) { m_arr.set (m_n, v); return *this; }
65
66 private:
69
72 };
73
74
82 PackedArray (int bitsize = 8,
83 const allocator_type& allocator = allocator_type());
84
95 size_type n,
96 value_type val = 0,
97 const allocator_type& allocator = allocator_type());
98
104 void assign (size_type n, value_type u);
105
110
114 size_type size() const;
115
119 size_type max_size() const;
120
125 size_type capacity() const;
126
132 void resize (size_type sz, value_type c = 0);
133
137 bool empty() const;
138
144 void reserve (size_type n);
145
150 value_type get(size_type n) const;
151
157 void set(size_type n, value_type val);
158
168
178
187 value_type at(size_type n) const;
188
197 proxy at(size_type n);
198
206 value_type front() const;
207
215 value_type back() const;
216
224 proxy front();
225
233 proxy back();
234
239 void push_back (value_type x);
240
244 void pop_back();
245
250 void swap (PackedArray& other);
251
255 void clear();
256
263 void set_bitsize (int bitsize);
264
268 int bitsize () const;
269
270
271private:
273 int m_bitsize = 0;
274
277
280
283
286 size_t nbase (size_type n) const;
287
289 size_t tondx (size_type n) const;
290
292 int tooff (size_type n) const;
293
295 value_type doget (size_type ndx, int off) const;
296
298 void doset (size_type ndx, int off, value_type v);
299
301 void range_check (size_type n) const;
302};
303
304
305} // namespace CxxUtils
306
307
308#endif // not CXXUTILS_PACKEDARRAY_H
static Double_t sz
#define x
proxy class for representing an lvalue to an element of PackedArray.
Definition PackedArray.h:55
PackedArray & m_arr
Reference to the container referenced by the proxy.
Definition PackedArray.h:68
proxy & operator=(value_type v)
Set the element referenced by the proxy to v.
Definition PackedArray.h:64
size_type m_n
Index of the element referenced by the proxy.
Definition PackedArray.h:71
proxy(PackedArray &arr, size_type n)
Constructor, from a PackedArray and index n.
Definition PackedArray.h:58
int m_bitsize
The current bitsize of the container.
size_type size() const
Returns the number of elements in the collection.
void set_bitsize(int bitsize)
Change the bitsize of the container.
allocator_type get_allocator() const
Returns the allocator of the underlying vector.
size_t tondx(size_type n) const
Find the index in the base vector where entry starts.
void clear()
Erase all the elements in the collection.
size_type m_size
The current number of entries in the container.
value_type front() const
Access the first element in the collection as an rvalue.
value_type operator[](size_type n) const
Access an element, as an rvalue.
value_type m_mask
Mask with m_bitsize bits set.
size_type capacity() const
Returns the total number of elements that the collection can hold before needing to allocate more mem...
basetype m_vec
Underlying vector holding the data.
void range_check(size_type n) const
Check that n is in range and throw out_of_range if not.
value_type doget(size_type ndx, int off) const
Return the entry at base index ndx/offset off.
PackedArray(int bitsize=8, const allocator_type &allocator=allocator_type())
Constructor.
void doset(size_type ndx, int off, value_type v)
Set the entry at base index ndx/offset off to v.
int bitsize() const
Return the bitsize of the container.
value_type at(size_type n) const
Access an element, as an rvalue.
size_type max_size() const
Returns the size() of the largest possible collection.
void resize(size_type sz, value_type c=0)
Resizes the collection to the specified number of elements.
int tooff(size_type n) const
Find the bit offset of entry within its entry in the base vector.
value_type get(size_type n) const
Return the entry at index n.
void assign(size_type n, value_type u)
Set the container to multiple copies of the same value.
std::vector< unsigned int > basetype
Definition PackedArray.h:42
bool empty() const
Returns true if the collection is empty.
void push_back(value_type x)
Add an element to the end of the collection.
value_type back() const
Access the last element in the collection as an rvalue.
void swap(PackedArray &other)
Swap this collection with another.
void pop_back()
Remove the last element from the collection.
size_t nbase(size_type n) const
Calculate the number of entries in the base vector needed to hold entries with the current bitsize.
basetype::allocator_type allocator_type
Definition PackedArray.h:48
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
unsigned int value_type
Definition PackedArray.h:47
ConcurrentBitset & set()
Turn on all bits in the set.