Skip to content

Commit

Permalink
much simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
kosloot committed Jul 3, 2023
1 parent a6dc3fa commit 0d8d194
Showing 1 changed file with 56 additions and 64 deletions.
120 changes: 56 additions & 64 deletions include/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,92 +534,84 @@ class PatternVector { //acts like a (small) map (but implemented as a vector to

PatternVector() {};

PatternVector(const PatternVector & ref) {
for ( const auto& pfv_ref : ref.data ){
//make a copy
Pattern *pfv = new Pattern(pfv_ref);
this->data.push_back(*pfv);
}
PatternVector( const PatternVector& ref ) {
data = ref.data;
}

PatternVector& operator=( const PatternVector & ref) {
PatternVector& operator=( const PatternVector& ref ) {
if ( this != &ref ){
for ( const auto& pfv_ref : ref.data ){
//make a copy
Pattern *pfv = new Pattern(pfv_ref);
this->data.push_back(*pfv);
}
data = ref.data;
}
return *this;
}

virtual ~PatternVector() {
}
bool has(const Pattern & ref) const {
for (const_iterator iter = this->begin(); iter != this->end(); ++iter) {
if (*iter == ref) {
return true;
}
}
return false;
}

bool has(const Pattern & ref) const {
for (const_iterator iter = this->begin(); iter != this->end(); ++iter) {
if (*iter == ref) {
return true;
}
}
return false;
}

iterator find(const Pattern & ref) {
for (iterator iter = this->begin(); iter != this->end(); ++iter) {
if (*iter == ref) {
return iter;
}
}
return this->end();
}

unsigned int count() const { return data.size(); }
iterator find(const Pattern & ref) {
for (iterator iter = this->begin(); iter != this->end(); ++iter) {
if (*iter == ref) {
return iter;
}
}
return this->end();
}

unsigned int count() const { return data.size(); }


void insert(const Pattern & pattern, bool checkexists=true) {
//make a copy, safer
if (checkexists) {
iterator found = this->find(pattern);
if (found == this->end()) {
this->data.push_back(pattern);
}
} else {
this->data.push_back(pattern);
}
}

size_t size() const { return data.size(); }
void insert(const Pattern & pattern, bool checkexists=true) {
//make a copy, safer
if (checkexists) {
iterator found = this->find(pattern);
if (found == this->end()) {
this->data.push_back(pattern);
}
} else {
this->data.push_back(pattern);
}
}

virtual std::string tostring() {
//we have no classdecoder at this point
std::cerr << "ERROR: PatternFeatureVector does not support serialisation to string" << std::endl;
throw InternalError();
}
size_t size() const { return data.size(); }

iterator begin() { return data.begin(); }
const_iterator begin() const { return data.begin(); }
virtual std::string tostring() {
//we have no classdecoder at this point
std::cerr << "ERROR: PatternFeatureVector does not support serialisation to string" << std::endl;
throw InternalError();
}

iterator end() { return data.end(); }
const_iterator end() const { return data.end(); }
iterator begin() { return data.begin(); }
const_iterator begin() const { return data.begin(); }

virtual Pattern * getdata(const Pattern & pattern) {
iterator iter = this->find(pattern);
if (iter != this->end()) {
Pattern * p = &(*iter);
return p;
}
return NULL;
}
iterator end() { return data.end(); }
const_iterator end() const { return data.end(); }

void reserve(size_t size) {
data.reserve(size);
}
void shrink_to_fit() {
data.shrink_to_fit();
}
virtual Pattern * getdata(const Pattern & pattern) {
iterator iter = this->find(pattern);
if (iter != this->end()) {
Pattern * p = &(*iter);
return p;
}
return NULL;
}

void reserve(size_t size) {
data.reserve(size);
}
void shrink_to_fit() {
data.shrink_to_fit();
}

};

Expand Down

0 comments on commit 0d8d194

Please sign in to comment.