Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members Related Pages

# TSV.cpp

Go to the documentation of this file.

    00001
    00037 #include <math.h>
    00038 #include "TSV.h"
    00039 #include "Debug.h"
    00040
    00041
    00052 int CompareTSVElement(const void* elem1, const void* elem2)
    00053 {
    00054         double& e1 = *(double*)elem1;
    00055         double& e2 = *(double*)elem2;
    00056
    00057         ASSERT(e1 >= 0 && e2 >= 0);
    00058
    00059         if (e1 < e2)
    00060                 return 1;
    00061         else if (e1 > e2)
    00062                 return -1;
    00063         else
    00064                 return 0;
    00065 }
    00066
    00068 double TSV::Norm2() const
    00069 {
    00070         const double* pData = GetData();
    00071         double d = 0.0;
    00072
    00073         for(int i = 0; i < GetSize(); i++)
    00074                 d += pData[i] * pData[i];
    00075
    00076         return sqrt(d);
    00077 }
    00078
    00082 TSV TSV::operator-(const TSV& rhs) const
    00083 {
    00084         bool bRhsIsBigger = rhs.GetSize() > GetSize();
    00085         int i, nMinSize, nMaxSize;
    00086
    00087         if (bRhsIsBigger) {
    00088                 nMinSize = GetSize();
    00089                 nMaxSize = rhs.GetSize();
    00090         }
    00091         else {
    00092                 nMinSize = rhs.GetSize();
    00093                 nMaxSize = GetSize();
    00094         }
    00095
    00096         TSV r(nMaxSize);
    00097
    00098         for(i = 0; i < nMinSize; i++)
    00099                 r[i] = operator[](i) - rhs[i];
    00100
    00101         if (bRhsIsBigger)
    00102                 for(; i < nMaxSize; i++)
    00103                         r[i] = -rhs[i];
    00104         else
    00105                 for(; i < nMaxSize; i++)
    00106                         r[i] = operator[](i);
    00107
    00108 /*      int size = GetSize();
    00109         TSV r(size);
    00110
    00111         ASSERT(size == rhs.GetSize());
    00112
    00113         for(int i = 0; i < size; i++)
    00114                 r[i] = operator[](i) - rhs[i];*/
    00115
    00116         return r;
    00117 }