1 #ifndef _DATA_VINT_VECTOR_H_
2 #define _DATA_VINT_VECTOR_H_
37 set_num_bytes(
sizeof(uint64_t));
47 set_num_bytes(num_bytes);
67 for(vector<uint8_t>::const_iterator i = v.
data.begin(); i != v.
data.end(); i++)
80 assert((num_bytes >= 1) && (num_bytes <= (
int)
sizeof(uint64_t)));
84 num_bytes_ = (int8_t)num_bytes;
87 while(--num_bytes > 0) mask = ((mask << 8) | 0xFF);
95 return (
int)num_bytes_;
103 return (
int)data.size();
113 assert(((index * num_bytes_) +
sizeof(uint64_t)) <= data.size());
114 return (*((uint64_t *)&(data[index * (
int)num_bytes_])) & mask);
123 data.insert(data.end(), data.size() <= 0 ?
sizeof(uint64_t) : (
int)num_bytes_, 0);
124 *((uint64_t *)&(data[data.size() -
sizeof(uint64_t)])) = value;
140 return max(0, (((
int)data.size() - (int)
sizeof(uint64_t)) / (
int)num_bytes_) + 1);
148 assert(data.size() >=
sizeof(uint64_t));
149 return *((uint64_t *)&(data[data.size() -
sizeof(uint64_t)]));
void clear()
Clears the content.
Definition: vint_vector.h:130
const vint_vector & operator=(const vint_vector &v)
Copy assignment.
Definition: vint_vector.h:61
This class has been implemented with the same philosophy that the class STL vector, but specifically designed to store integers with a length in bytes that can be not multiple from 2 (e.g.
Definition: vint_vector.h:24
vint_vector(const vint_vector &v)
Copy constructor.
Definition: vint_vector.h:53
int8_t num_bytes_
Number of bytes used for the integers.
Definition: vint_vector.h:28
vector< uint8_t > data
Definition: vint_vector.h:29
int size() const
Returns the size of the vector, in number of items.
Definition: vint_vector.h:138
vint_vector()
Initializes the vector to store 64-bit integers.
Definition: vint_vector.h:35
uint64_t mask
Mask used for accessing the data.
Definition: vint_vector.h:27
void set_num_bytes(int num_bytes)
Changes the number of bytes of the integer values.
Definition: vint_vector.h:78
virtual ~vint_vector()
Definition: vint_vector.h:152
void push_back(uint64_t value)
Adds a new item to the end of the vector.
Definition: vint_vector.h:121
vint_vector(int num_bytes)
Initializes the vector to store integers with the number of bytes given as parameter.
Definition: vint_vector.h:45
uint64_t operator[](int index) const
Operator overloading for indexing the integer values.
Definition: vint_vector.h:111
int data_bytes() const
Returns the current number of bytes stored.
Definition: vint_vector.h:101
uint64_t & back()
Return the reference of the last item of the vector.
Definition: vint_vector.h:146
int num_bytes() const
Returns the number of bytes used.
Definition: vint_vector.h:93