#include <lac/dsmatrix.h>
#include <ostream.h>
-#include <base/sort.h>
+
+
+/*----------------- from sort.h -------------------------*/
+
+
+//////////
+template<class T>
+inline void swap(T* a, T* b)
+{
+ T x = *a;
+ *a = *b;
+ *b = x;
+}
+
+//////////
+template<class T>
+inline void simple_sort(long n, T* field)
+{
+ long i,j;
+ for (i=1;i<n;i++)
+ {
+ for (j=i+1;j<=n;j++)
+ {
+ if (field[j] < field[i])
+ {
+ swap(field+i,field+j);
+ }
+ }
+ }
+}
+
+template<class T>
+inline void heapsort_sift(T* a, long l, long r)
+{
+ long i = l;
+ long j = 2*i;
+ T x = a[i];
+
+ while (j<=r)
+ {
+ if (j<r)
+ {
+ if (a[j] < a[j+1]) j++;
+ }
+ if (!(x < a[j])) break;
+ a[i] = a[j];
+ i = j;
+ j = 2*i;
+ }
+ a[i] = x;
+}
+
+
+//////////
+template<class T>
+inline void heapsort(int n, T* field)
+{
+ field--;
+
+ long l =(n/2)+1;
+ long r = n;
+
+ while (l>1)
+ {
+ l--;
+ heapsort_sift(field,l,r);
+ }
+ while (r>1)
+ {
+ swap(field+l,field+r);
+ r--;
+ heapsort_sift(field,l,r);
+ }
+}
+
+//////////
+template<class T>
+inline void _quicksort(long r, T* a, long l)
+{
+ long i = l;
+ long j = r;
+ T* x = &a[(l+r)/2];
+ do
+ {
+ while (a[i] < *x) i++;
+ while (*x < a[j]) j--;
+ if (i<=j)
+ {
+ swap(a+i,a+j);
+ i++;
+ j--;
+ }
+ }
+ while (i<=j);
+ if (l<j) _quicksort(j,a,l);
+ if (i<r) _quicksort(r,a,i);
+}
+
+template<class T>
+inline void quicksort(long r, T* a)
+{
+ _quicksort(r,a,1);
+}
+
+
+/*----------------- from sort.h -------------------------*/
+
+
void
dSMatrixStruct::reinit(int m, int n, int max_per_row)
{
- THROW1(m<=0, IntError(IntError::IllegalDimension, m));
- THROW1(n<=0, IntError(IntError::IllegalDimension, n));
- THROW1(max_per_row<=0, IntError(IntError::IllegalDimension, max_per_row));
+// THROW1(m<=0, IntError(IntError::IllegalDimension, m));
+// THROW1(n<=0, IntError(IntError::IllegalDimension, n));
+// THROW1(max_per_row<=0, IntError(IntError::IllegalDimension, max_per_row));
rows = m;
cols = n;
vec_len = m * max_per_row;
{
dim = n;
maxdim = n;
- THROW1(n<0, IntError(IntError::IllegalDimension, n, "dVector"));
+ //THROW1(n<0, IntError(IntError::IllegalDimension, n, "dVector"));
if (n)
{
val = new double[maxdim];
- THROWUNCOND(!val, Error(Error::NoMem,"dVector::dVector"));
+ //THROWUNCOND(!val, Error(Error::NoMem,"dVector::dVector"));
(*this) = 0.;
}
}
if (dim)
{
val = new double[maxdim];
- THROWUNCOND(!val, Error(Error::NoMem,"dVector::dVector"));
+ //THROWUNCOND(!val, Error(Error::NoMem,"dVector::dVector"));
for (int i=0;i<dim;i++) val[i] = v.val[i];
}
}
void dVector::reinit(int n, int fast)
{
- THROW1(n<=0, IntError(IntError::IllegalDimension, n));
+ //THROW1(n<=0, IntError(IntError::IllegalDimension, n));
if (n>maxdim)
{
if (val) delete[] val;
val = new double[n];
- THROWUNCOND(!val, Error(Error::NoMem,"dVector::reinit"));
+ //THROWUNCOND(!val, Error(Error::NoMem,"dVector::reinit"));
maxdim = n;
}
dim = n;
{
if (val) delete[] val;
val = new double[n];
- THROWUNCOND(!val, Error(Error::NoMem,"dVector::reinit"));
+ //THROWUNCOND(!val, Error(Error::NoMem,"dVector::reinit"));
maxdim = n;
}
dim = n;
void dVector::cadd(int i, const VectorBase& V, double s, int j)
{
const dVector& v = (const dVector&) V;
- THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cadd"));
- THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd"));
+ //THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cadd"));
+ //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd"));
val[i] += s*v.val[j];
}
void dVector::cadd(int i, const VectorBase& V, double s, int j, double t, int k)
{
const dVector& v = (const dVector&) V;
- THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cadd"));
- THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd"));
- THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cadd"));
+ //THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cadd"));
+ //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd"));
+ //THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cadd"));
val[i] += s*v.val[j] + t*v.val[k];
}
double t, int k, double q, int l, double r, int m)
{
const dVector& v = (const dVector&) V;
- THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cadd"));
- THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd"));
- THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cadd"));
- THROW1((l<0) || (l>v.dim), IntError(IntError::Range,l,"cadd"));
- THROW1((m<0) || (m>v.dim), IntError(IntError::Range,m,"cadd"));
+ //THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cadd"));
+ //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd"));
+ //THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cadd"));
+ //THROW1((l<0) || (l>v.dim), IntError(IntError::Range,l,"cadd"));
+ //THROW1((m<0) || (m>v.dim), IntError(IntError::Range,m,"cadd"));
val[i] += s*v.val[j] + t*v.val[k] + q*v.val[l] + r*v.val[m];
}
void dVector::czero(int i)
{
- THROW1((i<0) || (i>dim), IntError(IntError::Range,i));
+ //THROW1((i<0) || (i>dim), IntError(IntError::Range,i));
val[i] = 0.;
}
void dVector::cequ(int i, const VectorBase& V, double s, int j)
{
const dVector& v = (const dVector&) V;
- THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cequ"));
- THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ"));
+ //THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cequ"));
+ //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ"));
val[i] = s*v.val[j];
}
void dVector::cequ(int i, const VectorBase& V, double s, int j, double t, int k)
{
const dVector& v = (const dVector&) V;
- THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cequ"));
- THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ"));
- THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cequ"));
+ //THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cequ"));
+ //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ"));
+ //THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cequ"));
val[i] = s*v.val[j] + t*v.val[k];
}
double t, int k, double q, int l, double r, int m)
{
const dVector& v = (const dVector&) V;
- THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cequ"));
- THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ"));
- THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cequ"));
- THROW1((l<0) || (l>v.dim), IntError(IntError::Range,l,"cequ"));
- THROW1((m<0) || (m>v.dim), IntError(IntError::Range,m,"cequ"));
+ //THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cequ"));
+ //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ"));
+ //THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cequ"));
+ //THROW1((l<0) || (l>v.dim), IntError(IntError::Range,l,"cequ"));
+ //THROW1((m<0) || (m>v.dim), IntError(IntError::Range,m,"cequ"));
val[i] = s*v.val[j] + t*v.val[k] + q*v.val[l] + r*v.val[m];
}