Skip to content

Commit 0d8d194

Browse files
committed
much simpler
1 parent a6dc3fa commit 0d8d194

File tree

1 file changed

+56
-64
lines changed

1 file changed

+56
-64
lines changed

include/datatypes.h

Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -534,92 +534,84 @@ class PatternVector { //acts like a (small) map (but implemented as a vector to
534534

535535
PatternVector() {};
536536

537-
PatternVector(const PatternVector & ref) {
538-
for ( const auto& pfv_ref : ref.data ){
539-
//make a copy
540-
Pattern *pfv = new Pattern(pfv_ref);
541-
this->data.push_back(*pfv);
542-
}
537+
PatternVector( const PatternVector& ref ) {
538+
data = ref.data;
543539
}
544540

545-
PatternVector& operator=( const PatternVector & ref) {
541+
PatternVector& operator=( const PatternVector& ref ) {
546542
if ( this != &ref ){
547-
for ( const auto& pfv_ref : ref.data ){
548-
//make a copy
549-
Pattern *pfv = new Pattern(pfv_ref);
550-
this->data.push_back(*pfv);
551-
}
543+
data = ref.data;
552544
}
553545
return *this;
554546
}
555547

556548
virtual ~PatternVector() {
557549
}
558-
bool has(const Pattern & ref) const {
559-
for (const_iterator iter = this->begin(); iter != this->end(); ++iter) {
560-
if (*iter == ref) {
561-
return true;
562-
}
563-
}
564-
return false;
565-
}
566550

551+
bool has(const Pattern & ref) const {
552+
for (const_iterator iter = this->begin(); iter != this->end(); ++iter) {
553+
if (*iter == ref) {
554+
return true;
555+
}
556+
}
557+
return false;
558+
}
567559

568-
iterator find(const Pattern & ref) {
569-
for (iterator iter = this->begin(); iter != this->end(); ++iter) {
570-
if (*iter == ref) {
571-
return iter;
572-
}
573-
}
574-
return this->end();
575-
}
576560

577-
unsigned int count() const { return data.size(); }
561+
iterator find(const Pattern & ref) {
562+
for (iterator iter = this->begin(); iter != this->end(); ++iter) {
563+
if (*iter == ref) {
564+
return iter;
565+
}
566+
}
567+
return this->end();
568+
}
578569

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

580572

581-
void insert(const Pattern & pattern, bool checkexists=true) {
582-
//make a copy, safer
583-
if (checkexists) {
584-
iterator found = this->find(pattern);
585-
if (found == this->end()) {
586-
this->data.push_back(pattern);
587-
}
588-
} else {
589-
this->data.push_back(pattern);
590-
}
591-
}
592573

593-
size_t size() const { return data.size(); }
574+
void insert(const Pattern & pattern, bool checkexists=true) {
575+
//make a copy, safer
576+
if (checkexists) {
577+
iterator found = this->find(pattern);
578+
if (found == this->end()) {
579+
this->data.push_back(pattern);
580+
}
581+
} else {
582+
this->data.push_back(pattern);
583+
}
584+
}
594585

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

601-
iterator begin() { return data.begin(); }
602-
const_iterator begin() const { return data.begin(); }
588+
virtual std::string tostring() {
589+
//we have no classdecoder at this point
590+
std::cerr << "ERROR: PatternFeatureVector does not support serialisation to string" << std::endl;
591+
throw InternalError();
592+
}
603593

604-
iterator end() { return data.end(); }
605-
const_iterator end() const { return data.end(); }
594+
iterator begin() { return data.begin(); }
595+
const_iterator begin() const { return data.begin(); }
606596

607-
virtual Pattern * getdata(const Pattern & pattern) {
608-
iterator iter = this->find(pattern);
609-
if (iter != this->end()) {
610-
Pattern * p = &(*iter);
611-
return p;
612-
}
613-
return NULL;
614-
}
597+
iterator end() { return data.end(); }
598+
const_iterator end() const { return data.end(); }
615599

616-
void reserve(size_t size) {
617-
data.reserve(size);
618-
}
619-
void shrink_to_fit() {
620-
data.shrink_to_fit();
621-
}
600+
virtual Pattern * getdata(const Pattern & pattern) {
601+
iterator iter = this->find(pattern);
602+
if (iter != this->end()) {
603+
Pattern * p = &(*iter);
604+
return p;
605+
}
606+
return NULL;
607+
}
622608

609+
void reserve(size_t size) {
610+
data.reserve(size);
611+
}
612+
void shrink_to_fit() {
613+
data.shrink_to_fit();
614+
}
623615

624616
};
625617

0 commit comments

Comments
 (0)