From 31a74d9ef833bd26a4934aa3b5b8ca00be48d3ee Mon Sep 17 00:00:00 2001
From: John Romein <romein@astron.nl>
Date: Fri, 4 Jan 2008 17:01:48 +0000
Subject: [PATCH] bug 225: Added (public) Ranges type to SparseSet<T>

---
 Appl/CEP/CS1/CS1_BGLProc/src/Allocator.cc            |  4 +---
 Appl/CEP/CS1/CS1_BGLProc/src/Correlator.cc           |  4 +---
 Appl/CEP/CS1/CS1_BGLProc/src/PPF.cc                  |  4 ++--
 Appl/CEP/CS1/CS1_IONProc/src/BeamletBuffer.cc        |  3 +--
 Appl/CEP/CS1/CS1_IONProc/src/ION_Allocator.cc        |  4 +---
 Appl/CEP/CS1/CS1_IONProc/src/WH_InputSection.cc      |  2 +-
 .../CS1_Interface/include/CS1_Interface/SparseSet.h  | 12 +++++++-----
 7 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/Appl/CEP/CS1/CS1_BGLProc/src/Allocator.cc b/Appl/CEP/CS1/CS1_BGLProc/src/Allocator.cc
index fcdc4a6bc0f..529096b6194 100644
--- a/Appl/CEP/CS1/CS1_BGLProc/src/Allocator.cc
+++ b/Appl/CEP/CS1/CS1_BGLProc/src/Allocator.cc
@@ -34,9 +34,7 @@ Overlay::Overlay(const Heap &heap)
 
 void *Overlay::allocate(size_t size, int alignment)
 {
-  const std::vector<SparseSet<void *>::range> &ranges = freeList.getRanges();
-
-  for (SparseSet<void *>::const_iterator it = ranges.begin(); it != ranges.end(); it ++) {
+  for (SparseSet<void *>::const_iterator it = freeList.getRanges().begin(); it != freeList.getRanges().end(); it ++) {
     void *begin = (void *) (((size_t) it->begin + alignment - 1) & ~(alignment - 1));
 
     if ((char *) it->end - (char *) begin >= (ptrdiff_t) size) {
diff --git a/Appl/CEP/CS1/CS1_BGLProc/src/Correlator.cc b/Appl/CEP/CS1/CS1_BGLProc/src/Correlator.cc
index 8b1bbeb57d2..5b8d039ea55 100644
--- a/Appl/CEP/CS1/CS1_BGLProc/src/Correlator.cc
+++ b/Appl/CEP/CS1/CS1_BGLProc/src/Correlator.cc
@@ -51,9 +51,7 @@ double Correlator::computeCentroidAndValidSamples(const SparseSet<unsigned> &fla
   unsigned sq	     = itsNrSamplesPerIntegration * itsNrSamplesPerIntegration;
   unsigned nrSamples = itsNrSamplesPerIntegration;
 
-  const std::vector<SparseSet<unsigned>::range> &ranges = flags.getRanges();
-
-  for (SparseSet<unsigned>::const_iterator it = ranges.begin(); it != ranges.end(); it ++) {
+  for (SparseSet<unsigned>::const_iterator it = flags.getRanges().begin(); it != flags.getRanges().end(); it ++) {
     sq	      -= (it->end - it->begin) * (it->end + it->begin);
     nrSamples -= (it->end - it->begin);
   }
diff --git a/Appl/CEP/CS1/CS1_BGLProc/src/PPF.cc b/Appl/CEP/CS1/CS1_BGLProc/src/PPF.cc
index 4461c74651a..313e8cb8276 100644
--- a/Appl/CEP/CS1/CS1_BGLProc/src/PPF.cc
+++ b/Appl/CEP/CS1/CS1_BGLProc/src/PPF.cc
@@ -129,7 +129,7 @@ void PPF::computeFlags(const TransposedData *transposedData, FilteredData *filte
 #else
   for (unsigned stat = 0; stat < itsNrStations; stat ++) {
     filteredData->flags[stat].reset();
-    const std::vector<SparseSet<unsigned>::range> &ranges = transposedData->flags[stat].getRanges();
+    const SparseSet<unsigned>::Ranges &ranges = transposedData->flags[stat].getRanges();
 
     for (SparseSet<unsigned>::const_iterator it = ranges.begin(); it != ranges.end(); it ++) {
       unsigned begin = std::max(0, (signed) it->begin / NR_SUBBAND_CHANNELS - NR_TAPS + 1);
@@ -277,7 +277,7 @@ void PPF::filter(double centerFrequency, const TransposedData *transposedData, F
       computePhaseShifts(phaseShifts, transposedData->delays[stat], baseFrequency);
     }
 
-    const std::vector<SparseSet<unsigned>::range> &ranges = filteredData->flags[stat].getRanges();
+    const SparseSet<unsigned>::Ranges &ranges = filteredData->flags[stat].getRanges();
     SparseSet<unsigned>::const_iterator it = ranges.begin();
 
     for (unsigned time = 0; time < itsNrSamplesPerIntegration; time ++) {
diff --git a/Appl/CEP/CS1/CS1_IONProc/src/BeamletBuffer.cc b/Appl/CEP/CS1/CS1_IONProc/src/BeamletBuffer.cc
index c23ff8355b0..c563c325003 100644
--- a/Appl/CEP/CS1/CS1_IONProc/src/BeamletBuffer.cc
+++ b/Appl/CEP/CS1/CS1_IONProc/src/BeamletBuffer.cc
@@ -147,9 +147,8 @@ void BeamletBuffer::readFlags(SparseSet<unsigned> &flags)
   pthread_mutex_unlock(&itsValidDataMutex);
 
   flags.reset().include(0, static_cast<unsigned>(itsEnd - itsBegin));
-  const std::vector<SparseSet<TimeStamp>::range> &validRanges = validTimes.getRanges();
 
-  for (SparseSet<TimeStamp>::const_iterator it = validRanges.begin(); it != validRanges.end(); it ++)
+  for (SparseSet<TimeStamp>::const_iterator it = validTimes.getRanges().begin(); it != validTimes.getRanges().end(); it ++)
     flags.exclude(static_cast<unsigned>(it->begin - itsBegin),
 		  static_cast<unsigned>(it->end - itsBegin));
 }
diff --git a/Appl/CEP/CS1/CS1_IONProc/src/ION_Allocator.cc b/Appl/CEP/CS1/CS1_IONProc/src/ION_Allocator.cc
index 0353450f1ec..0eea9830c6c 100644
--- a/Appl/CEP/CS1/CS1_IONProc/src/ION_Allocator.cc
+++ b/Appl/CEP/CS1/CS1_IONProc/src/ION_Allocator.cc
@@ -65,9 +65,7 @@ void *ION_Allocator::allocate(size_t nbytes, size_t alignment)
 #else
   pthread_mutex_lock(&mutex);
 
-  const std::vector<SparseSet<char *>::range> &ranges = freeList.getRanges();
-
-  for (SparseSet<char *>::const_iterator it = ranges.begin(); it != ranges.end(); it ++) {
+  for (SparseSet<char *>::const_iterator it = ranges.getRanges().begin(); it != ranges.getRanges().end(); it ++) {
     char *begin = (char *) (((size_t) it->begin + alignment - 1) & ~(alignment - 1));
 
     if (it->end - begin >= (ptrdiff_t) nbytes) {
diff --git a/Appl/CEP/CS1/CS1_IONProc/src/WH_InputSection.cc b/Appl/CEP/CS1/CS1_IONProc/src/WH_InputSection.cc
index f1c88b843ca..55c4c0e90dc 100644
--- a/Appl/CEP/CS1/CS1_IONProc/src/WH_InputSection.cc
+++ b/Appl/CEP/CS1/CS1_IONProc/src/WH_InputSection.cc
@@ -147,7 +147,7 @@ void WH_InputSection::preprocess()
 
 void WH_InputSection::limitFlagsLength(SparseSet<unsigned> &flags)
 {
-  const std::vector<SparseSet<unsigned>::range> &ranges = flags.getRanges();
+  const SparseSet<unsigned>::Ranges &ranges = flags.getRanges();
 
   if (ranges.size() > 16)
     flags.include(ranges[15].begin, ranges[ranges.size() - 1].end);
diff --git a/Appl/CEP/CS1/CS1_Interface/include/CS1_Interface/SparseSet.h b/Appl/CEP/CS1/CS1_Interface/include/CS1_Interface/SparseSet.h
index 2503d44411e..c9b5a264cb4 100644
--- a/Appl/CEP/CS1/CS1_Interface/include/CS1_Interface/SparseSet.h
+++ b/Appl/CEP/CS1/CS1_Interface/include/CS1_Interface/SparseSet.h
@@ -44,8 +44,9 @@ template <typename T> class SparseSet {
       T begin, end;
     };
 
-    typedef typename std::vector<range>::iterator	iterator;
-    typedef typename std::vector<range>::const_iterator const_iterator;
+    typedef typename std::vector<range>	    Ranges;
+    typedef typename Ranges::iterator	    iterator;
+    typedef typename Ranges::const_iterator const_iterator;
 
     SparseSet<T> &include(T index);
     SparseSet<T> &include(T first /* inclusive */, T last /* exclusive */);
@@ -64,7 +65,7 @@ template <typename T> class SparseSet {
     SparseSet<T> &operator -= (size_t count);
     SparseSet<T> subset(T first, T last) const;
 
-    const std::vector<range> &getRanges() const;
+    const Ranges &getRanges() const;
 
     void write(BlobOStream &) const;
     void read(BlobIStream &);
@@ -73,7 +74,7 @@ template <typename T> class SparseSet {
     void    unmarshall(const void *ptr);
 
   private:
-    std::vector<range> ranges;
+    Ranges ranges;
 
     struct less {
       bool operator() (const range &x, const range &y)
@@ -125,7 +126,8 @@ template <typename T> inline SparseSet<T> SparseSet<T>::subset(T first, T last)
 }
 
 
-template <typename T> inline const std::vector<typename SparseSet<T>::range> &SparseSet<T>::getRanges() const
+//template <typename T> inline const std::vector<typename SparseSet<T>::range> &SparseSet<T>::getRanges() const
+template <typename T> inline const typename SparseSet<T>::Ranges &SparseSet<T>::getRanges() const
 {
   return ranges;
 }
-- 
GitLab