source: git/Singular/intvec.h @ 416465

spielwiese
Last change on this file since 416465 was 416465, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* bug-fixes from work with Thomas git-svn-id: file:///usr/local/Singular/svn/trunk@3826 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.0 KB
Line 
1#ifndef INTVEC_H
2#define INTVEC_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: intvec.h,v 1.12 1999-11-15 17:20:07 obachman Exp $ */
7/*
8* ABSTRACT: class intvec: lists/vectors of integers
9*/
10#include <string.h>
11#include "mmemory.h"
12#include "febase.h"
13
14// Macros for getting new intvecs to enable debugging of memory
15#ifdef MDEBUG
16#define NewIntvec0()        new intvec(__FILE__, __LINE__)
17#define NewIntvec1(l)       new intvec(__FILE__, __LINE__, l)
18#define NewIntvec2(s, e)    new intvec(__FILE__, __LINE__, s, e)
19#define NewIntvec3(r, c, i) new intvec(__FILE__, __LINE__, r, c, i)
20#define NewIntvecIv(iv)     new intvec(__FILE__, __LINE__, iv)
21#else
22#define NewIntvec0  new intvec
23#define NewIntvec1  new intvec
24#define NewIntvec2  new intvec
25#define NewIntvec3  new intvec
26#define NewIntvecIv new intvec
27#endif
28
29class intvec
30{
31private:
32  int *v;
33  int row;
34  int col;
35public:
36
37#ifdef MDEBUG
38  intvec(char* file, int line, int l = 1);
39  intvec(char* file, int line, int s, int e);
40  intvec(char* file, int line, int r, int c, int init);
41  intvec(char* file, int line, intvec* iv);
42#endif
43
44  intvec(int l = 1)
45    {
46      v = (int *)Alloc0(sizeof(int)*l);
47      row = l;
48      col = 1;
49    }
50  intvec(int s, int e);
51  intvec(int r, int c, int init);
52  intvec(intvec* iv);
53
54  void resize(int new_length);
55  int range(int i)
56    { return ((i<row) && (i>=0) && (col==1)); }
57  int range(int i, int j)
58    { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
59  int& operator[](int i)
60    {
61#ifndef NDEBUG
62      if((i<0)||(i>=row*col))
63      {
64        Werror("wrong intvec index:%d\n",i);
65      }
66#endif
67      return v[i];
68    }
69#define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
70  void operator+=(int intop);
71  void operator-=(int intop);
72  void operator*=(int intop);
73  void operator/=(int intop);
74  void operator%=(int intop);
75  // -2: not compatible, -1: <, 0:=, 1: >
76  int compare(intvec* o);
77  int compare(int o);
78  int  length() const { return col*row; }
79  int  cols() const { return col; }
80  int  rows() const { return row; }
81  void length(int l) { row = l; col = 1; }
82  void show(int mat=0,int spaces=0);
83  void makeVector() { row*=col;col=1; }
84  // keiner (ausser obachman) darf das folgenden benutzen !!!
85  int * ivGetVec() { return v; }
86  char * String(int dim = 2);
87  char * ivString(int mat=0,int spaces=0, int dim=2);
88  ~intvec()
89    {
90      mmTestL(this);
91      if (v!=NULL)
92      {
93        Free((ADDRESS)v,sizeof(int)*row*col);
94        v=NULL;
95      }
96    }
97  void ivTEST()
98    {
99      mmTestL(this);
100      mmTest((ADDRESS)v,sizeof(int)*row*col);
101    }
102};
103intvec * ivCopy(intvec * o);
104intvec * ivAdd(intvec * a, intvec * b);
105intvec * ivSub(intvec * a, intvec * b);
106intvec * ivTranp(intvec * o);
107int      ivTrace(intvec * o);
108intvec * ivMult(intvec * a, intvec * b);
109void     ivTriangMat(intvec * imat, int srw, int col);
110int      ivFirstEmptyRow(intvec * imat);
111void     ivCancelContent(intvec * imat,int from=1);
112intvec * ivSolveIntMat(intvec * imat);
113
114#undef INLINE_THIS
115
116#endif
Note: See TracBrowser for help on using the repository browser.