From 77618b3511ee5edb6509902126293a084f9767bf Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Fri, 27 Nov 2015 11:02:12 +0100 Subject: Angleset: Change add behaviour to not run combine() The most often used command for angleset in this tool is the add function. If at the end of every add the combine() function is being called, a lot of CPU time is wasted. Add now doesn't call combine(), and marks the angleset as dirty instead. All functions that require a clean angleset now check if it's dirty, and if yes call combine(). --- anglerange.cpp | 4 ++-- anglerange.h | 6 ++++-- angleset.cpp | 18 +++++++++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/anglerange.cpp b/anglerange.cpp index c62f760..99e6718 100644 --- a/anglerange.cpp +++ b/anglerange.cpp @@ -144,7 +144,7 @@ bool anglerange::isinside(const angleclass &val) const } } -anglerange anglerange::overlap(const anglerange &other) +anglerange anglerange::overlap(const anglerange &other) const { //storage for the return value: anglerange retval; //anglerange constructor without arguments: emtpy range [0:0] @@ -239,7 +239,7 @@ anglerange anglerange::overlap(const anglerange &other) return(retval); } -anglerange anglerange::combine(const anglerange &other) +anglerange anglerange::combine(const anglerange &other) const { anglerange retval; retval.setsorttype(sortby); //return value inherits current sorttype. diff --git a/anglerange.h b/anglerange.h index 6d6d286..f0c9eec 100644 --- a/anglerange.h +++ b/anglerange.h @@ -77,11 +77,13 @@ public: //this function calculates the overlap between this anglerange and another one, returning it as //a new anglerange. - anglerange overlap(const anglerange &other); + anglerange overlap(const anglerange &other) const; //this function does the opposite of overlap: Both ranges are combined into one bigger range. //if they are disjoint, an empty range is given back. - anglerange combine(const anglerange &other); + anglerange combine(const anglerange &other) const; + + //a subtract function is not possible at this level, as single angle ranges could get disjoint by it. bool operator<(const anglerange &other) const; bool operator>(const anglerange &other) const; diff --git a/angleset.cpp b/angleset.cpp index fc759b8..24d5b62 100644 --- a/angleset.cpp +++ b/angleset.cpp @@ -114,9 +114,10 @@ void angleset::add(const anglerange &value) //this means: we *should not reuse* this function for adding anglesets. if(!value.isempty()) { + consistent=false; storage.push_back(value); storage.back().setsorttype(anglerange::SRT_LOWER); - combine(); + //combine(); } } @@ -125,14 +126,16 @@ void angleset::add(const angleset &value) storage.reserve(storage.size()+value.storage.size()); storage.insert(storage.end(),value.storage.begin(),value.storage.end()); //if value is a valid angleset, sort order is set to SRT_LOWER for all fields. - combine(); + consistent=false; + //combine(); } void angleset::add(const double &lower, const double &upper) { storage.push_back(anglerange(lower,upper)); storage.back().setsorttype(anglerange::SRT_LOWER); - combine(); + consistent=false; + //combine(); } @@ -164,25 +167,34 @@ angleset angleset::overlap(const angleset &other) retval.add(overlap(i)); } ); + if(!other.consistent) + retval.combine(); return(retval); } std::vector angleset::getranges() { + if(!consistent) + combine(); return storage; } const std::vector& angleset::getrangesref() { + if(!consistent) + combine(); return storage; } void angleset::clear() { storage.clear(); + consistent=true; } void angleset::sort() { + if(!consistent) + combine(); std::sort(storage.begin(),storage.end()); } -- cgit v1.2.3