source: git/kernel/intvec.h @ 47b2b2d

fieker-DuValspielwiese
Last change on this file since 47b2b2d was c6b849, checked in by Motsak Oleksandr <motsak@…>, 15 years ago
*motsak: copy git-svn-id: file:///usr/local/Singular/svn/trunk@11881 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: intvec.h,v 1.8 2009-06-05 05:18:27 motsak Exp $ */
7/*
8* ABSTRACT: class intvec: lists/vectors of integers
9*/
10#include <string.h>
11#include "omalloc.h"
12#include "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    v   = (int *)omAlloc(sizeof(int)*row*col);
39    for (int i=row*col-1;i>=0; i--)
40    {
41      v[i] = (*iv)[i];
42    }
43  }
44
45  void resize(int new_length);
46  inline int range(int i) const
47    { return ((i<row) && (i>=0) && (col==1)); }
48  inline int range(int i, int j) const
49    { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
50  inline int& operator[](int i)
51    {
52#ifndef NDEBUG
53      if((i<0)||(i>=row*col))
54      {
55        Werror("wrong intvec index:%d\n",i);
56      }
57#endif
58      return v[i];
59    }
60  inline const int& operator[](int i) const
61    {
62#ifndef NDEBUG
63      if((i<0)||(i>=row*col))
64      {
65        Werror("wrong intvec index:%d\n",i);
66      }
67#endif
68      return v[i];
69    }
70#define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
71  void operator+=(int intop);
72  void operator-=(int intop);
73  void operator*=(int intop);
74  void operator/=(int intop);
75  void operator%=(int intop);
76  // -2: not compatible, -1: <, 0:=, 1: >
77  int compare(intvec* o);
78  int compare(int o);
79  inline int  length() const { return col*row; }
80  inline int  cols() const { return col; }
81  inline int  rows() const { return row; }
82  inline void length(int l) { row = l; col = 1; }
83  void show(int mat=0,int spaces=0) const;
84  inline void makeVector() { row*=col;col=1; }
85  char * String(int dim = 2) const;
86  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
87  inline ~intvec()
88    {
89      if (v!=NULL)
90      {
91        omFreeSize((ADDRESS)v,sizeof(int)*row*col);
92        v=NULL;
93      }
94    }
95  inline void ivTEST()
96    {
97      omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
98    }
99  inline int min_in()
100  {
101    int m=v[0];
102    for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
103    return m;
104  }
105#if 0
106  void* operator new ( size_t size )
107  {
108    void* addr;
109    //omTypeAlloc(void*, addr, size);
110    addr=omAlloc0Bin(intvec_bin);
111    return addr;
112  }
113  void operator delete ( void* block )
114  { //omfree( block );
115    omFreeBin((ADDRESS)block, intvec_bin);
116  }
117#endif
118  // keiner (ausser obachman) darf das folgenden benutzen !!!
119  inline int * ivGetVec() { return v; }
120};
121inline intvec * ivCopy(const intvec * o)
122{
123  if( o != NULL )
124    return new intvec(o);
125
126  return NULL;
127}
128
129intvec * ivAdd(intvec * a, intvec * b);
130intvec * ivSub(intvec * a, intvec * b);
131intvec * ivTranp(intvec * o);
132int      ivTrace(intvec * o);
133intvec * ivMult(intvec * a, intvec * b);
134//void     ivTriangMat(intvec * imat);
135void     ivTriangIntern(intvec * imat, int &ready, int &all);
136intvec * ivSolveKern(intvec * imat, int ready);
137
138
139#ifdef MDEBUG
140#define ivTest(v) v->ivTEST()
141#else
142#define ivTest(v)   ((void)0)
143#endif
144#undef INLINE_THIS
145
146#endif
Note: See TracBrowser for help on using the repository browser.