source: git/kernel/intvec.h @ cafd4ff

spielwiese
Last change on this file since cafd4ff was ddbc22, checked in by Hans Schoenemann <hannes@…>, 13 years ago
intvec::view only for debugging git-svn-id: file:///usr/local/Singular/svn/trunk@13987 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[35aab3]1#ifndef INTVEC_H
2#define INTVEC_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
[341696]6/* $Id$ */
[35aab3]7/*
8* ABSTRACT: class intvec: lists/vectors of integers
9*/
10#include <string.h>
[b1dfaf]11#include <omalloc/omalloc.h>
[599326]12#include <kernel/febase.h>
[35aab3]13
[a82adc]14
15//extern omBin intvec_bin;
16
[35aab3]17class intvec
18{
19private:
20  int *v;
21  int row;
22  int col;
23public:
24
[30b8381]25  inline intvec(int l = 1)
[35aab3]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);
[c6b849]33  intvec(const intvec* iv)
[a82adc]34  {
[c6b849]35    assume( iv != NULL );
[a82adc]36    row = iv->rows();
37    col = iv->cols();
[9b4a332]38    if (row*col>0)
[a82adc]39    {
[9b4a332]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      }
[a82adc]45    }
[9b4a332]46    else v=NULL;
[a82adc]47  }
[35aab3]48
49  void resize(int new_length);
[315ec1]50  inline int range(int i) const
[35aab3]51    { return ((i<row) && (i>=0) && (col==1)); }
[315ec1]52  inline int range(int i, int j) const
[35aab3]53    { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
[30b8381]54  inline int& operator[](int i)
[35aab3]55    {
56#ifndef NDEBUG
57      if((i<0)||(i>=row*col))
58      {
59        Werror("wrong intvec index:%d\n",i);
60      }
[315ec1]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      }
[35aab3]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: >
[cd2d90]81  int compare(const intvec* o) const;
82  int compare(int o) const;
[30b8381]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; }
[e3915e]87  void show(int mat=0,int spaces=0) const;
[ddbc22]88  #ifndef NDEBUG
[e9c3b2]89  void view() const;
[ddbc22]90  #endif
[e9c3b2]91
[30b8381]92  inline void makeVector() { row*=col;col=1; }
[e3915e]93  char * String(int dim = 2) const;
94  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
[30b8381]95  inline ~intvec()
[35aab3]96    {
97      if (v!=NULL)
98      {
99        omFreeSize((ADDRESS)v,sizeof(int)*row*col);
100        v=NULL;
101      }
102    }
[771339]103  inline void ivTEST() const
[35aab3]104    {
105      omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
106    }
[30b8381]107  inline int min_in()
108  {
109    int m=v[0];
[8436580]110    for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
[30b8381]111    return m;
112  }
[a82adc]113#if 0
114  void* operator new ( size_t size )
115  {
116    void* addr;
117    //omTypeAlloc(void*, addr, size);
118    addr=omAlloc0Bin(intvec_bin);
119    return addr;
120  }
121  void operator delete ( void* block )
[c6b849]122  { //omfree( block );
[a82adc]123    omFreeBin((ADDRESS)block, intvec_bin);
124  }
125#endif
[30b8381]126  // keiner (ausser obachman) darf das folgenden benutzen !!!
127  inline int * ivGetVec() { return v; }
[35aab3]128};
[c6b849]129inline intvec * ivCopy(const intvec * o)
[a82adc]130{
[c6b849]131  if( o != NULL )
132    return new intvec(o);
133
134  return NULL;
[a82adc]135}
136
[35aab3]137intvec * ivAdd(intvec * a, intvec * b);
138intvec * ivSub(intvec * a, intvec * b);
139intvec * ivTranp(intvec * o);
140int      ivTrace(intvec * o);
141intvec * ivMult(intvec * a, intvec * b);
142//void     ivTriangMat(intvec * imat);
143void     ivTriangIntern(intvec * imat, int &ready, int &all);
144intvec * ivSolveKern(intvec * imat, int ready);
145
[0d7903]146#ifdef MDEBUG
[771339]147inline void ivTest(intvec * v)
148{
149  v->ivTEST();
150}
[0d7903]151#else
152#define ivTest(v) ((void)0)
153#endif
[771339]154
[35aab3]155#undef INLINE_THIS
156
157#endif
Note: See TracBrowser for help on using the repository browser.