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 private:
00103 typedef w_base_t::uint8_t u64;
00104 typedef w_base_t::uint4_t u32;
00105
00106 enum dummy_enumid { max_small = MAX_SMALL_VEC_SIZE };
00107 void _calc_kvl(uint4_t seed, uint4_t& h) const;
00108 static u32 convert64_32 (u64 num);
00109 public:
00110 cvec_t() {
00111 _cnt = 0;
00112 _size = 0;
00113 _base = &_pair[0];
00114 }
00115 cvec_t(const cvec_t& v1, const cvec_t& v2) {
00116 _base= &_pair[0];
00117 set(v1, v2);
00118 }
00119 cvec_t(const void* p, size_t l) {
00120 _base = &_pair[0];
00121 set(p, l);
00122 }
00123 cvec_t(const cvec_t& v, size_t offset, size_t limit) {
00124 _base = &_pair[0];
00125 set(v, offset, limit);
00126 }
00127 ~cvec_t();
00128
00129 void split(size_t l1, cvec_t& v1, cvec_t& v2) const;
00130
00131
00132 cvec_t& put(const cvec_t& v, size_t offset, size_t nbytes);
00133
00134 cvec_t& put(const void* p, size_t l);
00135
00136 cvec_t& put(const cvec_t& v);
00137
00138
00139 cvec_t& reset() {
00140 _cnt = _size = 0;
00141 return *this;
00142 }
00143
00144 cvec_t& set(const cvec_t& v1, const cvec_t& v2) {
00145 return reset().put(v1).put(v2);
00146 }
00147
00148 cvec_t& set(const cvec_t& v) {
00149 return reset().put(v);
00150 }
00151
00152
00153 cvec_t& set(const void* p, size_t l) {
00154 return reset().put(p, l);
00155 }
00156
00157
00158
00159 cvec_t& set(const cvec_t& v, size_t offset, size_t limit) {
00160 return reset().put(v, offset, limit);
00161 }
00162
00163
00164
00165 size_t size() const {
00166 return _size;
00167 }
00168
00169
00170 size_t copy_to(void* p, size_t limit = 0x7fffffff) const;
00171
00172 int cmp(const cvec_t& v, size_t* common_size = 0) const;
00173 int cmp(const void* s, size_t len) const;
00174
00175 static int cmp(const cvec_t& v1,
00176 const cvec_t& v2, size_t* common_size = 0) {
00177 return v1.cmp(v2, common_size);
00178 }
00179
00180
00181 int count() const {return _cnt;}
00182
00183 int checksum() const;
00184 void calc_kvl(uint4_t& h) const;
00185 void calc_kvl2(uint4_t& h) const;
00186 void init() { _cnt = _size = 0; }
00187
00188
00189
00190
00191
00192
00193
00194 void vecdelparts() { while(_cnt-->0) {
00195 delete[] _base[_cnt].ptr;
00196 _base[_cnt].ptr = NULL;
00197 _base[_cnt].len = 0;
00198 }
00199 init();
00200 }
00201 void delparts() { while(_cnt-->0) {
00202 delete _base[_cnt].ptr;
00203 _base[_cnt].ptr = NULL;
00204 _base[_cnt].len = 0;
00205 }
00206 init();
00207 }
00208
00209 bool is_pos_inf() const { return this == &pos_inf; }
00210 bool is_neg_inf() const { return this == &neg_inf; }
00211 bool is_null() const { return size() == 0; }
00212
00213 friend inline bool operator<(const cvec_t& v1, const cvec_t& v2);
00214 friend inline bool operator<=(const cvec_t& v1, const cvec_t& v2);
00215 friend inline bool operator>=(const cvec_t& v1, const cvec_t& v2);
00216 friend inline bool operator>(const cvec_t& v1, const cvec_t& v2);
00217 friend inline bool operator==(const cvec_t& v1, const cvec_t& v2);
00218 friend inline bool operator!=(const cvec_t& v1, const cvec_t& v2);
00219
00220 friend ostream& operator<<(ostream&, const cvec_t& v);
00221 friend istream& operator>>(istream&, cvec_t& v);
00222
00223 static cvec_t pos_inf;
00224 static cvec_t neg_inf;
00225
00226 private:
00227
00228 cvec_t(const cvec_t& v);
00229
00230
00231 bool _is_large() const {return _base != &_pair[0];}
00232
00233
00234 int _max_cnt() const {
00235 return (int)(_is_large() ? _pair[0].len : (int)max_small);
00236 }
00237
00238 void _grow(int total_cnt);
00239
00240
00241
00242 cvec_t& operator=(cvec_t);
00243
00244 size_t recalc_size() const;
00245 bool check_size() const;
00246
00247 public:
00248 bool is_zvec() const {
00249 #if W_DEBUG_LEVEL > 2
00250 if(count()>0) {
00251 if(_pair[0].ptr == zero_location) {
00252 w_assert3(count() == 1);
00253 }
00254 }
00255 #endif
00256 return (count()==0)
00257 ||
00258 (count() == 1 && _pair[0].ptr == zero_location);
00259 }
00260 };
00261
00262
00263
00264
00265
00266
00267 class vec_t : public cvec_t {
00268 public:
00269
00270 vec_t() : cvec_t() {};
00271
00272 vec_t(const cvec_t& v1, const cvec_t& v2) : cvec_t(v1, v2) {};
00273
00274 vec_t(const void* p, size_t l) : cvec_t(p, l) {};
00275
00276 vec_t(const vec_t& v, size_t offset, size_t limit)
00277 : cvec_t(v, offset, limit) {};
00278
00279 vec_t(const vec_t&v) : cvec_t() {
00280 reset().put(v);
00281 }
00282
00283
00284
00285
00286
00287
00288
00289 const vec_t& copy_from(
00290 const void* p,
00291 size_t limit,
00292 size_t offset = 0) const;
00293
00294
00295
00296
00297
00298
00299
00300 vec_t& copy_from(const cvec_t& v);
00301
00302
00303
00304
00305
00306
00307
00308 vec_t& copy_from(
00309 const cvec_t& v,
00310 size_t offset,
00311 size_t limit,
00312 size_t myoffset = 0);
00313
00314
00315 CADDR_T ptr(int index) const { return (index >= 0 && index < _cnt) ?
00316 _base[index].ptr : (CADDR_T) NULL; }
00317
00318 size_t len(int index) const { return (index >= 0 && index < _cnt) ?
00319 _base[index].len : 0; }
00320
00321
00322
00323
00324 void mkchunk( int maxsize,
00325 int skip,
00326 vec_t &result
00327 ) const;
00328
00329
00330
00331 static vec_t& pos_inf;
00332
00333 static vec_t& neg_inf;
00334
00335 private:
00336
00337 vec_t& operator=(vec_t);
00338
00339 };
00340
00341 inline bool operator<(const cvec_t& v1, const cvec_t& v2)
00342 {
00343 return v1.cmp(v2) < 0;
00344 }
00345
00346 inline bool operator<=(const cvec_t& v1, const cvec_t& v2)
00347 {
00348 return v1.cmp(v2) <= 0;
00349 }
00350
00351 inline bool operator>=(const cvec_t& v1, const cvec_t& v2)
00352 {
00353 return v1.cmp(v2) >= 0;
00354 }
00355
00356 inline bool operator>(const cvec_t& v1, const cvec_t& v2)
00357 {
00358 return v1.cmp(v2) > 0;
00359 }
00360
00361 inline bool operator==(const cvec_t& v1, const cvec_t& v2)
00362 {
00363 return (&v1==&v2) || v1.cmp(v2) == 0;
00364 }
00365
00366 inline bool operator!=(const cvec_t& v1, const cvec_t& v2)
00367 {
00368 return ! (v1 == v2);
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 class zvec_t : public vec_t {
00381 public:
00382 zvec_t() : vec_t(zero_location,0) {};
00383 zvec_t(size_t l) : vec_t(zero_location, l) {};
00384 zvec_t &put(size_t l) { reset().put(zero_location,l); return *this; }
00385 private:
00386
00387 zvec_t(const zvec_t&) :vec_t(zero_location, 0) {}
00388 zvec_t &operator=(zvec_t);
00389
00390 zvec_t(const cvec_t& v1, const cvec_t& v2);
00391 zvec_t(const void* p, size_t l);
00392 zvec_t(const vec_t& v, size_t offset, size_t limit);
00393 };
00394
00395
00396
00397 #endif