Skip to content

Instantly share code, notes, and snippets.

@sorki
Created December 9, 2009 16:01
Show Gist options
  • Save sorki/252557 to your computer and use it in GitHub Desktop.
Save sorki/252557 to your computer and use it in GitHub Desktop.
#include<vector>
#include<iterator>
//#include "exceptions.h"
using namespace std;
template <class I, class T>
class SparseArray {
private:
vector<pair<I, T> > values;
bool exists(I position);
bool allowOverwrite;
public:
// SparseArray();
T getValue(I position);
void setValue(I position, T value);
void setAllowOverwrite (bool allow) { this->allowOverwrite = allow; }
bool getAllowOverwrite () { return this->allowOverwrite; }
typename vector<pair <I, T> >::iterator begin();
typename vector<pair <I, T> >::iterator end();
};
template <class I, class T>
void SparseArray<I,T>::setValue(I position, T value) {
this->values.push_back(make_pair(position,value));
}
template <class I, class T>
typename vector<pair <I, T> >::iterator SparseArray<I,T>::begin() {
//return this->values.begin();
//return iterator(this->values, this->values.begin());
return iterator<I, T>::iterator(this->values, this->values.begin());
}
template <class I, class T>
typename vector<pair <I, T> >::iterator SparseArray<I,T>::end() {
// return iterator(this->values, this->values.end());
return iterator<I, T>::iterator(this->values, this->values.end());
}
template <class I, class T>
bool SparseArray<I,T>::exists(I position) {
// vectoriterator = this->begin();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment