source: git/libpolys/misc/intvec.h @ 45cc512

spielwiese
Last change on this file since 45cc512 was e9d581, checked in by Hans Schoenemann <hannes@…>, 11 years ago
add: concat for intmat, bigintmat
  • Property mode set to 100644
File size: 3.5 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    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(const intvec* iv)
34  {
35    assume( iv != NULL );
36    row = iv->rows();
37    col = iv->cols();
38    assume(row > 0);
39    assume(col > 0);
40    if (row*col>0)
41    {
42      v   = (int *)omAlloc(sizeof(int)*row*col);
43      for (int i=row*col-1;i>=0; i--)
44      {
45        v[i] = (*iv)[i];
46      }
47    }
48    else v=NULL;
49  }
50
51  void resize(int new_length);
52  inline int range(int i) const
53    { return ((i<row) && (i>=0) && (col==1)); }
54  inline int range(int i, int j) const
55    { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
56  inline int& operator[](int i)
57    {
58#ifndef NDEBUG
59      if((i<0)||(i>=row*col))
60      {
61        Werror("wrong intvec index:%d\n",i);
62      }
63#endif
64      return v[i];
65    }
66  inline const int& operator[](int i) const
67    {
68#ifndef NDEBUG
69      if((i<0)||(i>=row*col))
70      {
71        Werror("wrong intvec index:%d\n",i);
72      }
73#endif
74      return v[i];
75    }
76#define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
77  void operator+=(int intop);
78  void operator-=(int intop);
79  void operator*=(int intop);
80  void operator/=(int intop);
81  void operator%=(int intop);
82  // -2: not compatible, -1: <, 0:=, 1: >
83  int compare(const intvec* o) const;
84  int compare(int o) const;
85  inline int  length() const { return col*row; }
86  inline int  cols() const { return col; }
87  inline int  rows() const { return row; }
88  inline void length(int l) { row = l; col = 1; }
89  void show(int mat=0,int spaces=0) const;
90  #ifndef NDEBUG
91  void view() const;
92  #endif
93
94  inline void makeVector() { row*=col;col=1; }
95  char * String(int dim = 2) const;
96  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
97  inline ~intvec()
98    {
99      if (v!=NULL)
100      {
101        omFreeSize((ADDRESS)v,sizeof(int)*row*col);
102        v=NULL;
103      }
104    }
105  inline void ivTEST() const
106    {
107      omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
108    }
109  inline int min_in()
110  {
111    int m=v[0];
112    for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
113    return m;
114  }
115#if 0
116  // TODO: no omalloc Bin (de-)/allocation?
117  void* operator new ( size_t size )
118  {
119    void* addr;
120    //omTypeAlloc(void*, addr, size);
121    addr=omAlloc0Bin(intvec_bin);
122    return addr;
123  }
124  void operator delete ( void* block )
125  { //omfree( block );
126    omFreeBin((ADDRESS)block, intvec_bin);
127  }
128#endif
129  // keiner (ausser obachman) darf das folgenden benutzen !!!
130  inline int * ivGetVec() { return v; }
131};
132inline intvec * ivCopy(const intvec * o)
133{
134  if( o != NULL )
135    return new intvec(o);
136
137  return NULL;
138}
139
140intvec * ivAdd(intvec * a, intvec * b);
141intvec * ivSub(intvec * a, intvec * b);
142intvec * ivTranp(intvec * o);
143int      ivTrace(intvec * o);
144intvec * ivMult(intvec * a, intvec * b);
145//void     ivTriangMat(intvec * imat);
146void     ivTriangIntern(intvec * imat, int &ready, int &all);
147intvec * ivSolveKern(intvec * imat, int ready);
148intvec * ivConcat(intvec * a, intvec * b);
149
150#ifdef MDEBUG
151inline void ivTest(intvec * v)
152{
153  v->ivTEST();
154}
155#else
156#define ivTest(v) do {} while (0)
157#endif
158
159#undef INLINE_THIS
160
161#endif
Note: See TracBrowser for help on using the repository browser.