source: git/ntl/include/NTL/WordVector.h @ 311902

spielwiese
Last change on this file since 311902 was 311902, checked in by Hans Schönemann <hannes@…>, 20 years ago
*hannes: 5.3.2-C++-fix git-svn-id: file:///usr/local/Singular/svn/trunk@7474 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.4 KB
Line 
1
2#ifndef NTL_WordVector__H
3#define NTL_WordVector__H
4
5/**************************************************************
6
7  A WordVector is functionally similar to
8  a  generic NTL vector of _ntl_ulong. 
9
10  Be careful! the MaxLength() function does not return
11    the max length ever set, but rather the max space allocated,
12    which *may* be more.
13
14  The FixLength() facility is not available.
15
16  The reason for special-casing is efficiency (of course).
17
18**************************************************************/
19
20
21
22#include <NTL/tools.h>
23#include <NTL/ZZ.h>
24
25NTL_OPEN_NNS
26
27
28
29#ifndef NTL_RANGE_CHECK
30#define NTL_WV_RANGE_CHECK_CODE
31#else
32#define NTL_WV_RANGE_CHECK_CODE if (i < 0 || !rep || i >= long(rep[-1])) RangeError(i);
33#endif
34
35// vectors are allocated in chunks of this size
36
37#ifndef NTL_WordVectorMinAlloc
38#define NTL_WordVectorMinAlloc (4)
39#endif
40
41// vectors are always expanded by at least this ratio
42
43#ifndef NTL_WordVectorExpansionRatio
44#define NTL_WordVectorExpansionRatio (1.2)
45#endif
46
47// controls initialization during input
48
49#ifndef NTL_WordVectorInputBlock
50#define NTL_WordVectorInputBlock 50
51#endif
52
53
54class WordVector { 
55public: 
56   _ntl_ulong *rep; 
57   void RangeError(long i) const; 
58
59   WordVector(WordVector& x, INIT_TRANS_TYPE) { rep = x.rep; x.rep = 0; }
60
61
62 
63   WordVector() { rep = 0; } 
64   WordVector(INIT_SIZE_TYPE, long n) { rep = 0; DoSetLength(n); } 
65   WordVector(const WordVector& a) { rep = 0; *this = a; }     
66
67   WordVector& operator=(const WordVector& a); 
68
69   ~WordVector(); 
70   void kill(); 
71
72   void DoSetLength(long n);
73 
74   void SetLength(long n)
75   {
76      _ntl_ulong *x = rep;
77      if (x && long(x[-2] >> 1) >= n && n >= 0)
78         x[-1] = n;
79      else
80         DoSetLength(n);
81   }
82
83   void ZeroLength() { if (rep) rep[-1] = 0; }
84         
85   void SetMaxLength(long n); 
86   void QuickSetLength(long n) { rep[-1] = _ntl_ulong(n); } 
87 
88   long length() const { return (!rep) ?  0 : long(rep[-1]); } 
89   long MaxLength() const 
90   { return (!rep) ?  0 : long(rep[-2] >> 1); } 
91 
92   _ntl_ulong& operator[](long i)   
93   { 
94      NTL_WV_RANGE_CHECK_CODE 
95      return rep[i]; 
96   } 
97 
98   const _ntl_ulong& operator[](long i) const 
99   { 
100      NTL_WV_RANGE_CHECK_CODE 
101      return rep[i]; 
102   } 
103 
104   _ntl_ulong& operator()(long i) { return (*this)[i-1]; } 
105   const _ntl_ulong& operator()(long i) const { return (*this)[i-1]; } 
106   
107 
108   const _ntl_ulong* elts() const { return rep; } 
109   _ntl_ulong* elts() { return rep; } 
110         
111   static void swap_impl(WordVector& x, WordVector& y); 
112   static void append_impl(WordVector& v, _ntl_ulong a); 
113   static void append_impl(WordVector& v, const WordVector& w); 
114}; 
115
116inline void swap(WordVector& x, WordVector& y) 
117   { WordVector::swap_impl(x, y); }
118
119inline void append(WordVector& v, _ntl_ulong a)
120   { WordVector::append_impl(v, a); }
121
122inline void append(WordVector& v, const WordVector& w)
123   { WordVector::append_impl(v, w); }
124
125
126long operator==(const WordVector& a, const WordVector& b); 
127long operator!=(const WordVector& a, const WordVector& b);
128
129
130long InnerProduct(const WordVector& a, const WordVector& b);
131
132void ShiftAdd(_ntl_ulong *cp, const _ntl_ulong* ap, long sa, long n);
133// cp = cp + (a << n)
134
135
136long WV_BlockConstructAlloc(WordVector& x, long d, long n);
137 
138void WV_BlockConstructSet(WordVector& x, WordVector& y, long i);
139 
140long WV_BlockDestroy(WordVector& x);
141
142long WV_storage(long d);
143
144
145
146
147
148NTL_CLOSE_NNS
149
150#endif
Note: See TracBrowser for help on using the repository browser.