23 #ifndef _GEMA_SPARSE_VECTOR_H_ 24 #define _GEMA_SPARSE_VECTOR_H_ 28 #include <QVarLengthArray> 30 #include <QLinkedList> 31 #include <QtAlgorithms> 42 const T at(
int index,
const T& defValue)
const {
return _data.
value(index, defValue); }
44 void insert(
int index,
const T& val) {
_data.
insert(index, val); }
46 void remove(
int index,
const T& defValue) { Q_UNUSED(defValue);
_data.
remove(index); }
48 void clear(
int n,
const T& defVal) { Q_UNUSED(n); Q_UNUSED(defVal);
_data.
clear(); }
58 const T at(
int index,
const T& defValue)
const 63 if(it->
first == index)
65 else if(it->
first > index)
71 void insert(
int index,
const T& val)
76 if(it->
first == index)
81 else if(it->
first > index)
90 void remove(
int index,
const T& defValue)
96 if(it->
first == index)
101 else if(it->
first > index)
106 void clear(
int n,
const T& defVal) { Q_UNUSED(n); Q_UNUSED(defVal);
_data.
clear(); }
121 const T at(
int index,
const T& defValue)
const 124 assert(index >= 0 && index < *(
_index.
end()-1));
144 void insert(
int index,
const T& val)
146 assert(index >= 0 && index <= *(
_index.
end()-1));
162 #if defined ENABLE_TESTS || defined ENABLE_SPARSE_TESTS 163 validateInternalStructure();
177 if(
_data[itPos] == val)
182 if(*(it+1) == index + 1)
189 if(itPos > 0 &&
_data[itPos - 1] == val)
205 else if(itPos > 0 &&
_data[itPos - 1] == val)
221 if(itPos == 0 ||
_data[itPos-1] != val)
233 if(
_data[itPos-1] == val)
260 #if defined ENABLE_TESTS || defined ENABLE_SPARSE_TESTS 261 validateInternalStructure();
265 void remove(
int index,
const T& defValue) { insert(index, defValue); }
267 void clear(
int n,
const T& defVal)
274 #if defined ENABLE_TESTS || defined ENABLE_SPARSE_TESTS 275 validateInternalStructure();
279 #if defined ENABLE_TESTS || defined ENABLE_SPARSE_TESTS 280 void validateInternalStructure()
288 for(
int i = 1, n =
_data.
size(); i<n; i++)
const T & at(int i) const const
Definition: gmSparseVector.h:113
QHash::iterator insert(const Key &key, const T &value)
QLinkedList::iterator erase(QLinkedList::iterator pos)
QVarLengthArray::iterator begin()
QVarLengthArray< int, 1 > _index
_index[i] stores the first index of a block with continuous value given by _data[i].
Definition: gmSparseVector.h:294
QLinkedList::iterator begin()
Declaration of usefull configuration definitions for the Core library.
QLinkedList< QPair< int, T > > _data
Linked list storing (index, value) pairs. Sorted by index.
Definition: gmSparseVector.h:109
QLinkedList::iterator insert(QLinkedList::iterator before, const T &value)
QVarLengthArray::const_iterator constEnd() const const
QHash< int, T > _data
Hash table storing the sparse data keyed by its index.
Definition: gmSparseVector.h:52
QLinkedList::iterator end()
Definition: gmSparseVector.h:39
QVarLengthArray< T, 1 > _data
The value associated with indices _index[i] ... (_index[i+1]-1)
Definition: gmSparseVector.h:295
QVarLengthArray::const_iterator constBegin() const const
QVarLengthArray::iterator erase(QVarLengthArray::const_iterator begin, QVarLengthArray::const_iterator end)
int remove(const Key &key)
const T value(const Key &key) const const
bool isEmpty() const const
QVarLengthArray::iterator end()
QLinkedList::const_iterator constBegin() const const
QLinkedList::const_iterator constEnd() const const
Definition: gmSparseVector.h:55
void insert(int i, T &&value)