source: git/libpolys/misc/intvec.h @ fd201f

spielwiese
Last change on this file since fd201f was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 3.4 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      v = (int *)omAlloc0(sizeof(int)*l);
27      row = l;
28      col = 1;
29    }
30  intvec(int s, int e);
31  intvec(int r, int c, int init);
32  intvec(const intvec* iv)
33  {
34    assume( iv != NULL );
35    row = iv->rows();
36    col = iv->cols();
37    if (row*col>0)
38    {
39      v   = (int *)omAlloc(sizeof(int)*row*col);
40      for (int i=row*col-1;i>=0; i--)
41      {
42        v[i] = (*iv)[i];
43      }
44    }
45    else v=NULL;
46  }
47
48  void resize(int new_length);
49  inline int range(int i) const
50    { return ((i<row) && (i>=0) && (col==1)); }
51  inline int range(int i, int j) const
52    { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
53  inline int& operator[](int i)
54    {
55#ifndef NDEBUG
56      if((i<0)||(i>=row*col))
57      {
58        Werror("wrong intvec index:%d\n",i);
59      }
60#endif
61      return v[i];
62    }
63  inline const int& operator[](int i) const
64    {
65#ifndef NDEBUG
66      if((i<0)||(i>=row*col))
67      {
68        Werror("wrong intvec index:%d\n",i);
69      }
70#endif
71      return v[i];
72    }
73#define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
74  void operator+=(int intop);
75  void operator-=(int intop);
76  void operator*=(int intop);
77  void operator/=(int intop);
78  void operator%=(int intop);
79  // -2: not compatible, -1: <, 0:=, 1: >
80  int compare(const intvec* o) const;
81  int compare(int o) const;
82  inline int  length() const { return col*row; }
83  inline int  cols() const { return col; }
84  inline int  rows() const { return row; }
85  inline void length(int l) { row = l; col = 1; }
86  void show(int mat=0,int spaces=0) const;
87  #ifndef NDEBUG
88  void view() const;
89  #endif
90
91  inline void makeVector() { row*=col;col=1; }
92  char * String(int dim = 2) const;
93  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
94  inline ~intvec()
95    {
96      if (v!=NULL)
97      {
98        omFreeSize((ADDRESS)v,sizeof(int)*row*col);
99        v=NULL;
100      }
101    }
102  inline void ivTEST() const
103    {
104      omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
105    }
106  inline int min_in()
107  {
108    int m=v[0];
109    for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
110    return m;
111  }
112#if 0
113  void* operator new ( size_t size )
114  {
115    void* addr;
116    //omTypeAlloc(void*, addr, size);
117    addr=omAlloc0Bin(intvec_bin);
118    return addr;
119  }
120  void operator delete ( void* block )
121  { //omfree( block );
122    omFreeBin((ADDRESS)block, intvec_bin);
123  }
124#endif
125  // keiner (ausser obachman) darf das folgenden benutzen !!!
126  inline int * ivGetVec() { return v; }
127};
128inline intvec * ivCopy(const intvec * o)
129{
130  if( o != NULL )
131    return new intvec(o);
132
133  return NULL;
134}
135
136intvec * ivAdd(intvec * a, intvec * b);
137intvec * ivSub(intvec * a, intvec * b);
138intvec * ivTranp(intvec * o);
139int      ivTrace(intvec * o);
140intvec * ivMult(intvec * a, intvec * b);
141//void     ivTriangMat(intvec * imat);
142void     ivTriangIntern(intvec * imat, int &ready, int &all);
143intvec * ivSolveKern(intvec * imat, int ready);
144
145#ifdef MDEBUG
146inline void ivTest(intvec * v)
147{
148  v->ivTEST();
149}
150#else
151#define ivTest(v) ((void)0)
152#endif
153
154#undef INLINE_THIS
155
156#endif
Note: See TracBrowser for help on using the repository browser.