source: git/kernel/intvec.h @ e9c3b2

spielwiese
Last change on this file since e9c3b2 was e9c3b2, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
ADD: intvec: new view() method ADD: some debug for NF strategy object ADD: idSize From: Oleksandr Motsak <motsak@mathematik.uni-kl.de> git-svn-id: file:///usr/local/Singular/svn/trunk@13978 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.3 KB
Line 
1#ifndef INTVEC_H
2#define INTVEC_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7/*
8* ABSTRACT: class intvec: lists/vectors of integers
9*/
10#include <string.h>
11#include <omalloc/omalloc.h>
12#include <kernel/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(const intvec* iv)
34  {
35    assume( iv != NULL );
36    row = iv->rows();
37    col = iv->cols();
38    if (row*col>0)
39    {
40      v   = (int *)omAlloc(sizeof(int)*row*col);
41      for (int i=row*col-1;i>=0; i--)
42      {
43        v[i] = (*iv)[i];
44      }
45    }
46    else v=NULL;
47  }
48
49  void resize(int new_length);
50  inline int range(int i) const
51    { return ((i<row) && (i>=0) && (col==1)); }
52  inline int range(int i, int j) const
53    { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
54  inline int& operator[](int i)
55    {
56#ifndef NDEBUG
57      if((i<0)||(i>=row*col))
58      {
59        Werror("wrong intvec index:%d\n",i);
60      }
61#endif
62      return v[i];
63    }
64  inline const int& operator[](int i) const
65    {
66#ifndef NDEBUG
67      if((i<0)||(i>=row*col))
68      {
69        Werror("wrong intvec index:%d\n",i);
70      }
71#endif
72      return v[i];
73    }
74#define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
75  void operator+=(int intop);
76  void operator-=(int intop);
77  void operator*=(int intop);
78  void operator/=(int intop);
79  void operator%=(int intop);
80  // -2: not compatible, -1: <, 0:=, 1: >
81  int compare(const intvec* o) const;
82  int compare(int o) const;
83  inline int  length() const { return col*row; }
84  inline int  cols() const { return col; }
85  inline int  rows() const { return row; }
86  inline void length(int l) { row = l; col = 1; }
87  void show(int mat=0,int spaces=0) const;
88  void view() const;
89
90  inline void makeVector() { row*=col;col=1; }
91  char * String(int dim = 2) const;
92  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
93  inline ~intvec()
94    {
95      if (v!=NULL)
96      {
97        omFreeSize((ADDRESS)v,sizeof(int)*row*col);
98        v=NULL;
99      }
100    }
101  inline void ivTEST() const
102    {
103      omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
104    }
105  inline int min_in()
106  {
107    int m=v[0];
108    for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
109    return m;
110  }
111#if 0
112  void* operator new ( size_t size )
113  {
114    void* addr;
115    //omTypeAlloc(void*, addr, size);
116    addr=omAlloc0Bin(intvec_bin);
117    return addr;
118  }
119  void operator delete ( void* block )
120  { //omfree( block );
121    omFreeBin((ADDRESS)block, intvec_bin);
122  }
123#endif
124  // keiner (ausser obachman) darf das folgenden benutzen !!!
125  inline int * ivGetVec() { return v; }
126};
127inline intvec * ivCopy(const intvec * o)
128{
129  if( o != NULL )
130    return new intvec(o);
131
132  return NULL;
133}
134
135intvec * ivAdd(intvec * a, intvec * b);
136intvec * ivSub(intvec * a, intvec * b);
137intvec * ivTranp(intvec * o);
138int      ivTrace(intvec * o);
139intvec * ivMult(intvec * a, intvec * b);
140//void     ivTriangMat(intvec * imat);
141void     ivTriangIntern(intvec * imat, int &ready, int &all);
142intvec * ivSolveKern(intvec * imat, int ready);
143
144#ifdef MDEBUG
145inline void ivTest(intvec * v)
146{
147  v->ivTEST();
148}
149#else
150#define ivTest(v) ((void)0)
151#endif
152
153#undef INLINE_THIS
154
155#endif
Note: See TracBrowser for help on using the repository browser.