23#ifndef _GEMA_SPARSE_VECTOR_H_
24#define _GEMA_SPARSE_VECTOR_H_
28#include <QVarLengthArray>
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++)
Definition gmSparseVector.h:40
QHash< int, T > _data
Hash table storing the sparse data keyed by its index.
Definition gmSparseVector.h:52
Definition gmSparseVector.h:56
QLinkedList< QPair< int, T > > _data
Linked list storing (index, value) pairs. Sorted by index.
Definition gmSparseVector.h:109
Definition gmSparseVector.h:114
QVarLengthArray< int, 1 > _index
_index[i] stores the first index of a block with continuous value given by _data[i].
Definition gmSparseVector.h:294
QVarLengthArray< T, 1 > _data
The value associated with indices _index[i] ... (_index[i+1]-1)
Definition gmSparseVector.h:295
Declaration of useful configuration definitions for the Core library.
QHash::iterator insert(const Key &key, const T &value)
int remove(const Key &key)
const T value(const Key &key) const const
QLinkedList::iterator begin()
QLinkedList::const_iterator constBegin() const const
QLinkedList::const_iterator constEnd() const const
QLinkedList::iterator end()
QLinkedList::iterator erase(QLinkedList::iterator pos)
QLinkedList::iterator insert(QLinkedList::iterator before, const T &value)
const T & at(int i) const const
QVarLengthArray::iterator begin()
QVarLengthArray::const_iterator constBegin() const const
QVarLengthArray::const_iterator constEnd() const const
QVarLengthArray::iterator end()
QVarLengthArray::iterator erase(QVarLengthArray::const_iterator begin, QVarLengthArray::const_iterator end)
void insert(int i, T &&value)
bool isEmpty() const const