source: git/libpolys/misc/intvec.h @ 42a81e

fieker-DuValspielwiese
Last change on this file since 42a81e was 52b3cf7, checked in by Hans Schoenemann <hannes@…>, 9 years ago
intvec: 0:0
  • Property mode set to 100644
File size: 3.6 KB
Line 
1#ifndef INTVEC_H
2#define INTVEC_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/*
7* ABSTRACT: class intvec: lists/vectors of integers
8*/
9#include <string.h>
10#include <omalloc/omalloc.h>
11#include <reporter/reporter.h>
12
13
14//extern omBin intvec_bin;
15
16class intvec
17{
18private:
19  int *v;
20  int row;
21  int col;
22public:
23
24  inline intvec(int l = 1)
25  {
26    assume(l >= 0);
27    if (l>0) v = (int *)omAlloc0(sizeof(int)*l);
28    else     v = NULL;
29    row = l;
30    col = 1;
31  }
32  intvec(int s, int e);
33  intvec(int r, int c, int init);
34  intvec(const intvec* iv)
35  {
36    assume( iv != NULL );
37    row = iv->rows();
38    col = iv->cols();
39    assume(row >= 0);
40    assume(col > 0);
41    if (row*col>0)
42    {
43      v   = (int *)omAlloc(sizeof(int)*row*col);
44      for (int i=row*col-1;i>=0; i--)
45      {
46        v[i] = (*iv)[i];
47      }
48    }
49    else v=NULL;
50  }
51
52  void resize(int new_length);
53  inline int range(int i) const
54    { return ((i<row) && (i>=0) && (col==1)); }
55  inline int range(int i, int j) const
56    { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
57  inline int& operator[](int i)
58    {
59#ifndef SING_NDEBUG
60      if((i<0)||(i>=row*col))
61      {
62        Werror("wrong intvec index:%d\n",i);
63      }
64#endif
65      return v[i];
66    }
67  inline const int& operator[](int i) const
68    {
69#ifndef SING_NDEBUG
70      if((i<0)||(i>=row*col))
71      {
72        Werror("wrong intvec index:%d\n",i);
73      }
74#endif
75      return v[i];
76    }
77#define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
78  void operator+=(int intop);
79  void operator-=(int intop);
80  void operator*=(int intop);
81  void operator/=(int intop);
82  void operator%=(int intop);
83  // -2: not compatible, -1: <, 0:=, 1: >
84  int compare(const intvec* o) const;
85  int compare(int o) const;
86  inline int  length() const { return col*row; }
87  inline int  cols() const { return col; }
88  inline int  rows() const { return row; }
89  inline void length(int l) { row = l; col = 1; }
90  void show(int mat=0,int spaces=0) const;
91  #ifndef SING_NDEBUG
92  void view() const;
93  #endif
94
95  inline void makeVector() { row*=col;col=1; }
96  char * String(int dim = 2) const;
97  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
98  inline ~intvec()
99    {
100      if (v!=NULL)
101      {
102        omFreeSize((ADDRESS)v,sizeof(int)*row*col);
103        v=NULL;
104      }
105    }
106  inline void ivTEST() const
107    {
108      if (row>0) omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
109    }
110  inline int min_in()
111  {
112    int m=0;
113    if (row>0)
114    {
115      m=v[0];
116      for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
117    }
118    return m;
119  }
120#if 0
121  // TODO: no omalloc Bin (de-)/allocation?
122  void* operator new ( size_t size )
123  {
124    void* addr;
125    //omTypeAlloc(void*, addr, size);
126    addr=omAlloc0Bin(intvec_bin);
127    return addr;
128  }
129  void operator delete ( void* block )
130  { //omfree( block );
131    omFreeBin((ADDRESS)block, intvec_bin);
132  }
133#endif
134  // keiner (ausser obachman) darf das folgenden benutzen !!!
135  inline int * ivGetVec() { return v; }
136};
137inline intvec * ivCopy(const intvec * o)
138{
139  if( o != NULL )
140    return new intvec(o);
141
142  return NULL;
143}
144
145intvec * ivAdd(intvec * a, intvec * b);
146intvec * ivSub(intvec * a, intvec * b);
147intvec * ivTranp(intvec * o);
148int      ivTrace(intvec * o);
149intvec * ivMult(intvec * a, intvec * b);
150//void     ivTriangMat(intvec * imat);
151void     ivTriangIntern(intvec * imat, int &ready, int &all);
152intvec * ivSolveKern(intvec * imat, int ready);
153intvec * ivConcat(intvec * a, intvec * b);
154
155#ifdef MDEBUG
156inline void ivTest(intvec * v)
157{
158  v->ivTEST();
159}
160#else
161#define ivTest(v) do {} while (0)
162#endif
163
164#undef INLINE_THIS
165
166#endif
Note: See TracBrowser for help on using the repository browser.