source: git/kernel/intvec.h @ 585bbcb

spielwiese
Last change on this file since 585bbcb was a82adc, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes: try to optimize intvec git-svn-id: file:///usr/local/Singular/svn/trunk@8252 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.0 KB
Line 
1#ifndef INTVEC_H
2#define INTVEC_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: intvec.h,v 1.5 2005-05-20 15:33:19 Singular Exp $ */
7/*
8* ABSTRACT: class intvec: lists/vectors of integers
9*/
10#include <string.h>
11#include "omalloc.h"
12#include "febase.h"
13
14
15//extern omBin intvec_bin;
16
17class intvec
18{
19private:
20  int *v;
21  int row;
22  int col;
23public:
24
25  inline intvec(int l = 1)
26    {
27      v = (int *)omAlloc0(sizeof(int)*l);
28      row = l;
29      col = 1;
30    }
31  intvec(int s, int e);
32  intvec(int r, int c, int init);
33  intvec(intvec* iv)
34  {
35    row = iv->rows();
36    col = iv->cols();
37    v   = (int *)omAlloc(sizeof(int)*row*col);
38    for (int i=row*col-1;i>=0; i--)
39    {
40      v[i] = (*iv)[i];
41    }
42  }
43
44  void resize(int new_length);
45  inline int range(int i)
46    { return ((i<row) && (i>=0) && (col==1)); }
47  inline int range(int i, int j)
48    { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
49  inline int& operator[](int i)
50    {
51#ifndef NDEBUG
52      if((i<0)||(i>=row*col))
53      {
54        Werror("wrong intvec index:%d\n",i);
55      }
56#endif
57      return v[i];
58    }
59#define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
60  void operator+=(int intop);
61  void operator-=(int intop);
62  void operator*=(int intop);
63  void operator/=(int intop);
64  void operator%=(int intop);
65  // -2: not compatible, -1: <, 0:=, 1: >
66  int compare(intvec* o);
67  int compare(int o);
68  inline int  length() const { return col*row; }
69  inline int  cols() const { return col; }
70  inline int  rows() const { return row; }
71  inline void length(int l) { row = l; col = 1; }
72  void show(int mat=0,int spaces=0);
73  inline void makeVector() { row*=col;col=1; }
74  char * String(int dim = 2);
75  char * ivString(int not_mat=1,int spaces=0, int dim=2);
76  inline ~intvec()
77    {
78      if (v!=NULL)
79      {
80        omFreeSize((ADDRESS)v,sizeof(int)*row*col);
81        v=NULL;
82      }
83    }
84  inline void ivTEST()
85    {
86      omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
87    }
88  inline int min_in()
89  {
90    int m=v[0];
91    for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
92    return m;
93  }
94#if 0
95  void* operator new ( size_t size )
96  {
97    void* addr;
98    //omTypeAlloc(void*, addr, size);
99    addr=omAlloc0Bin(intvec_bin);
100    return addr;
101  }
102  void operator delete ( void* block )
103  { //omfree( block );
104    omFreeBin((ADDRESS)block, intvec_bin);
105  }
106#endif
107  // keiner (ausser obachman) darf das folgenden benutzen !!!
108  inline int * ivGetVec() { return v; }
109};
110inline intvec * ivCopy(intvec * o)
111{
112  intvec * iv=new intvec(o);
113  return iv;
114}
115
116intvec * ivAdd(intvec * a, intvec * b);
117intvec * ivSub(intvec * a, intvec * b);
118intvec * ivTranp(intvec * o);
119int      ivTrace(intvec * o);
120intvec * ivMult(intvec * a, intvec * b);
121//void     ivTriangMat(intvec * imat);
122void     ivTriangIntern(intvec * imat, int &ready, int &all);
123intvec * ivSolveKern(intvec * imat, int ready);
124
125
126#ifdef MDEBUG
127#define ivTest(v) v->ivTEST()
128#else
129#define ivTest(v)   ((void)0)
130#endif
131#undef INLINE_THIS
132
133#endif
Note: See TracBrowser for help on using the repository browser.