00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef VEC_T_H
00054 #define VEC_T_H
00055
00056 #include "w_defines.h"
00057
00058
00059
00060
00061
00062
00063
00064 #ifdef __GNUG__
00065 #pragma interface
00066 #endif
00067
00068 typedef const unsigned char * CADDR_T;
00069 #define MAX_SMALL_VEC_SIZE 8
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 struct vec_pair_t {
00081 CADDR_T ptr;
00082 size_t len;
00083 };
00084
00085
00086
00087 struct VEC_t {
00088 int _cnt;
00089 size_t _size;
00090 vec_pair_t* _base;
00091
00092 vec_pair_t _pair[MAX_SMALL_VEC_SIZE];
00093 };
00094
00095
00096
00097 class cvec_t : protected VEC_t {
00098 friend class vec_t;
00099 protected:
00100 static CADDR_T zero_location;
00101
00102 public:
00103 enum dummy_enumid { max_small = MAX_SMALL_VEC_SIZE };
00104 public:
00105 cvec_t() {
00106 _cnt = 0;
00107 _size = 0;
00108 _base = &_pair[0];
00109 }
00110 cvec_t(const cvec_t& v1, const cvec_t& v2) {
00111 _base= &_pair[0];
00112 set(v1, v2);
00113 }
00114 cvec_t(const void* p, size_t l) {
00115 _base = &_pair[0];
00116 set(p, l);
00117 }
00118 cvec_t(const cvec_t& v, size_t offset, size_t limit) {
00119 _base = &_pair[0];
00120 set(v, offset, limit);
00121 }
00122 ~cvec_t();
00123
00124 void split(size_t l1, cvec_t& v1, cvec_t& v2) const;
00125
00126
00127 cvec_t& put(const cvec_t& v, size_t offset, size_t nbytes);
00128
00129 cvec_t& put(const void* p, size_t l);
00130
00131 cvec_t& put(const cvec_t& v);
00132
00133
00134 cvec_t& reset() {
00135 _cnt = _size = 0;
00136 return *this;
00137 }
00138
00139 cvec_t& set(const cvec_t& v1, const cvec_t& v2) {
00140 return reset().put(v1).put(v2);
00141 }
00142
00143 cvec_t& set(const cvec_t& v) {
00144 return reset().put(v);
00145 }
00146
00147
00148 cvec_t& set(const void* p, size_t l) {
00149 return reset().put(p, l);
00150 }
00151
00152
00153
00154 cvec_t& set(const cvec_t& v, size_t offset, size_t limit) {
00155 return reset().put(v, offset, limit);
00156 }
00157
00158
00159
00160 size_t size() const {
00161 return _size;
00162 }
00163
00164
00165 size_t copy_to(void* p, size_t limit = 0x7fffffff) const;
00166
00167 int cmp(const cvec_t& v, size_t* common_size = 0) const;
00168 int cmp(const void* s, size_t len) const;
00169
00170 static int cmp(const cvec_t& v1,
00171 const cvec_t& v2, size_t* common_size = 0) {
00172 return v1.cmp(v2, common_size);
00173 }
00174
00175
00176 int count() const {return _cnt;}
00177
00178 int checksum() const;
00179 void calc_kvl(uint4_t& h) const;
00180 void init() { _cnt = _size = 0; }
00181
00182
00183
00184
00185
00186
00187
00188 void vecdelparts() { while(_cnt-->0) {
00189 delete[] _base[_cnt].ptr;
00190 _base[_cnt].ptr = NULL;
00191 _base[_cnt].len = 0;
00192 }
00193 init();
00194 }
00195 void delparts() { while(_cnt-->0) {
00196 delete _base[_cnt].ptr;
00197 _base[_cnt].ptr = NULL;
00198 _base[_cnt].len = 0;
00199 }
00200 init();
00201 }
00202
00203 bool is_pos_inf() const { return this == &pos_inf; }
00204 bool is_neg_inf() const { return this == &neg_inf; }
00205 bool is_null() const { return size() == 0; }
00206
00207 friend inline bool operator<(const cvec_t& v1, const cvec_t& v2);
00208 friend inline bool operator<=(const cvec_t& v1, const cvec_t& v2);
00209 friend inline bool operator>=(const cvec_t& v1, const cvec_t& v2);
00210 friend inline bool operator>(const cvec_t& v1, const cvec_t& v2);
00211 friend inline bool operator==(const cvec_t& v1, const cvec_t& v2);
00212 friend inline bool operator!=(const cvec_t& v1, const cvec_t& v2);
00213
00214 friend ostream& operator<<(ostream&, const cvec_t& v);
00215 friend istream& operator>>(istream&, cvec_t& v);
00216
00217 static cvec_t pos_inf;
00218 static cvec_t neg_inf;
00219
00220 private:
00221
00222 cvec_t(const cvec_t& v);
00223
00224
00225 bool _is_large() const {return _base != &_pair[0];}
00226
00227
00228 int _max_cnt() const {
00229 return (int)(_is_large() ? _pair[0].len : (int)max_small);
00230 }
00231
00232 void _grow(int total_cnt);
00233
00234
00235
00236 cvec_t& operator=(cvec_t);
00237
00238 size_t recalc_size() const;
00239 bool check_size() const;
00240
00241 public:
00242 bool is_zvec() const {
00243 #if W_DEBUG_LEVEL > 2
00244 if(count()>0) {
00245 if(_pair[0].ptr == zero_location) {
00246 w_assert3(count() == 1);
00247 }
00248 }
00249 #endif
00250 return (count()==0)
00251 ||
00252 (count() == 1 && _pair[0].ptr == zero_location);
00253 }
00254 };
00255
00256
00257
00258
00259
00260
00261 class vec_t : public cvec_t {
00262 public:
00263
00264 vec_t() : cvec_t() {};
00265
00266 vec_t(const cvec_t& v1, const cvec_t& v2) : cvec_t(v1, v2) {};
00267
00268 vec_t(const void* p, size_t l) : cvec_t(p, l) {};
00269
00270 vec_t(const vec_t& v, size_t offset, size_t limit)
00271 : cvec_t(v, offset, limit) {};
00272
00273
00274
00275
00276
00277
00278
00279 const vec_t& copy_from(
00280 const void* p,
00281 size_t limit,
00282 size_t offset = 0) const;
00283
00284
00285
00286
00287
00288
00289
00290 vec_t& copy_from(const cvec_t& v);
00291
00292
00293
00294
00295
00296
00297
00298 vec_t& copy_from(
00299 const cvec_t& v,
00300 size_t offset,
00301 size_t limit,
00302 size_t myoffset = 0);
00303
00304
00305 CADDR_T ptr(int index) const { return (index >= 0 && index < _cnt) ?
00306 _base[index].ptr : (CADDR_T) NULL; }
00307
00308 size_t len(int index) const { return (index >= 0 && index < _cnt) ?
00309 _base[index].len : 0; }
00310
00311
00312
00313
00314 void mkchunk( int maxsize,
00315 int skip,
00316 vec_t &result
00317 ) const;
00318
00319
00320
00321 static vec_t& pos_inf;
00322
00323 static vec_t& neg_inf;
00324
00325 private:
00326
00327 vec_t(const vec_t&) : cvec_t() {
00328 cerr << "vec_t: disabled member called" << endl;
00329 cerr << "failed at \"" << __FILE__ << ":" << __LINE__ << "\"" << endl;
00330 W_FATAL (fcINTERNAL);
00331 }
00332 private:
00333
00334 vec_t& operator=(vec_t);
00335
00336 };
00337
00338 inline bool operator<(const cvec_t& v1, const cvec_t& v2)
00339 {
00340 return v1.cmp(v2) < 0;
00341 }
00342
00343 inline bool operator<=(const cvec_t& v1, const cvec_t& v2)
00344 {
00345 return v1.cmp(v2) <= 0;
00346 }
00347
00348 inline bool operator>=(const cvec_t& v1, const cvec_t& v2)
00349 {
00350 return v1.cmp(v2) >= 0;
00351 }
00352
00353 inline bool operator>(const cvec_t& v1, const cvec_t& v2)
00354 {
00355 return v1.cmp(v2) > 0;
00356 }
00357
00358 inline bool operator==(const cvec_t& v1, const cvec_t& v2)
00359 {
00360 return (&v1==&v2) || v1.cmp(v2) == 0;
00361 }
00362
00363 inline bool operator!=(const cvec_t& v1, const cvec_t& v2)
00364 {
00365 return ! (v1 == v2);
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 class zvec_t : public vec_t {
00378 public:
00379 zvec_t() : vec_t(zero_location,0) {};
00380 zvec_t(size_t l) : vec_t(zero_location, l) {};
00381 zvec_t &put(size_t l) { reset().put(zero_location,l); return *this; }
00382 private:
00383
00384 zvec_t(const zvec_t&) :vec_t(zero_location, 0) {}
00385 zvec_t &operator=(zvec_t);
00386
00387 zvec_t(const cvec_t& v1, const cvec_t& v2);
00388 zvec_t(const void* p, size_t l);
00389 zvec_t(const vec_t& v, size_t offset, size_t limit);
00390 };
00391
00392
00393
00394 #endif