[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Fri Mar 25 19:38:55 CET 2005


CVS commit by arwalker: 

Remove obsolete functions
Don't resize vector and reallocate memory unless necessary
Don't call update on created vectors


  M +22 -40    ksthistogram.cpp   1.57
  M +1 -7      ksthistogram.h   1.32


--- kdeextragear-2/kst/kst/ksthistogram.cpp  #1.56:1.57
@@ -104,6 +104,7 @@ void KstHistogram::commonConstructor(con
                                      KstHsNormType in_norm_mode) {
   _typeString = i18n("Histogram");
-
   _NormMode = in_norm_mode;
+  _Bins = 0L;
+  _NBins = 0;
 
   setTagName(in_tag);
@@ -126,5 +127,5 @@ void KstHistogram::commonConstructor(con
     _NBins = 2;
   }
-  Bins = new unsigned long[_NBins];
+  _Bins = new unsigned long[_NBins];
   _NS = 3 * _NBins + 1;
 
@@ -151,6 +152,6 @@ KstHistogram::~KstHistogram() {
   KST::vectorList.lock().writeUnlock();
 
-  delete[] Bins;
-  Bins = 0L;
+  delete[] _Bins;
+  _Bins = 0L;
 }
 
@@ -189,5 +190,5 @@ KstObject::UpdateType KstHistogram::upda
   _W = (_MaxX - _MinX)/double(_NBins);
 
-  memset(Bins, 0, _NBins*sizeof(*Bins));
+  memset(_Bins, 0, _NBins*sizeof(*_Bins));
 
   ns = _inputVectors[RAWVECTOR]->length();
@@ -196,10 +197,10 @@ KstObject::UpdateType KstHistogram::upda
     i_bin = (int)floor((y-_MinX)/_W);
     if (i_bin >= 0 && i_bin < _NBins) {
-      Bins[i_bin]++;
+      _Bins[i_bin]++;
     } else {
       // the top boundry of the top bin is included in the top bin.
       // for all other bins, the top boundry is included in the next bin
       if (y == _MaxX) {
-        Bins[_NBins-1]++;
+        _Bins[_NBins-1]++;
       }
     }
@@ -207,5 +208,5 @@ KstObject::UpdateType KstHistogram::upda
 
   for (i_bin=0; i_bin<_NBins; i_bin++) {
-    y = Bins[i_bin];
+    y = _Bins[i_bin];
     if (y > MaxY) {
       MaxY = y;
@@ -254,10 +255,7 @@ KstObject::UpdateType KstHistogram::upda
   for ( i_bin = 0; i_bin<_NBins; i_bin++ ) {
     bins[i_bin] = ( double( i_bin ) + 0.5 )*_W + _MinX;
-    hist[i_bin] = Bins[i_bin]*_Normalization;
+    hist[i_bin] = _Bins[i_bin]*_Normalization;
   }
 
-  (*_bVector)->update(update_counter);
-  (*_hVector)->update(update_counter);
-
   return setLastUpdateResult(UPDATE);
 }
@@ -285,18 +283,17 @@ void KstHistogram::setXRange(double xmin
 
 void KstHistogram::internalSetNBins(int in_n_bins) {
-  delete[] Bins;
-
+  if (in_n_bins < 2) {
+    in_n_bins = 2;
+  }
+  if (_NBins != in_n_bins) {
   _NBins = in_n_bins;
-
-  if (_NBins < 2) {
-    _NBins = 2;
+    delete[] _Bins;
+    _Bins = new unsigned long[_NBins];
+    memset(_Bins, 0, _NBins*sizeof(*_Bins));
+    (*_bVector)->resize(_NBins);
+    (*_hVector)->resize(_NBins);
   }
-  Bins = new unsigned long[_NBins];
-  memset(Bins, 0, _NBins*sizeof(*Bins));
   _W = (_MaxX - _MinX)/double(_NBins);
   _NS = 3 * _NBins + 1;
-
-  (*_bVector)->resize(_NBins);
-  (*_hVector)->resize(_NBins);
 }
 
@@ -378,19 +375,4 @@ void KstHistogram::save(QTextStream &ts,
 
 
-double KstHistogram::vMax() const {
-  return _inputVectors[RAWVECTOR]->max();
-}
-
-
-double KstHistogram::vMin() const {
-  return _inputVectors[RAWVECTOR]->min();
-}
-
-
-int KstHistogram::vNumSamples() const {
-  return _inputVectors[RAWVECTOR]->length();
-}
-
-
 QString KstHistogram::propertyString() const {
   return i18n("Histogram: %1").arg(vTag());

--- kdeextragear-2/kst/kst/ksthistogram.h  #1.31:1.32
@@ -54,8 +54,4 @@ public:
   virtual KstCurveType type() const;
 
-  double vMax() const;
-  double vMin() const;
-  int vNumSamples() const;
-
   bool isNormNum()        const { return _NormMode == KST_HS_NUMBER; }
   void setIsNormNum()           { _NormMode = KST_HS_NUMBER; }
@@ -94,9 +90,7 @@ private:
   int _NS;
   int _NBins;
-  unsigned long *Bins;
+  unsigned long *_Bins;
   double _Normalization;
   double _W;
-
-  //real-time auto bin on every update
   bool _realTimeAutoBin;
   




More information about the Kst mailing list