SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ds.h
Go to the documentation of this file.
1 // Address-Pointer
3 template <class TRec>
4 class TAPt{
5 private:
6  TRec* Addr;
7 public:
8  TAPt(): Addr(NULL){}
9  TAPt(const TAPt& Pt): Addr(Pt.Addr){}
10  TAPt(TRec* _Addr): Addr(_Addr){}
12  void Save(TSOut&) const {Fail;}
13 
14  TAPt& operator=(const TAPt& Pt){Addr=Pt.Addr; return *this;}
15  TAPt& operator=(TRec* _Addr){Addr=_Addr; return *this;}
16  bool operator==(const TAPt& Pt) const {return *Addr==*Pt.Addr;}
17  bool operator!=(const TAPt& Pt) const {return *Addr!=*Pt.Addr;}
18  bool operator<(const TAPt& Pt) const {return *Addr<*Pt.Addr;}
19 
20  TRec* operator->() const {Assert(Addr!=NULL); return Addr;}
21  TRec& operator*() const {Assert(Addr!=NULL); return *Addr;}
22  TRec& operator[](const int& RecN) const {
23  Assert(Addr!=NULL); return Addr[RecN];}
24  TRec* operator()() const {return Addr;}
25 
26  bool Empty() const {return Addr==NULL;}
27 };
28 
30 // Pair
31 template <class TVal1, class TVal2>
32 class TPair{
33 public:
34  TVal1 Val1;
35  TVal2 Val2;
36 public:
37  TPair(): Val1(), Val2(){}
38  TPair(const TPair& Pair): Val1(Pair.Val1), Val2(Pair.Val2){}
39  TPair(const TVal1& _Val1, const TVal2& _Val2): Val1(_Val1), Val2(_Val2){}
40  explicit TPair(TSIn& SIn): Val1(SIn), Val2(SIn){}
41  void Save(TSOut& SOut) const {
42  Val1.Save(SOut); Val2.Save(SOut);}
43  void Load(TSIn& SIn) {Val1.Load(SIn); Val2.Load(SIn);}
44  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
45  void SaveXml(TSOut& SOut, const TStr& Nm) const;
46 
47  TPair& operator=(const TPair& Pair){
48  if (this!=&Pair){Val1=Pair.Val1; Val2=Pair.Val2;} return *this;}
49  bool operator==(const TPair& Pair) const {
50  return (Val1==Pair.Val1)&&(Val2==Pair.Val2);}
51  bool operator<(const TPair& Pair) const {
52  return (Val1<Pair.Val1)||((Val1==Pair.Val1)&&(Val2<Pair.Val2));}
53 
54  int GetMemUsed() const {return Val1.GetMemUsed()+Val2.GetMemUsed();}
55 
56  int GetPrimHashCd() const {return TPairHashImpl::GetHashCd(Val1.GetPrimHashCd(), Val2.GetPrimHashCd()); }
57  int GetSecHashCd() const {return TPairHashImpl::GetHashCd(Val2.GetSecHashCd(), Val1.GetSecHashCd()); }
58 
59  void GetVal(TVal1& _Val1, TVal2& _Val2) const {_Val1=Val1; _Val2=Val2;}
60  const TVal1& GetVal1() const { return Val1;}
61  const TVal2& GetVal2() const { return Val2;}
62  TStr GetStr() const {
63  return TStr("Pair(")+Val1.GetStr()+", "+Val2.GetStr()+")";}
64 };
65 
66 template <class TVal1, class TVal2, class TSizeTy>
67 void GetSwitchedPrV(const TVec<TPair<TVal1, TVal2>, TSizeTy>& SrcPrV, TVec<TPair<TVal2, TVal1>, TSizeTy>& DstPrV){
68  const TSizeTy Prs = SrcPrV.Len();
69  DstPrV.Gen(Prs, 0);
70  for (TSizeTy PrN=0; PrN<Prs; PrN++){
71  const TPair<TVal1, TVal2>& SrcPr=SrcPrV[PrN];
72  DstPrV.Add(TPair<TVal2, TVal1>(SrcPr.Val2, SrcPr.Val1));
73  }
74 }
75 
114 
116 template <class TVal1, class TVal2>
118 private:
119  bool IsAsc;
120 public:
121  TCmpPairByVal2(const bool& AscSort=true) : IsAsc(AscSort) { }
122  bool operator () (const TPair<TVal1, TVal2>& P1, const TPair<TVal1, TVal2>& P2) const {
123  if (IsAsc) { return P1.Val2 < P2.Val2; } else { return P2.Val2 < P1.Val2; }
124  }
125 };
126 
128 // Triple
129 template <class TVal1, class TVal2, class TVal3>
130 class TTriple{
131 public:
132  TVal1 Val1;
133  TVal2 Val2;
134  TVal3 Val3;
135 public:
136  TTriple(): Val1(), Val2(), Val3(){}
137  TTriple(const TTriple& Triple):
138  Val1(Triple.Val1), Val2(Triple.Val2), Val3(Triple.Val3){}
139  TTriple(const TVal1& _Val1, const TVal2& _Val2, const TVal3& _Val3):
140  Val1(_Val1), Val2(_Val2), Val3(_Val3){}
141  explicit TTriple(TSIn& SIn): Val1(SIn), Val2(SIn), Val3(SIn){}
142  void Save(TSOut& SOut) const {
143  Val1.Save(SOut); Val2.Save(SOut); Val3.Save(SOut);}
144  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
145  void SaveXml(TSOut& SOut, const TStr& Nm) const;
146 
147  TTriple& operator=(const TTriple& Triple){
148  if (this!=&Triple){Val1=Triple.Val1; Val2=Triple.Val2; Val3=Triple.Val3;}
149  return *this;}
150  bool operator==(const TTriple& Triple) const {
151  return (Val1==Triple.Val1)&&(Val2==Triple.Val2)&&(Val3==Triple.Val3);}
152  bool operator<(const TTriple& Triple) const {
153  return (Val1<Triple.Val1)||((Val1==Triple.Val1)&&(Val2<Triple.Val2))||
154  ((Val1==Triple.Val1)&&(Val2==Triple.Val2)&&(Val3<Triple.Val3));}
155 
156  int GetPrimHashCd() const {return TPairHashImpl::GetHashCd(TPairHashImpl::GetHashCd(Val1.GetPrimHashCd(), Val2.GetPrimHashCd()), Val3.GetPrimHashCd()); }
157  int GetSecHashCd() const {return TPairHashImpl::GetHashCd(TPairHashImpl::GetHashCd(Val2.GetSecHashCd(), Val3.GetSecHashCd()), Val1.GetSecHashCd()); }
158  int GetMemUsed() const {return Val1.GetMemUsed()+Val2.GetMemUsed()+Val3.GetMemUsed();}
159 
160  void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3) const {
161  _Val1=Val1; _Val2=Val2; _Val3=Val3;}
162 
163  const TVal1& GetVal1() const { return Val1;}
164  const TVal2& GetVal2() const { return Val2;}
165  const TVal3& GetVal3() const { return Val3;}
166 };
167 
191 
193 template <class TVal1, class TVal2, class TVal3>
195 private:
196  bool IsAsc;
197 public:
198  TCmpTripleByVal2(const bool& AscSort=true) : IsAsc(AscSort) { }
200  if (IsAsc) { return T1.Val2 < T2.Val2; } else { return T2.Val2 < T1.Val2; }
201  }
202 };
203 
205 template <class TVal1, class TVal2, class TVal3>
207 private:
208  bool IsAsc;
209 public:
210  TCmpTripleByVal3(const bool& AscSort=true) : IsAsc(AscSort) { }
212  if (IsAsc) { return T1.Val3 < T2.Val3; } else { return T2.Val3 < T1.Val3; }
213  }
214 };
215 
217 // Quad
218 template <class TVal1, class TVal2, class TVal3, class TVal4>
219 class TQuad{
220 public:
221  TVal1 Val1;
222  TVal2 Val2;
223  TVal3 Val3;
224  TVal4 Val4;
225 public:
226  TQuad():
227  Val1(), Val2(), Val3(), Val4(){}
228  TQuad(const TQuad& Quad):
229  Val1(Quad.Val1), Val2(Quad.Val2), Val3(Quad.Val3), Val4(Quad.Val4){}
230  TQuad(const TVal1& _Val1, const TVal2& _Val2, const TVal3& _Val3, const TVal4& _Val4):
231  Val1(_Val1), Val2(_Val2), Val3(_Val3), Val4(_Val4){}
232  explicit TQuad(TSIn& SIn):
233  Val1(SIn), Val2(SIn), Val3(SIn), Val4(SIn){}
234  void Save(TSOut& SOut) const {
235  Val1.Save(SOut); Val2.Save(SOut); Val3.Save(SOut); Val4.Save(SOut);}
236  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
237  void SaveXml(TSOut& SOut, const TStr& Nm) const;
238 
239  TQuad& operator=(const TQuad& Quad){
240  if (this!=&Quad){
241  Val1=Quad.Val1; Val2=Quad.Val2; Val3=Quad.Val3; Val4=Quad.Val4;}
242  return *this;}
243  bool operator==(const TQuad& Quad) const {
244  return (Val1==Quad.Val1)&&(Val2==Quad.Val2)&&(Val3==Quad.Val3)&&(Val4==Quad.Val4);}
245  bool operator<(const TQuad& Quad) const {
246  return (Val1<Quad.Val1)||((Val1==Quad.Val1)&&(Val2<Quad.Val2))||
247  ((Val1==Quad.Val1)&&(Val2==Quad.Val2)&&(Val3<Quad.Val3))||
248  ((Val1==Quad.Val1)&&(Val2==Quad.Val2)&&(Val3==Quad.Val3)&&(Val4<Quad.Val4));}
249 
250  int GetPrimHashCd() const {return TPairHashImpl::GetHashCd(TPairHashImpl::GetHashCd(Val1.GetPrimHashCd(), Val2.GetPrimHashCd()), TPairHashImpl::GetHashCd(Val3.GetPrimHashCd(), Val4.GetPrimHashCd())); }
251  int GetSecHashCd() const {return TPairHashImpl::GetHashCd(TPairHashImpl::GetHashCd(Val2.GetSecHashCd(), Val3.GetSecHashCd()), TPairHashImpl::GetHashCd(Val4.GetSecHashCd(), Val1.GetSecHashCd())); }
252 
253  void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3, TVal4& _Val4) const {
254  _Val1=Val1; _Val2=Val2; _Val3=Val3; _Val4=Val4;}
255  const TVal1& GetVal1() const { return Val1;}
256  const TVal2& GetVal2() const { return Val2;}
257  const TVal3& GetVal3() const { return Val3;}
258  const TVal4& GetVal4() const { return Val4;}
259 };
260 
268 
270 // Tuple
271 template<class TVal, int NVals>
272 class TTuple {
273 private:
274  TVal ValV [NVals];
275 public:
276  TTuple(){}
277  TTuple(const TVal& InitVal) { for (int i=0; i<Len(); i++) ValV[i]=InitVal; }
278  TTuple(const TTuple& Tup) { for (int i=0; i<Len(); i++) ValV[i]=Tup[i]; }
279  TTuple(TSIn& SIn) { for (int i=0; i<Len(); i++) ValV[i].Load(SIn); }
280  void Save(TSOut& SOut) const { for (int i=0; i<Len(); i++) ValV[i].Save(SOut); }
281  void Load(TSIn& SIn) { for (int i=0; i<Len(); i++) ValV[i].Load(SIn); }
282 
283  int Len() const { return NVals; }
284  TVal& operator[] (const int& ValN) { return ValV[ValN]; }
285  const TVal& operator[] (const int& ValN) const { return ValV[ValN]; }
286  TTuple& operator = (const TTuple& Tup) { if (this != & Tup) {
287  for (int i=0; i<Len(); i++) ValV[i]=Tup[i]; } return *this; }
288  bool operator == (const TTuple& Tup) const {
289  if (Len()!=Tup.Len()) { return false; } if (&Tup==this) { return true; }
290  for (int i=0; i<Len(); i++) if(ValV[i]!=Tup[i]){return false;} return true; }
291  bool operator < (const TTuple& Tup) const {
292  if (Len() == Tup.Len()) { for (int i=0; i<Len(); i++) {
293  if(ValV[i]<Tup[i]){return true;} else if(ValV[i]>Tup[i]){return false;} } return false; }
294  else { return Len() < Tup.Len(); } }
295  void Sort(const bool& Asc=true);
296  int FindMx() const;
297  int FindMn() const;
298  int GetPrimHashCd() const { int hc = 0;
299  for (int i = 0; i < NVals; i++) { hc = TPairHashImpl::GetHashCd(hc, ValV[i].GetPrimHashCd()); }
300  return hc; }
301  int GetSecHashCd() const { int hc = 0;
302  for (int i = 1; i < NVals; i++) { hc = TPairHashImpl::GetHashCd(hc, ValV[i].GetSecHashCd()); }
303  if (NVals > 0) { hc = TPairHashImpl::GetHashCd(hc, ValV[0].GetSecHashCd()); }
304  return hc; }
305 
306  TStr GetStr() const { TChA ValsStr;
307  for (int i=0; i<Len(); i++) { ValsStr+=" "+ValV[i].GetStr(); }
308  return TStr::Fmt("Tuple(%d):", Len())+ValsStr; }
309 };
310 
311 template<class TVal, int NVals>
312 void TTuple<TVal, NVals>::Sort(const bool& Asc) {
313  TVec<TVal, int> V(NVals);
314  for (int i=0; i<NVals; i++) { V.Add(ValV[i]); }
315  V.Sort(Asc);
316  for (int i=0; i<NVals; i++) { ValV[i] = V[i]; }
317 }
318 
319 template<class TVal, int NVals>
321  TVal MxVal = ValV[0];
322  int ValN = 0;
323  for (int i = 1; i < NVals; i++) {
324  if (MxVal<ValV[i]) {
325  MxVal=ValV[i]; ValN=i;
326  }
327  }
328  return ValN;
329 }
330 
331 template<class TVal, int NVals>
333  TVal MnVal = ValV[0];
334  int ValN = 0;
335  for (int i = 1; i < NVals; i++) {
336  if (MnVal>ValV[i]) {
337  MnVal=ValV[i]; ValN=i;
338  }
339  }
340  return ValN;
341 }
342 
344 // Key-Data
345 template <class TKey, class TDat>
346 class TKeyDat{
347 public:
348  TKey Key;
349  TDat Dat;
350 public:
351  TKeyDat(): Key(), Dat(){}
352  TKeyDat(const TKeyDat& KeyDat): Key(KeyDat.Key), Dat(KeyDat.Dat){}
353  explicit TKeyDat(const TKey& _Key): Key(_Key), Dat(){}
354  TKeyDat(const TKey& _Key, const TDat& _Dat): Key(_Key), Dat(_Dat){}
355  explicit TKeyDat(TSIn& SIn): Key(SIn), Dat(SIn){}
356  void Save(TSOut& SOut) const {Key.Save(SOut); Dat.Save(SOut);}
357  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
358  void SaveXml(TSOut& SOut, const TStr& Nm) const;
359 
360  TKeyDat& operator=(const TKeyDat& KeyDat){
361  if (this!=&KeyDat){Key=KeyDat.Key; Dat=KeyDat.Dat;} return *this;}
362  bool operator==(const TKeyDat& KeyDat) const {return Key==KeyDat.Key;}
363  bool operator<(const TKeyDat& KeyDat) const {return Key<KeyDat.Key;}
364 
365  int GetPrimHashCd() const {return Key.GetPrimHashCd();}
366  int GetSecHashCd() const {return Key.GetSecHashCd();}
367 };
368 
369 template <class TKey, class TDat>
370 void GetSwitchedKdV(const TVec<TKeyDat<TKey, TDat>, int>& SrcKdV, TVec<TKeyDat<TDat, TKey>, int>& DstKdV){
371  const int Kds=SrcKdV.Len();
372  DstKdV.Gen(Kds, 0);
373  for (int KdN=0; KdN<Kds; KdN++){
374  const TKeyDat<TKey, TDat>& SrcKd=SrcKdV[KdN];
375  DstKdV.Add(TKeyDat<TDat, TKey>(SrcKd.Dat, SrcKd.Key));
376  }
377 }
378 
406 
407 // Key-Data comparator
408 
409 template <class TVal1, class TVal2>
411 private:
412  bool IsAsc;
413 public:
414  TCmpKeyDatByDat(const bool& AscSort=true) : IsAsc(AscSort) { }
415  bool operator () (const TKeyDat<TVal1, TVal2>& P1, const TKeyDat<TVal1, TVal2>& P2) const {
416  if (IsAsc) { return P1.Dat < P2.Dat; } else { return P2.Dat < P1.Dat; }
417  }
418 };
419 
420 //#//////////////////////////////////////////////
422 
429 template <class TVal, class TSizeTy = int>
430 class TVec{
431 public:
432  typedef TVal* TIter;
433 protected:
434  TSizeTy MxVals;
435  TSizeTy Vals;
436  TVal* ValT;
437  bool IsShM;
438  void Resize(const TSizeTy& _MxVals=-1);
441  TStr GetXOutOfBoundsErrMsg(const TSizeTy& ValN) const;
442 public:
443  TVec(): MxVals(0), Vals(0), ValT(NULL), IsShM(false) {}
444  TVec(const TVec<TVal, TSizeTy>& Vec);
446  explicit TVec(const TSizeTy& _Vals){
447  IsShM = false;
448  IAssert(0<=_Vals); MxVals=Vals=_Vals;
449  if (_Vals==0){ValT=NULL;} else {ValT=new TVal[_Vals];}}
451  TVec(const TSizeTy& _MxVals, const TSizeTy& _Vals){
452  IsShM = false;
453  IAssert((0<=_Vals)&&(_Vals<=_MxVals)); MxVals=_MxVals; Vals=_Vals;
454  if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
456 
459  explicit TVec(TVal *_ValT, const TSizeTy& _Vals):
460  MxVals(-1), Vals(_Vals), ValT(_ValT), IsShM(false){}
461  ~TVec() {if ((ValT!=NULL) && (MxVals!=-1)) {delete[] ValT;}}
462  explicit TVec(TSIn& SIn): MxVals(0), Vals(0), ValT(NULL), IsShM(false) {Load(SIn);}
464 
469  void LoadShM(TShMIn& ShMIn);
471  template <typename TLoadShMElem>
472  void LoadShM(TShMIn& ShMIn, TLoadShMElem LoadFromShMFn) {
473  if ((ValT!=NULL) && (MxVals!=-1)) {delete[] ValT;}
474  ShMIn.Load(MxVals);
475  ShMIn.Load(Vals);
476  if (MxVals == 0) {
477  ValT = NULL;
478  } else {
479  ValT=new TVal[MxVals];
480  for (TSizeTy ValN=0; ValN<Vals; ValN++) {
481  LoadFromShMFn(ValT+ValN, ShMIn);
482  }
483  }
484  IsShM = false;
485  }
486 
487  void Load(TSIn& SIn);
488  void Save(TSOut& SOut) const;
489  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
490  void SaveXml(TSOut& SOut, const TStr& Nm) const;
491 
495  TVec<TVal, TSizeTy>& operator+(const TVal& Val){Add(Val); return *this;}
497  bool operator==(const TVec<TVal, TSizeTy>& Vec) const;
499 
501  bool operator<(const TVec<TVal, TSizeTy>& Vec) const;
503  const TVal& operator[](const TSizeTy& ValN) const {
504  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
505  return ValT[ValN];}
507  TVal& operator[](const TSizeTy& ValN){
508  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
509  return ValT[ValN];}
511  TSizeTy GetMemUsed() const {
512  return TSizeTy(2*sizeof(TSizeTy)+sizeof(TVal*)+MxVals*sizeof(TVal));}
514  TSizeTy GetMemSize() const {
515  return TSizeTy(2*sizeof(TVal)+sizeof(TSizeTy)*Vals);}
516 
518  int GetPrimHashCd() const;
520  int GetSecHashCd() const;
521 
523  void Gen(const TSizeTy& _Vals){ IAssert(0<=_Vals);
524  if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=Vals=_Vals;
525  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}}
527  void Gen(const TSizeTy& _MxVals, const TSizeTy& _Vals){ IAssert((0<=_Vals)&&(_Vals<=_MxVals));
528  if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=_MxVals; Vals=_Vals;
529  if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
531 
534  void GenExt(TVal *_ValT, const TSizeTy& _Vals){
535  if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
536  MxVals=-1; Vals=_Vals; ValT=_ValT;}
538 
541  bool IsExt() const {return MxVals==-1;}
543  void Reserve(const TSizeTy& _MxVals){Resize(_MxVals);}
545  void Reserve(const TSizeTy& _MxVals, const TSizeTy& _Vals){ IAssert((0<=_Vals)&&(_Vals<=_MxVals)); Resize(_MxVals); Vals=_Vals;}
547 
550  void Clr(const bool& DoDel=true, const TSizeTy& NoDelLim=-1);
552 
554  void Trunc(const TSizeTy& _Vals=-1);
556  void Reduce(const TSizeTy& _Vals=-1) {Vals = _Vals;}
558  void Pack();
560 
562  void MoveFrom(TVec<TVal, TSizeTy>& Vec);
564  void CopyUniqueFrom(TVec<TVal, TSizeTy>& Vec, TInt Offset, TInt Sz);
566  void Swap(TVec<TVal, TSizeTy>& Vec);
568 
570  bool Empty() const {return Vals==0;}
572 
575  TSizeTy Len() const {return Vals;}
577  TSizeTy Reserved() const {return MxVals;}
579  const TVal& Last() const {return GetVal(Len()-1);}
581  TVal& Last(){return GetVal(Len()-1);}
583  TSizeTy LastValN() const {return Len()-1;}
585  const TVal& LastLast() const { AssertR(1<Vals, GetXOutOfBoundsErrMsg(Vals-2)); return ValT[Vals-2];}
587  TVal& LastLast(){ AssertR(1<Vals, GetXOutOfBoundsErrMsg(Vals-2)); return ValT[Vals-2];}
589  const TVal& GetRndVal(TRnd& Rnd=TInt::Rnd) const { return GetVal(Rnd.GetUniDevInt(Len())); }
591  TVal& GetRndVal(TRnd& Rnd=TInt::Rnd) { return GetVal(Rnd.GetUniDevInt(Len())); }
593  TIter BegI() const {return ValT;}
595  TIter EndI() const {return ValT+Vals;}
597  TIter GetI(const TSizeTy& ValN) const {return ValT+ValN;}
598 
600 
602  TSizeTy Add(){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
603  if (Vals==MxVals){Resize();} return Vals++;}
604 
606 
608  TSizeTy Add(const TVal& Val){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
609  if (Vals==MxVals){Resize();} ValT[Vals]=Val; return Vals++;}
610  TSizeTy Add(TVal& Val){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
611  if (Vals==MxVals){Resize();} ValT[Vals]=Val; return Vals++;}
613  TSizeTy Add(const TVal& Val, const TSizeTy& ResizeLen){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
614  if (Vals==MxVals){Resize(MxVals+ResizeLen);} ValT[Vals]=Val; return Vals++;}
615 #ifdef USE_OPENMP
616  TSizeTy AddMP(const TVal& Val){ const int Idx = __sync_fetch_and_add(&Vals, 1);
618  ValT[Idx]=Val; return Idx;}
620 
622  TSizeTy MoveLastMP(const TVal& Val, int Inc){ const int Idx = __sync_fetch_and_add(&Vals, Inc);
623  return Idx;}
624 #endif
625  TSizeTy AddV(const TVec<TVal, TSizeTy>& ValV);
628 
630  TSizeTy AddSorted(const TVal& Val, const bool& Asc=true, const TSizeTy& _MxVals=-1);
632 
634  TSizeTy AddBackSorted(const TVal& Val, const bool& Asc);
636 
638  TSizeTy AddMerged(const TVal& Val);
640 
642  TSizeTy AddVMerged(const TVec<TVal, TSizeTy>& ValV);
644 
647  TSizeTy AddUnique(const TVal& Val);
649  const TVal& GetVal(const TSizeTy& ValN) const {return operator[](ValN);}
651  TVal& GetVal(const TSizeTy& ValN){return operator[](ValN);}
653  void SetVal(const TSizeTy& ValN, const TVal& Val){
654  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
655  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN)); ValT[ValN] = Val;}
657  void GetSubValV(const TSizeTy& BValN, const TSizeTy& EValN, TVec<TVal, TSizeTy>& ValV) const;
659  void Ins(const TSizeTy& ValN, const TVal& Val);
661  void Del(const TSizeTy& ValN);
663  void Del(const TSizeTy& MnValN, const TSizeTy& MxValN);
665  void DelLast(){Del(Len()-1);}
667  bool DelIfIn(const TVal& Val);
669  void DelAll(const TVal& Val);
671  void PutAll(const TVal& Val);
672 
674  void Swap(const TSizeTy& ValN1, const TSizeTy& ValN2){EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
675  const TVal Val=ValT[ValN1]; ValT[ValN1]=ValT[ValN2]; ValT[ValN2]=Val;}
677  static void SwapI(TIter LVal, TIter RVal){const TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
678 
680 
684  bool NextPerm();
686 
688  bool PrevPerm();
689 
690  // Sorting functions
692  TSizeTy GetPivotValN(const TSizeTy& LValN, const TSizeTy& RValN) const;
694 
696  void BSort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc);
698 
700  void ISort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc);
702 
705  TSizeTy Partition(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc);
707 
710  void QSort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc);
712 
715  void Sort(const bool& Asc=true);
717  bool IsSorted(const bool& Asc=true) const;
719  void Shuffle(TRnd& Rnd);
721  void Reverse();
723  void Reverse(TSizeTy LValN, TSizeTy RValN){ Assert(LValN>=0 && RValN<Len()); while (LValN < RValN){Swap(LValN++, RValN--);} }
725  void Merge();
726 
728  template <class TCmp>
729  static TIter GetPivotValNCmp(const TIter& BI, const TIter& EI, const TCmp& Cmp) {
730  TSizeTy SubVals=TSizeTy(EI-BI); if (SubVals > TInt::Mx-1) { SubVals = TInt::Mx-1; }
731  const TSizeTy ValN1=TInt::GetRnd(SubVals), ValN2=TInt::GetRnd(SubVals), ValN3=TInt::GetRnd(SubVals);
732  const TVal& Val1 = *(BI+ValN1); const TVal& Val2 = *(BI+ValN2); const TVal& Val3 = *(BI+ValN3);
733  if (Cmp(Val1, Val2)) {
734  if (Cmp(Val2, Val3)) return BI+ValN2;
735  else if (Cmp(Val3, Val1)) return BI+ValN1;
736  else return BI+ValN3;
737  } else {
738  if (Cmp(Val1, Val3)) return BI+ValN1;
739  else if (Cmp(Val3, Val2)) return BI+ValN2;
740  else return BI+ValN3; } }
742  template <class TCmp>
743  static TIter PartitionCmp(TIter BI, TIter EI, const TVal Pivot, const TCmp& Cmp) {
744  forever {
745  while (Cmp(*BI, Pivot)){++BI;} --EI;
746  while (Cmp(Pivot, *EI)){--EI;}
747  if (!(BI<EI)){return BI;} SwapI(BI, EI); ++BI; } }
749  template <class TCmp>
750  static void BSortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
751  for (TIter i = BI; i != EI; ++i) {
752  for (TIter j = EI-1; j != i; --j) {
753  if (Cmp(*j, *(j-1))) { SwapI(j, j-1); } } } }
755  template <class TCmp>
756  static void ISortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
757  if (BI + 1 < EI) {
758  for (TIter i = BI, j; i != EI; ++i) { TVal Tmp=*i; j=i;
759  while (j > BI && Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; } *j=Tmp; } } }
761  template <class TCmp>
762  static void QSortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
763  if (BI + 1 < EI) {
764  if (EI - BI < 20) { ISortCmp(BI, EI, Cmp); }
765  else { const TVal Val = *GetPivotValNCmp(BI, EI, Cmp);
766  TIter Split = PartitionCmp(BI, EI, Val, Cmp);
767  QSortCmp(BI, Split, Cmp); QSortCmp(Split, EI, Cmp); } } }
769  template <class TCmp>
770  void SortCmp(const TCmp& Cmp){ QSortCmp(BegI(), EndI(), Cmp);}
772  template <class TCmp>
773  bool IsSortedCmp(const TCmp& Cmp) const {
774  if (EndI() == BegI()) return true;
775  for (TIter i = BegI(); i != EndI()-1; ++i) {
776  if (Cmp(*(i+1), *i)){return false;} } return true; }
778  void Intrs(const TVec<TVal, TSizeTy>& ValV);
780  void Union(const TVec<TVal, TSizeTy>& ValV);
782 
784  void Diff(const TVec<TVal, TSizeTy>& ValV);
786  void Intrs(const TVec<TVal, TSizeTy>& ValV, TVec<TVal, TSizeTy>& DstValV) const;
788  void Union(const TVec<TVal, TSizeTy>& ValV, TVec<TVal, TSizeTy>& DstValV) const;
790 
792  void Diff(const TVec<TVal, TSizeTy>& ValV, TVec<TVal, TSizeTy>& DstValV) const;
794  TSizeTy IntrsLen(const TVec<TVal, TSizeTy>& ValV) const;
796  TSizeTy UnionLen(const TVec<TVal, TSizeTy>& ValV) const;
797 
799  TSizeTy Count(const TVal& Val) const;
801 
804  TSizeTy SearchBin(const TVal& Val) const;
806 
808  TSizeTy SearchBin(const TVal& Val, TSizeTy& InsValN) const;
810 
812  TSizeTy SearchBinLeft(const TVal& Val, TSizeTy& InsValN) const;
814 
817  TSizeTy SearchForw(const TVal& Val, const TSizeTy& BValN=0) const;
819 
821  TSizeTy SearchBack(const TVal& Val) const;
823 
825  TSizeTy SearchVForw(const TVec<TVal, TSizeTy>& ValV, const TSizeTy& BValN=0) const;
826 
828  bool IsIn(const TVal& Val) const {return SearchForw(Val)!=-1;}
830 
832  bool IsIn(const TVal& Val, TSizeTy& ValN) const { ValN=SearchForw(Val); return ValN!=-1;}
834 
836  bool IsInBin(const TVal& Val) const {return SearchBin(Val)!=-1;}
838  const TVal& GetDat(const TVal& Val) const { return GetVal(SearchForw(Val));}
840 
842  TVal& GetAddDat(const TVal& Val){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
843  const TSizeTy ValN=SearchForw(Val); if (ValN==-1){Add(Val); return Last();} else {return GetVal(ValN);}}
845  TSizeTy GetMxValN() const;
846 
848  static TVec<TVal, TSizeTy> GetV(const TVal& Val1){
849  TVec<TVal, TSizeTy> V(1, 0); V.Add(Val1); return V;}
851  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2){
852  TVec<TVal, TSizeTy> V(2, 0); V.Add(Val1); V.Add(Val2); return V;}
854  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3){
855  TVec<TVal, TSizeTy> V(3, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); return V;}
857  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4){
858  TVec<TVal, TSizeTy> V(4, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); return V;}
860  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5){
861  TVec<TVal, TSizeTy> V(5, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); return V;}
863  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5, const TVal& Val6){
864  TVec<TVal, TSizeTy> V(6, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); return V;}
866  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5, const TVal& Val6, const TVal& Val7){
867  TVec<TVal, TSizeTy> V(7, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); V.Add(Val7); return V;}
869  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5, const TVal& Val6, const TVal& Val7, const TVal& Val8){
870  TVec<TVal, TSizeTy> V(8, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); V.Add(Val7); V.Add(Val8); return V;}
872  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5, const TVal& Val6, const TVal& Val7, const TVal& Val8, const TVal& Val9){
873  TVec<TVal, TSizeTy> V(9, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); V.Add(Val7); V.Add(Val8); V.Add(Val9); return V;}
874 };
875 
876 template <class TVal, class TSizeTy>
877 void TVec<TVal, TSizeTy>::Resize(const TSizeTy& _MxVals){
878  IAssertR(MxVals!=-1 || IsShM, TStr::Fmt("Can not increase the capacity of the vector. %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", GetTypeNm(*this).CStr()).CStr());
879  IAssertR(MxVals!=(TInt::Mx-1024), TStr::Fmt("Buffer size at maximum. %s. [Program refuses to allocate more memory. Solution-1: Send your test case to developers.]", GetTypeNm(*this).CStr()).CStr());
880  TSizeTy OldMxVals = MxVals;
881  if (MxVals == -1) {MxVals = Vals;}
882  if (_MxVals==-1){
883  if (Vals==0){MxVals=16;} else {MxVals*=2;}
884  } else {
885  if (_MxVals<=MxVals){return;} else {MxVals=_MxVals;}
886  }
887  if (MxVals < 0) {
888  MxVals = TInt::Mx-1024;
889  }
890  if (ValT==NULL){
891  try {
892  ValT=new TVal[MxVals];
893  }
894  catch (std::exception Ex){
895  FailR(TStr::Fmt("TVec::Resize: %s, Length:%s, Capacity:%s, New capacity:%s, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
896  Ex.what(), TInt::GetStr(Vals).CStr(), TInt::GetStr(MxVals).CStr(), TInt::GetStr(_MxVals).CStr(), GetTypeNm(*this).CStr()).CStr());}
897  } else {
898  TVal* NewValT = NULL;
899  try {
900  NewValT=new TVal[MxVals];
901  }
902  catch (std::exception Ex){
903  FailR(TStr::Fmt("TVec::Resize: %s, Length:%s, Capacity:%s, New capacity:%s, Type:%s [Program failed to allocate more memory. Solution-1: Get a bigger machine and a 64-bit compiler.]",
904  Ex.what(), TInt::GetStr(Vals).CStr(), TInt::GetStr(MxVals).CStr(), TInt::GetStr(_MxVals).CStr(), GetTypeNm(*this).CStr()).CStr());}
905  IAssert(NewValT!=NULL);
906  for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
907  if (OldMxVals != -1) {delete[] ValT;} ValT=NewValT;
908  }
909  IsShM = false;
910 }
911 
912 template <class TVal, class TSizeTy>
914  return TStr()+
915  "Index:"+TInt::GetStr(ValN)+
916  " Vals:"+TInt::GetStr(Vals)+
917  " MxVals:"+TInt::GetStr(MxVals)+
918  " Type:"+GetTypeNm(*this);
919 }
920 
921 template <class TVal, class TSizeTy>
923  MxVals=Vec.MxVals;
924  Vals=Vec.Vals;
925  if (MxVals==0) {ValT=NULL;} else {ValT=new TVal[MxVals];}
926  for (TSizeTy ValN=0; ValN<Vec.Vals; ValN++){ValT[ValN]=Vec.ValT[ValN];}
927  IsShM = false;
928 }
929 
930 
931 template <class TVal, class TSizeTy>
933  if ((ValT!=NULL) && (MxVals!=-1)) {delete[] ValT;}
934  ShMIn.Load(MxVals);
935  MxVals = -1;
936  ShMIn.Load(Vals);
937  if (MxVals == 0) {
938  ValT = NULL;
939  } else {
940  ValT = (TVal*)(ShMIn.AdvanceCursor(Vals*sizeof(TVal)));
941  IsShM = true;
942  }
943 }
944 
945 template <class TVal, class TSizeTy>
947  if ( (ValT!=NULL) && (MxVals!=-1)) {delete[] ValT;}
948  SIn.Load(MxVals); SIn.Load(Vals); MxVals=Vals;
949  if ( MxVals==0 ){ValT=NULL;} else {ValT=new TVal[MxVals];}
950  for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=TVal(SIn);}
951 }
952 
953 template <class TVal, class TSizeTy>
954 void TVec<TVal, TSizeTy>::Save(TSOut& SOut) const {
955  if (MxVals!=-1){SOut.Save(MxVals);} else {SOut.Save(Vals);}
956  SOut.Save(Vals);
957  for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
958 }
959 
960 template <class TVal, class TSizeTy>
962  if (this!=&Vec){
963  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
964  MxVals=Vals=Vec.Vals;
965  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
966  for (TSizeTy ValN=0; ValN<Vec.Vals; ValN++){ValT[ValN]=Vec.ValT[ValN];}
967  }
968  return *this;
969 }
970 
971 template <class TVal, class TSizeTy>
973  if (this==&Vec){return true;}
974  if (Len()!=Vec.Len()){return false;}
975  for (TSizeTy ValN=0; ValN<Vals; ValN++){
976  if (ValT[ValN]!=Vec.ValT[ValN]){return false;}}
977  return true;
978 }
979 
980 template <class TVal, class TSizeTy>
982  if (this==&Vec){return false;}
983  if (Len()==Vec.Len()){
984  for (TSizeTy ValN=0; ValN<Vals; ValN++){
985  if (ValT[ValN]<Vec.ValT[ValN]){return true;}
986  else if (ValT[ValN]>Vec.ValT[ValN]){return false;}
987  else {}
988  }
989  return false;
990  } else {
991  return Len()<Vec.Len();
992  }
993 }
994 
995 // Improved hashing of vectors (Jure Apr 20 2013)
996 // This change makes binary representation of vectors incompatible with previous code.
997 // Previous hash functions are available for compatibility in class TVecHashF_OldGLib
998 template <class TVal, class TSizeTy>
1000  int hc = 0;
1001  for (TSizeTy i=0; i<Vals; i++){
1002  hc = TPairHashImpl::GetHashCd(hc, ValT[i].GetPrimHashCd());
1003  }
1004  return hc;
1005 }
1006 
1007 // Improved hashing of vectors (Jure Apr 20 2013)
1008 // This change makes binary representation of vectors incompatible with previous code.
1009 // Previous hash functions are available for compatibility in class TVecHashF_OldGLib
1010 template <class TVal, class TSizeTy>
1012  int hc = 0;
1013  for (TSizeTy i=0; i<Vals; i++){
1014  hc = TPairHashImpl::GetHashCd(hc, ValT[i].GetSecHashCd());
1015  }
1016  if (Vals > 0) {
1017  hc = TPairHashImpl::GetHashCd(hc, ValT[0].GetSecHashCd()); }
1018  return hc;
1019 }
1020 
1021 template <class TVal, class TSizeTy>
1022 void TVec<TVal, TSizeTy>::Clr(const bool& DoDel, const TSizeTy& NoDelLim){
1023  if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){
1024  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
1025  MxVals=Vals=0; ValT=NULL;
1026  } else {
1027  IAssertR(MxVals!=-1 || IsShM, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1028  Vals=0;
1029  }
1030 }
1031 
1032 template <class TVal, class TSizeTy>
1033 void TVec<TVal, TSizeTy>::Trunc(const TSizeTy& _Vals){
1034  EAssertR(!(MxVals==-1 && IsShM), "Cannot truncate a shared memory vector");
1035  IAssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1036  IAssert((_Vals==-1)||(_Vals>=0));
1037  if ((_Vals!=-1)&&(_Vals>=Vals)){
1038  return;
1039  } else
1040  if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){
1041  if (ValT!=NULL){delete[] ValT;}
1042  MxVals=Vals=0; ValT=NULL;
1043  } else {
1044  if (_Vals==-1){
1045  if (MxVals==Vals){return;} else {MxVals=Vals;}
1046  } else {
1047  MxVals=Vals=_Vals;
1048  }
1049  TVal* NewValT=new TVal[MxVals];
1050  IAssert(NewValT!=NULL);
1051  for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1052  delete[] ValT; ValT=NewValT;
1053  }
1054 }
1055 
1056 template <class TVal, class TSizeTy>
1058  EAssertR(!(IsShM && (MxVals == -1)), "Cannot pack accessed shared memory");
1059  IAssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1060  if (Vals==0){
1061  if (ValT!=NULL){delete[] ValT;} ValT=NULL;
1062  } else
1063  if (Vals<MxVals){
1064  MxVals=Vals;
1065  TVal* NewValT=new TVal[MxVals];
1066  IAssert(NewValT!=NULL);
1067  for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1068  delete[] ValT; ValT=NewValT;
1069  }
1070 }
1071 
1072 template <class TVal, class TSizeTy>
1074  if (this!=&Vec){
1075  if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
1076  MxVals=Vec.MxVals; Vals=Vec.Vals; ValT=Vec.ValT;
1077  Vec.MxVals=0; Vec.Vals=0; Vec.ValT=NULL;
1078  }
1079 }
1080 
1081 template <class TVal, class TSizeTy>
1083  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1084  if (this!=&Vec){
1085  if (ValT!=NULL && MxVals!=-1 && MxVals < Sz){
1086  delete[] ValT;
1087  ValT=new TVal[Sz];
1088  }
1089  if (Sz == 0) { Vals = 0; return; }
1090  ValT[0] = Vec.ValT[Offset];
1091  Vals = 1;
1092  for (TSizeTy ValN=1; ValN<Sz; ValN++){
1093  if (ValT[Vals-1] != Vec.ValT[Offset+ValN]) {
1094  ValT[Vals++] = Vec.ValT[Offset+ValN];
1095  }
1096  }
1097  }
1098 }
1099 
1100 template <class TVal, class TSizeTy>
1102  if (this!=&Vec){
1103  ::Swap(MxVals, Vec.MxVals);
1104  ::Swap(Vals, Vec.Vals);
1105  ::Swap(ValT, Vec.ValT);
1106  }
1107 }
1108 
1109 template <class TVal, class TSizeTy>
1111  AssertR(MxVals!=-1 || IsShM, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1112  for (TSizeTy ValN=0; ValN<ValV.Vals; ValN++){Add(ValV[ValN]);}
1113  return Len();
1114 }
1115 
1116 template <class TVal, class TSizeTy>
1117 TSizeTy TVec<TVal, TSizeTy>::AddSorted(const TVal& Val, const bool& Asc, const TSizeTy& _MxVals){
1118  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1119  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1120  TSizeTy ValN=Add(Val);
1121  if (Asc){
1122  while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){
1123  Swap(ValN, ValN-1); ValN--;}
1124  } else {
1125  while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){
1126  Swap(ValN, ValN-1); ValN--;}
1127  }
1128  if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);}
1129  return ValN;
1130 }
1131 
1132 template <class TVal, class TSizeTy>
1133 TSizeTy TVec<TVal, TSizeTy>::AddBackSorted(const TVal& Val, const bool& Asc){
1134  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1135  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1136  Add();
1137  TSizeTy ValN=Vals-2;
1138  while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
1139  ValT[ValN+1]=ValT[ValN]; ValN--;}
1140  ValT[ValN+1]=Val;
1141  return ValN+1;
1142 }
1143 
1144 template <class TVal, class TSizeTy>
1145 TSizeTy TVec<TVal, TSizeTy>::AddMerged(const TVal& Val){
1146  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1147  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1148  TSizeTy ValN=SearchBin(Val);
1149  if (ValN==-1){return AddSorted(Val);}
1150  else {GetVal(ValN)=Val; return -1;}
1151 }
1152 
1153 template <class TVal, class TSizeTy>
1155  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1156  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1157  for (TSizeTy ValN=0; ValN<ValV.Vals; ValN++){AddMerged(ValV[ValN]);}
1158  return Len();
1159 }
1160 
1161 template <class TVal, class TSizeTy>
1162 TSizeTy TVec<TVal, TSizeTy>::AddUnique(const TVal& Val){
1163  AssertR(MxVals!=-1 || IsShM, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1164  TSizeTy ValN=SearchForw(Val);
1165  if (ValN==-1){return Add(Val);}
1166  else {GetVal(ValN)=Val; return -1;}
1167 }
1168 
1169 template <class TVal, class TSizeTy>
1170 void TVec<TVal, TSizeTy>::GetSubValV(const TSizeTy& _BValN, const TSizeTy& _EValN, TVec<TVal, TSizeTy>& SubValV) const {
1171  const TSizeTy BValN=TInt::GetInRng(_BValN, 0, Len()-1);
1172  const TSizeTy EValN=TInt::GetInRng(_EValN, 0, Len()-1);
1173  const TSizeTy SubVals=TInt::GetMx(0, EValN-BValN+1);
1174  SubValV.Gen(SubVals, 0);
1175  for (TSizeTy ValN=BValN; ValN<=EValN; ValN++){
1176  SubValV.Add(GetVal(ValN));}
1177 }
1178 
1179 template <class TVal, class TSizeTy>
1180 void TVec<TVal, TSizeTy>::Ins(const TSizeTy& ValN, const TVal& Val){
1181  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1182  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1183  Add(); Assert((0<=ValN)&&(ValN<Vals));
1184  for (TSizeTy MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
1185  ValT[ValN]=Val;
1186 }
1187 
1188 template <class TVal, class TSizeTy>
1189 void TVec<TVal, TSizeTy>::Del(const TSizeTy& ValN){
1190  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1191  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1192  Assert((0<=ValN)&&(ValN<Vals));
1193  for (TSizeTy MValN=ValN+1; MValN<Vals; MValN++){
1194  ValT[MValN-1]=ValT[MValN];}
1195  ValT[--Vals]=TVal();
1196 }
1197 
1198 template <class TVal, class TSizeTy>
1199 void TVec<TVal, TSizeTy>::Del(const TSizeTy& MnValN, const TSizeTy& MxValN){
1200  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1201  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1202  Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
1203  Assert(MnValN<=MxValN);
1204  for (TSizeTy ValN=MxValN+1; ValN<Vals; ValN++){
1205  ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
1206  for (TSizeTy ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
1207  ValT[ValN]=TVal();}
1208  Vals-=MxValN-MnValN+1;
1209 }
1210 
1211 template <class TVal, class TSizeTy>
1212 bool TVec<TVal, TSizeTy>::DelIfIn(const TVal& Val){
1213  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1214  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1215  TSizeTy ValN=SearchForw(Val);
1216  if (ValN!=-1){Del(ValN); return true;}
1217  else {return false;}
1218 }
1219 
1220 template <class TVal, class TSizeTy>
1221 void TVec<TVal, TSizeTy>::DelAll(const TVal& Val){
1222  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1223  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1224  TSizeTy ValN;
1225  while ((ValN=SearchForw(Val))!=-1){Del(ValN);}
1226 }
1227 
1228 template <class TVal, class TSizeTy>
1229 void TVec<TVal, TSizeTy>::PutAll(const TVal& Val){
1230  EAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1231  for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
1232 }
1233 
1234 template <class TVal, class TSizeTy>
1235 void TVec<TVal, TSizeTy>::BSort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc){
1236  for (TSizeTy ValN1=MnLValN; ValN1<=MxRValN; ValN1++){
1237  for (TSizeTy ValN2=MxRValN; ValN2>ValN1; ValN2--){
1238  if (Asc){
1239  if (ValT[ValN2]<ValT[ValN2-1]){Swap(ValN2, ValN2-1);}
1240  } else {
1241  if (ValT[ValN2]>ValT[ValN2-1]){Swap(ValN2, ValN2-1);}
1242  }
1243  }
1244  }
1245 }
1246 
1247 template <class TVal, class TSizeTy>
1248 void TVec<TVal, TSizeTy>::ISort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc){
1249  if (MnLValN<MxRValN){
1250  for (TSizeTy ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){
1251  TVal Val=ValT[ValN1]; TSizeTy ValN2=ValN1;
1252  if (Asc){
1253  while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){
1254  ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1255  } else {
1256  while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){
1257  ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1258  }
1259  ValT[ValN2]=Val;
1260  }
1261  }
1262 }
1263 
1264 template <class TVal, class TSizeTy>
1265 TSizeTy TVec<TVal, TSizeTy>::GetPivotValN(const TSizeTy& LValN, const TSizeTy& RValN) const {
1266  TSizeTy SubVals=RValN-LValN+1;
1267  if (SubVals > TInt::Mx-1) { SubVals = TInt::Mx-1; }
1268  const TSizeTy ValN1=LValN+TInt::GetRnd(int(SubVals));
1269  const TSizeTy ValN2=LValN+TInt::GetRnd(int(SubVals));
1270  const TSizeTy ValN3=LValN+TInt::GetRnd(int(SubVals));
1271  const TVal& Val1=ValT[ValN1];
1272  const TVal& Val2=ValT[ValN2];
1273  const TVal& Val3=ValT[ValN3];
1274  if (Val1<Val2){
1275  if (Val2<Val3){return ValN2;}
1276  else if (Val3<Val1){return ValN1;}
1277  else {return ValN3;}
1278  } else {
1279  if (Val1<Val3){return ValN1;}
1280  else if (Val3<Val2){return ValN2;}
1281  else {return ValN3;}
1282  }
1283 }
1284 
1285 template <class TVal, class TSizeTy>
1286 TSizeTy TVec<TVal, TSizeTy>::Partition(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc){
1287  TSizeTy PivotValN=GetPivotValN(MnLValN, MxRValN);
1288  Swap(PivotValN, MnLValN);
1289  TVal PivotVal=ValT[MnLValN];
1290  TSizeTy LValN=MnLValN-1; TSizeTy RValN=MxRValN+1;
1291  forever {
1292  if (Asc){
1293  do {RValN--;} while (ValT[RValN]>PivotVal);
1294  do {LValN++;} while (ValT[LValN]<PivotVal);
1295  } else {
1296  do {RValN--;} while (ValT[RValN]<PivotVal);
1297  do {LValN++;} while (ValT[LValN]>PivotVal);
1298  }
1299  if (LValN<RValN){Swap(LValN, RValN);}
1300  else {return RValN;}
1301  };
1302 }
1303 
1304 template <class TVal, class TSizeTy>
1305 void TVec<TVal, TSizeTy>::QSort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc){
1306  if (MnLValN<MxRValN){
1307  if (MxRValN-MnLValN<20){
1308  ISort(MnLValN, MxRValN, Asc);
1309  } else {
1310  TSizeTy SplitValN=Partition(MnLValN, MxRValN, Asc);
1311  QSort(MnLValN, SplitValN, Asc);
1312  QSort(SplitValN+1, MxRValN, Asc);
1313  }
1314  }
1315 }
1316 
1317 template <class TVal, class TSizeTy>
1318 void TVec<TVal, TSizeTy>::Sort(const bool& Asc){
1319  QSort(0, Len()-1, Asc);
1320 }
1321 
1322 template <class TVal, class TSizeTy>
1323 bool TVec<TVal, TSizeTy>::IsSorted(const bool& Asc) const {
1324  if (Asc){
1325  for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1326  if (ValT[ValN]>ValT[ValN+1]){return false;}}
1327  } else {
1328  for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1329  if (ValT[ValN]<ValT[ValN+1]){return false;}}
1330  }
1331  return true;
1332 }
1333 
1334 template <class TVal, class TSizeTy>
1336  if (Len() < TInt::Mx) {
1337  for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1338  const int Range = int(Vals-ValN);
1339  Swap(ValN, ValN+Rnd.GetUniDevInt(Range));
1340  }
1341  } else {
1342  for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1343  const TSizeTy Range = Vals-ValN;
1344  Swap(ValN, TSizeTy(ValN+Rnd.GetUniDevInt64(Range)));
1345  }
1346  }
1347 }
1348 
1349 template <class TVal, class TSizeTy>
1351  for (TSizeTy ValN=0; ValN<Vals/2; ValN++){
1352  Swap(ValN, Vals-ValN-1);}
1353 }
1354 
1355 template <class TVal, class TSizeTy>
1357  IAssertR(!(IsShM && (MxVals == -1)), "Cannot write to shared memory");
1358  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1359  TVec<TVal, TSizeTy> SortedVec(*this); SortedVec.Sort();
1360  Clr();
1361  for (TSizeTy ValN=0; ValN<SortedVec.Len(); ValN++){
1362  if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){
1363  Add(SortedVec[ValN]);}
1364  }
1365 }
1366 
1367 template <class TVal, class TSizeTy>
1369  // start with a sorted sequence to obtain all permutations
1370  TSizeTy First = 0, Last = Len(), Next = Len()-1;
1371  if (Last < 2) return false;
1372  for(; ; ) {
1373  // find rightmost element smaller than successor
1374  TSizeTy Next1 = Next;
1375  if (GetVal(--Next) < GetVal(Next1)) { // swap with rightmost element that's smaller, flip suffix
1376  TSizeTy Mid = Last;
1377  for (; GetVal(Next) >= GetVal(--Mid); ) { }
1378  Swap(Next, Mid);
1379  Reverse(Next1, Last-1);
1380  return true;
1381  }
1382  if (Next == First) { // pure descending, flip all
1383  Reverse();
1384  return false;
1385  }
1386  }
1387 }
1388 
1389 template <class TVal, class TSizeTy>
1391  TSizeTy First = 0, Last = Len(), Next = Len()-1;
1392  if (Last < 2) return false;
1393  for(; ; ) {
1394  // find rightmost element not smaller than successor
1395  TSizeTy Next1 = Next;
1396  if (GetVal(--Next) >= GetVal(Next1)) { // swap with rightmost element that's not smaller, flip suffix
1397  TSizeTy Mid = Last;
1398  for (; GetVal(Next) < GetVal(--Mid); ) { }
1399  Swap(Next, Mid);
1400  Reverse(Next1, Last);
1401  return true;
1402  }
1403  if (Next == First) { // pure descending, flip all
1404  Reverse();
1405  return false;
1406  }
1407  }
1408 }
1409 
1410 template <class TVal, class TSizeTy>
1412  TVec<TVal, TSizeTy> IntrsVec;
1413  Intrs(ValV, IntrsVec);
1414  MoveFrom(IntrsVec);
1415 }
1416 
1417 template <class TVal, class TSizeTy>
1419  TVec<TVal, TSizeTy> UnionVec;
1420  Union(ValV, UnionVec);
1421  MoveFrom(UnionVec);
1422 }
1423 
1424 template <class TVal, class TSizeTy>
1426  TVec<TVal, TSizeTy> DiffVec;
1427  Diff(ValV, DiffVec);
1428  MoveFrom(DiffVec);
1429 }
1430 
1431 template <class TVal, class TSizeTy>
1433  DstValV.Clr();
1434  TSizeTy ValN1=0, ValN2=0;
1435  while ((ValN1<Len())&&(ValN2<ValV.Len())){
1436  const TVal& Val1=GetVal(ValN1);
1437  while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){
1438  ValN2++;}
1439  if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){
1440  DstValV.Add(Val1); ValN2++;}
1441  ValN1++;
1442  }
1443 }
1444 
1445 template <class TVal, class TSizeTy>
1447  DstValV.Gen(TInt::GetMx(Len(), ValV.Len()), 0);
1448  TSizeTy ValN1=0, ValN2=0;
1449  while ((ValN1<Len())&&(ValN2<ValV.Len())){
1450  const TVal& Val1=GetVal(ValN1);
1451  const TVal& Val2=ValV.GetVal(ValN2);
1452  if (Val1<Val2){DstValV.Add(Val1); ValN1++;}
1453  else if (Val1>Val2){DstValV.Add(Val2); ValN2++;}
1454  else {DstValV.Add(Val1); ValN1++; ValN2++;}
1455  }
1456  for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1457  DstValV.Add(GetVal(RestValN1));}
1458  for (TSizeTy RestValN2=ValN2; RestValN2<ValV.Len(); RestValN2++){
1459  DstValV.Add(ValV.GetVal(RestValN2));}
1460 }
1461 
1462 template <class TVal, class TSizeTy>
1464  DstValV.Clr();
1465  TSizeTy ValN1=0, ValN2=0;
1466  while (ValN1<Len() && ValN2<ValV.Len()) {
1467  const TVal& Val1 = GetVal(ValN1);
1468  while (ValN2<ValV.Len() && Val1>ValV.GetVal(ValN2)) ValN2++;
1469  if (ValN2<ValV.Len()) {
1470  if (Val1!=ValV.GetVal(ValN2)) { DstValV.Add(Val1); }
1471  ValN1++;
1472  }
1473  }
1474  for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1475  DstValV.Add(GetVal(RestValN1));}
1476 }
1477 
1478 template <class TVal, class TSizeTy>
1480  TSizeTy Cnt=0, ValN1=0, ValN2=0;
1481  while ((ValN1<Len())&&(ValN2<ValV.Len())){
1482  const TVal& Val1=GetVal(ValN1);
1483  while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){
1484  ValN2++;}
1485  if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){
1486  ValN2++; Cnt++;}
1487  ValN1++;
1488  }
1489  return Cnt;
1490 }
1491 
1492 template <class TVal, class TSizeTy>
1494  TSizeTy Cnt = 0, ValN1 = 0, ValN2 = 0;
1495  while ((ValN1 < Len()) && (ValN2 < ValV.Len())) {
1496  const TVal& Val1 = GetVal(ValN1);
1497  const TVal& Val2 = ValV.GetVal(ValN2);
1498  if (Val1 < Val2) {
1499  Cnt++; ValN1++;
1500  } else if (Val1 > Val2) {
1501  Cnt++; ValN2++;
1502  } else {
1503  Cnt++; ValN1++; ValN2++;
1504  }
1505  }
1506  Cnt += (Len() - ValN1) + (ValV.Len() - ValN2);
1507  return Cnt;
1508 }
1509 
1510 template <class TVal, class TSizeTy>
1511 TSizeTy TVec<TVal, TSizeTy>::Count(const TVal& Val) const {
1512  TSizeTy Count = 0;
1513  for (TSizeTy i = 0; i < Len(); i++){
1514  if (Val == ValT[i]){Count++;}}
1515  return Count;
1516 }
1517 
1518 template <class TVal, class TSizeTy>
1519 TSizeTy TVec<TVal, TSizeTy>::SearchBin(const TVal& Val) const {
1520  TSizeTy LValN=0, RValN=Len()-1;
1521  while (RValN>=LValN){
1522  TSizeTy ValN=(LValN+RValN)/2;
1523  if (Val==ValT[ValN]){return ValN;}
1524  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
1525  }
1526  return -1;
1527 }
1528 
1529 template <class TVal, class TSizeTy>
1530 TSizeTy TVec<TVal, TSizeTy>::SearchBin(const TVal& Val, TSizeTy& InsValN) const {
1531  TSizeTy LValN=0, RValN=Len()-1;
1532  while (RValN>=LValN){
1533  TSizeTy ValN=(LValN+RValN)/2;
1534  if (Val==ValT[ValN]){InsValN=ValN; return ValN;}
1535  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
1536  }
1537  InsValN=LValN; return -1;
1538 }
1539 
1540 template <class TVal, class TSizeTy>
1541 TSizeTy TVec<TVal, TSizeTy>::SearchBinLeft(const TVal& Val, TSizeTy& InsValN) const {
1542  TSizeTy LValN=0, RValN=Len()-1;
1543  while (RValN>=LValN){
1544  TSizeTy ValN=(LValN+RValN)/2;
1545  if (Val==ValT[ValN]){InsValN=ValN; return ValN;}
1546  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
1547  }
1548  InsValN=RValN; return -1;
1549 }
1550 
1551 template <class TVal, class TSizeTy>
1552 TSizeTy TVec<TVal, TSizeTy>::SearchForw(const TVal& Val, const TSizeTy& BValN) const {
1553  for (TSizeTy ValN=BValN; ValN<Vals; ValN++){
1554  if (Val==ValT[ValN]){return ValN;}}
1555  return -1;
1556 }
1557 
1558 template <class TVal, class TSizeTy>
1559 TSizeTy TVec<TVal, TSizeTy>::SearchBack(const TVal& Val) const {
1560  for (TSizeTy ValN=Vals-1; ValN>=0; ValN--){
1561  if (Val==ValT[ValN]){return ValN;}}
1562  return -1;
1563 }
1564 
1565 template <class TVal, class TSizeTy>
1566 TSizeTy TVec<TVal, TSizeTy>::SearchVForw(const TVec<TVal, TSizeTy>& ValV, const TSizeTy& BValN) const {
1567  TSizeTy ValVLen=ValV.Len();
1568  for (TSizeTy ValN=BValN; ValN<Vals-ValVLen+1; ValN++){
1569  bool Found=true;
1570  for (TSizeTy SubValN=0; SubValN<ValVLen; SubValN++){
1571  if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=false; break;}
1572  }
1573  if (Found){return ValN;}
1574  }
1575  return -1;
1576 }
1577 
1578 template <class TVal, class TSizeTy>
1580  if (Vals==0){return -1;}
1581  TSizeTy MxValN=0;
1582  for (TSizeTy ValN=1; ValN<Vals; ValN++){
1583  if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
1584  }
1585  return MxValN;
1586 }
1587 
1589 // Common-Vector-Types
1591 typedef TVec<TCh> TChV;
1623 typedef TVec<TIntKd> TIntKdV;
1665 
1666 //#//////////////////////////////////////////////
1668 
1671 template <class TVal, class TSizeTy=int>
1672 class TVecPool {
1673 public:
1676 private:
1680  TVal EmptyVal; // Empty value/vector
1681  TVal *ValBf; // Buffer for storing all the values
1682  TVec<uint64, int> IdToOffV; // Id to one past last (Vector starts at [id-1]). Vector length is IdToOff[id]-IdToOff[id-1]
1683 private:
1684  void Resize(const TSize& _MxVals);
1685 public:
1687 
1692  TVecPool(const TSize& ExpectVals=0, const TSize& _GrowBy=1000000, const bool& _FastCopy=false, const TVal& _EmptyVal=TVal());
1693  TVecPool(const TVecPool<TVal, TSizeTy>& Pool);
1694  TVecPool(TSIn& SIn);
1695  ~TVecPool() { if (ValBf != NULL) { delete [] ValBf; } ValBf=NULL; }
1696  static PVecPool New(const TSize& ExpectVals=0, const TSize& GrowBy=1000000, const bool& FastCopy=false) {
1697  return new TVecPool(ExpectVals, GrowBy, FastCopy); }
1698  static PVecPool Load(TSIn& SIn) { return new TVecPool(SIn); }
1699  static PVecPool Load(const TStr& FNm) { TFIn FIn(FNm); return Load(FIn); }
1700  void Save(TSOut& SOut) const;
1701  TVecPool& operator = (const TVecPool& Pool);
1702 
1704  int GetVecs() const { return IdToOffV.Len(); }
1706  TSize GetVals() const { return Vals; }
1708  bool IsVId(const int& VId) const { return (0 <= VId) && (VId < IdToOffV.Len()); }
1710  uint64 Reserved() const { return MxVals; }
1712  void Reserve(const TSize& MxVals) { Resize(MxVals); }
1714  const TVal& GetEmptyVal() const { return EmptyVal; }
1716  void SetEmptyVal(const TVal& _EmptyVal) { EmptyVal = _EmptyVal; }
1718  uint64 GetMemUsed() const {
1719  return sizeof(TCRef)+sizeof(TBool)+3*sizeof(TSize)+sizeof(TVal*)+MxVals*sizeof(TVal);}
1720 
1722  int AddV(const TValV& ValV);
1724 
1726  int AddEmptyV(const int& ValVLen);
1728  int GetVLen(const int& VId) const { if (VId==0){return 0;} else {return int(IdToOffV[VId]-IdToOffV[VId-1]);}}
1730  TVal* GetValVPt(const int& VId) const {
1731  if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
1732  else {return ValBf+IdToOffV[VId-1];}}
1734 
1736  void GetV(const int& VId, TValV& ValV) const {
1737  if (GetVLen(VId)==0){ValV.Clr();}
1738  else { ValV.GenExt(GetValVPt(VId), GetVLen(VId)); } }
1740  void PutV(const int& VId, const TValV& ValV) {
1741  IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
1742  if (FastCopy) {
1743  memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1744  else { TVal* ValPt = GetValVPt(VId);
1745  for (::TSize ValN=0; ValN < ::TSize(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1746  } }
1748 
1750  void CompactPool(const TVal& DelVal);
1752 
1754  void ShuffleAll(TRnd& Rnd=TInt::Rnd);
1755 
1757 
1759  void Clr(bool DoDel = true) {
1760  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
1761  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
1762  if (! DoDel) { PutAll(EmptyVal); } }
1764  void PutAll(const TVal& Val) {
1765  for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }
1766  friend class TPt<TVecPool<TVal> >;
1767 };
1768 
1769 template <class TVal, class TSizeTy>
1771  if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
1772  if (ValBf == NULL) {
1773  try { ValBf = new TVal [MxVals]; }
1774  catch (std::exception Ex) {
1775  FailR(TStr::Fmt("TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), TInt::GetStr(uint64(_MxVals)).CStr()).CStr()); }
1776  IAssert(ValBf != NULL);
1777  if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1778  } else {
1779  // printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
1780  TVal* NewValBf = NULL;
1781  try { NewValBf = new TVal [MxVals]; }
1782  catch (std::exception Ex) {
1783  FailR(TStr::Fmt("TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), TInt::GetStr(uint64(_MxVals)).CStr()).CStr()); }
1784  IAssert(NewValBf != NULL);
1785  if (FastCopy) {
1786  memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
1787  else {
1788  for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1789  if (EmptyVal != TVal()) { // init empty values
1790  for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1791  }
1792  delete [] ValBf;
1793  ValBf = NewValBf;
1794  }
1795 }
1796 
1797 template <class TVal, class TSizeTy>
1798 TVecPool<TVal, TSizeTy>::TVecPool(const TSize& ExpectVals, const TSize& _GrowBy, const bool& _FastCopy, const TVal& _EmptyVal) : GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
1799  IdToOffV.Add(0);
1800  Resize(ExpectVals);
1801 }
1802 
1803 template <class TVal, class TSizeTy>
1804 TVecPool<TVal, TSizeTy>::TVecPool(const TVecPool& Pool) : FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy), MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
1805  try {
1806  ValBf = new TVal [MxVals]; }
1807  catch (std::exception Ex) {
1808  FailR(TStr::Fmt("TVecPool::TVecPool: %s, MxVals: %s. [Program failed to allocate memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), TInt::GetStr(uint64(MxVals)).CStr()).CStr()); }
1809  IAssert(ValBf != NULL);
1810  if (FastCopy) {
1811  memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); }
1812  else {
1813  for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
1814 }
1815 
1816 template <class TVal, class TSizeTy>
1818  uint64 _GrowBy, _MxVals, _Vals;
1819  SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals);
1820  IAssertR(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx, "This is a 64-bit vector pool. Use a 64-bit compiler.");
1821  GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals
1822  EmptyVal = TVal(SIn);
1823  if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; }
1824  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
1825  { TInt MxVals(SIn), Vals(SIn);
1826  IdToOffV.Gen(Vals);
1827  for (int ValN = 0; ValN < Vals; ValN++) {
1828  uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx);
1829  IdToOffV[ValN]=TSize(Offset);
1830  } }
1831 }
1832 
1833 template <class TVal, class TSizeTy>
1835  SOut.Save(FastCopy);
1836  uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1837  SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
1838  SOut.Save(EmptyVal);
1839  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1840  { SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
1841  for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
1842  const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
1843  } }
1844 }
1845 
1846 template <class TVal, class TSizeTy>
1848  if (this!=&Pool) {
1849  FastCopy = Pool.FastCopy;
1850  GrowBy = Pool.GrowBy;
1851  MxVals = Pool.MxVals;
1852  Vals = Pool.Vals;
1853  EmptyVal = Pool.EmptyVal;
1854  IdToOffV=Pool.IdToOffV;
1855  try {
1856  ValBf = new TVal [MxVals]; }
1857  catch (std::exception Ex) {
1858  FailR(TStr::Fmt("TVecPool::operator=: %s, MxVals: %s. [Program failed to allocate memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), TInt::GetStr(uint64(MxVals)).CStr()).CStr()); }
1859  IAssert(ValBf != NULL);
1860  if (FastCopy) {
1861  memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
1862  else {
1863  for (TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
1864  }
1865  return *this;
1866 }
1867 
1868 template <class TVal, class TSizeTy>
1870  const TSize ValVLen = ValV.Len();
1871  if (ValVLen == 0) { return 0; }
1872  if (MxVals < Vals+ValVLen) { Resize(Vals+MAX(ValVLen, GrowBy)); }
1873  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1874  else { for (TSize ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1875  Vals+=ValVLen; IdToOffV.Add(Vals);
1876  return IdToOffV.Len()-1;
1877 }
1878 
1879 template <class TVal, class TSizeTy>
1880 int TVecPool<TVal, TSizeTy>::AddEmptyV(const int& ValVLen) {
1881  if (ValVLen==0){return 0;}
1882  if (MxVals < Vals+ValVLen){Resize(Vals+MAX(TSize(ValVLen), GrowBy)); }
1883  Vals+=ValVLen; IdToOffV.Add(Vals);
1884  return IdToOffV.Len()-1;
1885 }
1886 
1887 // Delete all elements of value DelVal from all vectors. Empty space is left at the end of the pool.
1888 template <class TVal, class TSizeTy>
1889 void TVecPool<TVal, TSizeTy>::CompactPool(const TVal& DelVal) {
1890  ::TSize TotalDel=0, NDel=0;
1891  // printf("Compacting %d vectors\n", IdToOffV.Len());
1892  for (int vid = 1; vid < IdToOffV.Len(); vid++) {
1893  // if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
1894  const uint Len = GetVLen(vid);
1895  TVal* ValV = GetValVPt(vid);
1896  if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
1897  if (Len == 0) { continue; }
1898  NDel = 0;
1899  for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
1900  if (*v == DelVal) {
1901  TVal* Beg = v;
1902  while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
1903  memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
1904  v -= NDel;
1905  }
1906  }
1907  memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
1908  TotalDel += NDel;
1909  }
1910  IdToOffV.Last() -= TotalDel;
1911  for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
1912  Vals -= TotalDel;
1913  // printf(" deleted %llu elements from the pool\n", TotalDel);
1914 }
1915 
1916 // shuffles all the order of elements in the pool (does not respect vector boundaries)
1917 template <class TVal, class TSizeTy>
1919  for (::TSize n = Vals-1; n > 0; n--) {
1920  const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
1921  const TVal Tmp = ValBf[n];
1922  ValBf[n] = ValBf[k];
1923  ValBf[k] = Tmp;
1924  }
1925 }
1926 
1927 
1929 // Below are old 32-bit implementations of TVec and other classes.
1930 // Old TVec takes at most 2G elements.
1931 // The new vector class supports 64-bits for the number of elements,
1932 // but also allows 32-bits for backward compatibility.
1933 // by Jure (Jan 2013)
1934 namespace TGLib_OLD {
1936 // Vector Pool
1937 template<class TVal>
1938 class TVecPool {
1939 public:
1942 private:
1946  TVal EmptyVal; // empty vector
1947  TVal *ValBf; // buffer storing all the values
1948  TVec< ::TSize> IdToOffV; // id to one past last (vector starts at [id-1])
1949 private:
1950  void Resize(const ::TSize& _MxVals);
1951 public:
1952  TVecPool(const ::TSize& ExpectVals=0, const ::TSize& _GrowBy=1000000, const bool& _FastCopy=false, const TVal& _EmptyVal=TVal());
1953  TVecPool(const TVecPool& Pool);
1954  TVecPool(TSIn& SIn);
1955  ~TVecPool() { if (ValBf != NULL) { delete [] ValBf; } ValBf=NULL; }
1956  static PVecPool New(const ::TSize& ExpectVals=0, const ::TSize& GrowBy=1000000, const bool& FastCopy=false) {
1957  return new TVecPool(ExpectVals, GrowBy, FastCopy); }
1958  static PVecPool Load(TSIn& SIn) { return new TVecPool(SIn); }
1959  static PVecPool Load(const TStr& FNm) { TFIn FIn(FNm); return Load(FIn); }
1960  void Save(TSOut& SOut) const;
1961 
1962  TVecPool& operator = (const TVecPool& Pool);
1963 
1964  ::TSize GetVals() const { return Vals; }
1965  ::TSize GetVecs() const { return IdToOffV.Len(); }
1966  bool IsVId(const int& VId) const { return (0 <= VId) && (VId < IdToOffV.Len()); }
1967  ::TSize Reserved() const { return MxVals; }
1968  void Reserve(const ::TSize& MxVals) { Resize(MxVals); }
1969  const TVal& GetEmptyVal() const { return EmptyVal; }
1970  void SetEmptyVal(const TVal& _EmptyVal) { EmptyVal = _EmptyVal; }
1972  return sizeof(TCRef)+sizeof(TBool)+3*sizeof(TSize)+sizeof(TVal*)+MxVals*sizeof(TVal);}
1973 
1974  int AddV(const TValV& ValV);
1975  int AddEmptyV(const int& ValVLen);
1976  uint GetVLen(const int& VId) const {
1977  if (VId==0){return 0;}
1978  else {return uint(IdToOffV[VId]-IdToOffV[VId-1]);}}
1979  TVal* GetValVPt(const int& VId) const {
1980  if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
1981  else {return ValBf+IdToOffV[VId-1];}}
1982  void GetV(const int& VId, TValV& ValV) const {
1983  if (GetVLen(VId)==0){ValV.Clr();}
1984  else { ValV.GenExt(GetValVPt(VId), GetVLen(VId)); } }
1985  void PutV(const int& VId, const TValV& ValV) {
1986  IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
1987  if (FastCopy) {
1988  memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
1989  else { TVal* ValPt = GetValVPt(VId);
1990  for (uint ValN=0; ValN < uint(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1991  }
1992  }
1993  void CompactPool(const TVal& DelVal); // delete all elements of value DelVal from all vectors
1994  void ShuffleAll(TRnd& Rnd=TInt::Rnd); // shuffles all the order of elements in the Pool (does not respect vector boundaries)
1995 
1996  //bool HasIdMap() const { return ! IdToOffV.Empty(); }
1997  //void ClrIdMap() { IdToOffV.Clr(true); }
1998  void Clr(bool DoDel = true) {
1999  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
2000  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
2001  if (! DoDel) { PutAll(EmptyVal); }
2002  }
2003  void PutAll(const TVal& Val) {
2004  for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }
2005 
2006  friend class TPt<TVecPool<TVal> >;
2007 };
2008 
2009 template <class TVal>
2011  if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
2012  if (ValBf == NULL) {
2013  try { ValBf = new TVal [MxVals]; }
2014  catch (std::exception Ex) {
2015  FailR(TStr::Fmt("TVecPool::Resize 1: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
2016  IAssert(ValBf != NULL);
2017  if (EmptyVal != TVal()) { PutAll(EmptyVal); }
2018  } else {
2019  // printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
2020  TVal* NewValBf = NULL;
2021  try { NewValBf = new TVal [MxVals]; }
2022  catch (std::exception Ex) { FailR(TStr::Fmt("TVecPool::Resize 2: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
2023  IAssert(NewValBf != NULL);
2024  if (FastCopy) {
2025  memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
2026  else {
2027  for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
2028  if (EmptyVal != TVal()) { // init empty values
2029  for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
2030  }
2031  delete [] ValBf;
2032  ValBf = NewValBf;
2033  }
2034 }
2035 
2036 template <class TVal>
2037 TVecPool<TVal>::TVecPool(const ::TSize& ExpectVals, const ::TSize& _GrowBy, const bool& _FastCopy, const TVal& _EmptyVal) :
2038  GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
2039  IdToOffV.Add(0);
2040  Resize(ExpectVals);
2041 }
2042 
2043 template <class TVal>
2045  FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy),
2046  MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
2047  try { ValBf = new TVal [MxVals]; }
2048  catch (std::exception Ex) { FailR(TStr::Fmt("TVecPool::TVecPool: %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
2049  IAssert(ValBf != NULL);
2050  if (FastCopy) {
2051  memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); }
2052  else {
2053  for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
2054 }
2055 
2056 template <class TVal>
2058  FastCopy(SIn) {
2059  uint64 _GrowBy, _MxVals, _Vals;
2060  SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals);
2061  IAssert(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx);
2062  GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals
2063  EmptyVal = TVal(SIn);
2064  if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; }
2065  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
2066  { TInt MxVals(SIn), Vals(SIn);
2067  IdToOffV.Gen(Vals);
2068  for (int ValN = 0; ValN < Vals; ValN++) {
2069  uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx);
2070  IdToOffV[ValN]=TSize(Offset);
2071  } }
2072 }
2073 
2074 template <class TVal>
2075 void TVecPool<TVal>::Save(TSOut& SOut) const {
2076  SOut.Save(FastCopy);
2077  uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2078  SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
2079  SOut.Save(EmptyVal);
2080  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2081  { SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
2082  for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
2083  const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
2084  } }
2085 }
2086 
2087 template <class TVal>
2089  if (this!=&Pool) {
2090  FastCopy = Pool.FastCopy;
2091  GrowBy = Pool.GrowBy;
2092  MxVals = Pool.MxVals;
2093  Vals = Pool.Vals;
2094  EmptyVal = Pool.EmptyVal;
2095  IdToOffV=Pool.IdToOffV;
2096  try { ValBf = new TVal [MxVals]; }
2097  catch (std::exception Ex) { FailR(TStr::Fmt("TVec::operator= : %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
2098  IAssert(ValBf != NULL);
2099  if (FastCopy) {
2100  memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
2101  else {
2102  for (uint64 ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
2103  }
2104  return *this;
2105 }
2106 
2107 template<class TVal>
2108 int TVecPool<TVal>::AddV(const TValV& ValV) {
2109  const ::TSize ValVLen = ValV.Len();
2110  if (ValVLen == 0) { return 0; }
2111  if (MxVals < Vals+ValVLen) { Resize(Vals+MAX(ValVLen, GrowBy)); }
2112  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
2113  else { for (uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2114  Vals+=ValVLen; IdToOffV.Add(Vals);
2115  return IdToOffV.Len()-1;
2116 }
2117 
2118 template<class TVal>
2119 int TVecPool<TVal>::AddEmptyV(const int& ValVLen) {
2120  if (ValVLen==0){return 0;}
2121  if (MxVals < Vals+ValVLen){Resize(Vals+MAX(TSize(ValVLen), GrowBy)); }
2122  Vals+=ValVLen; IdToOffV.Add(Vals);
2123  return IdToOffV.Len()-1;
2124 }
2125 
2126 // delete all elements of value DelVal from all vectors
2127 // empty space is left at the end of the pool
2128 template<class TVal>
2129 void TVecPool<TVal>::CompactPool(const TVal& DelVal) {
2130  ::TSize TotalDel=0, NDel=0;
2131  // printf("Compacting %d vectors\n", IdToOffV.Len());
2132  for (int vid = 1; vid < IdToOffV.Len(); vid++) {
2133  // if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
2134  const uint Len = GetVLen(vid);
2135  TVal* ValV = GetValVPt(vid);
2136  if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
2137  if (Len == 0) { continue; }
2138  NDel = 0;
2139  for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
2140  if (*v == DelVal) {
2141  TVal* Beg = v;
2142  while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
2143  memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
2144  v -= NDel;
2145  }
2146  }
2147  memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
2148  TotalDel += NDel;
2149  }
2150  IdToOffV.Last() -= TotalDel;
2151  for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
2152  Vals -= TotalDel;
2153  // printf(" deleted %llu elements from the pool\n", TotalDel);
2154 }
2155 
2156 // shuffles all the order of elements in the pool (does not respect vector boundaries)
2157 template<class TVal>
2159  for (::TSize n = Vals-1; n > 0; n--) {
2160  const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
2161  const TVal Tmp = ValBf[n];
2162  ValBf[n] = ValBf[k];
2163  ValBf[k] = Tmp;
2164  }
2165 }
2166 
2167 }; // namespace TGLib_OLD
2168 
2169 typedef TVecPool<TInt> TIntVecPool;
2171 
2173 // Vector-Pointer
2174 template <class TVal>
2175 class PVec{
2176 private:
2178 public:
2180 public:
2181  PVec<TVal>(): V(){}
2182  PVec<TVal>(const PVec<TVal>& Vec): V(Vec.V){}
2183  static TPt<PVec<TVal> > New(){
2184  return new PVec<TVal>();}
2185  PVec<TVal>(const int& MxVals, const int& Vals): V(MxVals, Vals){}
2186  static TPt<PVec<TVal> > New(const int& MxVals, const int& Vals){
2187  return new PVec<TVal>(MxVals, Vals);}
2188  PVec<TVal>(const TVec<TVal>& _V): V(_V){}
2189  static TPt<PVec<TVal> > New(const TVec<TVal>& V){
2190  return new PVec<TVal>(V);}
2191  explicit PVec<TVal>(TSIn& SIn): V(SIn){}
2192  static TPt<PVec<TVal> > Load(TSIn& SIn){return new PVec<TVal>(SIn);}
2193  void Save(TSOut& SOut) const {V.Save(SOut);}
2194 
2196  if (this!=&Vec){V=Vec.V;} return *this;}
2197  bool operator==(const PVec<TVal>& Vec) const {return V==Vec.V;}
2198  bool operator<(const PVec<TVal>& Vec) const {return V<Vec.V;}
2199  TVal& operator[](const int& ValN) const {return V[ValN];}
2200 
2201  bool Empty() const {return V.Empty();}
2202  int Len() const {return V.Len();}
2203  TVal GetVal(const int& ValN) const {return V[ValN];}
2204 
2205  int Add(const TVal& Val){return V.Add(Val);}
2206 
2207  friend class TPt<PVec<TVal> >;
2208 };
2209 
2211 // Common-Vector-Pointer-Types
2218 
2220 // 2D-Vector
2221 template <class TVal, class TSizeTy = int>
2222 class TVVec{
2223 private:
2226 public:
2227  TVVec(): XDim(), YDim(), ValV(){}
2228  TVVec(const TVVec& Vec):
2229  XDim(Vec.XDim), YDim(Vec.YDim), ValV(Vec.ValV){}
2230  TVVec(const TSizeTy& _XDim, const TSizeTy& _YDim):
2231  XDim(), YDim(), ValV(){Gen(_XDim, _YDim);}
2232  explicit TVVec(const TVec<TVal,TSizeTy>& _ValV, const TSizeTy& _XDim, const TSizeTy& _YDim):
2233  XDim(_XDim), YDim(_YDim), ValV(_ValV){ IAssert(ValV.Len()==XDim*YDim); }
2234  explicit TVVec(TSIn& SIn) {Load(SIn);}
2235  void Load(TSIn& SIn){XDim.Load(SIn); YDim.Load(SIn); ValV.Load(SIn);}
2236  void Save(TSOut& SOut) const {
2237  XDim.Save(SOut); YDim.Save(SOut); ValV.Save(SOut);}
2238 
2240  if (this!=&Vec){XDim=Vec.XDim; YDim=Vec.YDim; ValV=Vec.ValV;} return *this;}
2241  bool operator==(const TVVec& Vec) const {
2242  return (XDim==Vec.XDim)&&(YDim==Vec.YDim)&&(ValV==Vec.ValV);}
2243 
2244  bool Empty() const {return ValV.Len()==0;}
2245  void Clr(){XDim=0; YDim=0; ValV.Clr();}
2246  void Gen(const TSizeTy& _XDim, const TSizeTy& _YDim){
2247  Assert((_XDim>=0)&&(_YDim>=0));
2248  XDim=_XDim; YDim=_YDim; ValV.Gen(XDim*YDim);}
2249  TSizeTy GetXDim() const {return XDim;}
2250  TSizeTy GetYDim() const {return YDim;}
2251  TSizeTy GetRows() const {return XDim;}
2252  TSizeTy GetCols() const {return YDim;}
2254 
2255  const TVal& At(const TSizeTy& X, const TSizeTy& Y) const {
2256  Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim)));
2257  return ValV[X*YDim+Y];}
2258  TVal& At(const TSizeTy& X, const TSizeTy& Y){
2259  Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim)));
2260  return ValV[X*YDim+Y];}
2261  TVal& operator()(const TSizeTy& X, const TSizeTy& Y){
2262  return At(X, Y);}
2263  const TVal& operator()(const TSizeTy& X, const TSizeTy& Y) const {
2264  return At(X, Y);}
2265 
2266  void PutXY(const TSizeTy& X, const TSizeTy& Y, const TVal& Val){At(X, Y)=Val;}
2267  void PutAll(const TVal& Val){ValV.PutAll(Val);}
2268  void PutX(const TSizeTy& X, const TVal& Val){
2269  for (TSizeTy Y=0; Y<TSizeTy(YDim); Y++){At(X, Y)=Val;}}
2270  void PutY(const TSizeTy& Y, const TVal& Val){
2271  for (TSizeTy X=0; X<TSizeTy(XDim); X++){At(X, Y)=Val;}}
2272  TVal GetXY(const TSizeTy& X, const TSizeTy& Y) const {
2273  Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim)));
2274  return ValV[X*YDim+Y];}
2275  void GetRow(const TSizeTy& RowN, TVec<TVal, TSizeTy>& Vec) const;
2276  void GetCol(const TSizeTy& ColN, TVec<TVal, TSizeTy>& Vec) const;
2277 
2278  void SwapX(const TSizeTy& X1, const TSizeTy& X2);
2279  void SwapY(const TSizeTy& Y1, const TSizeTy& Y2);
2280  void Swap(TVVec<TVal, TSizeTy>& Vec);
2281 
2282  void ShuffleX(TRnd& Rnd);
2283  void ShuffleY(TRnd& Rnd);
2284  void GetMxValXY(TSizeTy& X, TSizeTy& Y) const;
2285 
2286  void CopyFrom(const TVVec<TVal, TSizeTy>& VVec);
2287  void AddXDim();
2288  void AddYDim();
2289  void DelX(const TSizeTy& X);
2290  void DelY(const TSizeTy& Y);
2291 };
2292 
2293 template <class TVal, class TSizeTy>
2294 void TVVec<TVal, TSizeTy>::SwapX(const TSizeTy& X1, const TSizeTy& X2){
2295  for (TSizeTy Y=0; Y<TSizeTy(YDim); Y++){
2296  TVal Val=At(X1, Y); At(X1, Y)=At(X2, Y); At(X2, Y)=Val;}
2297 }
2298 
2299 template <class TVal, class TSizeTy>
2300 void TVVec<TVal, TSizeTy>::SwapY(const TSizeTy& Y1, const TSizeTy& Y2){
2301  for (TSizeTy X=0; X<TSizeTy(XDim); X++){
2302  TVal Val=At(X, Y1); At(X, Y1)=At(X, Y2); At(X, Y2)=Val;}
2303 }
2304 
2305 template <class TVal, class TSizeTy>
2307  if (this!=&Vec){
2308  ::Swap(XDim, Vec.XDim);
2309  ::Swap(YDim, Vec.YDim);
2310  ValV.Swap(Vec.ValV);
2311  }
2312 }
2313 
2314 template <class TVal, class TSizeTy>
2316  for (TSizeTy X=0; X<XDim-1; X++){SwapX(X, X+Rnd.GetUniDevInt(XDim-X));}
2317 }
2318 
2319 template <class TVal, class TSizeTy>
2321  for (TSizeTy Y=0; Y<YDim-1; Y++){SwapY(Y, Y+Rnd.GetUniDevInt(YDim-Y));}
2322 }
2323 
2324 template <class TVal, class TSizeTy>
2325 void TVVec<TVal, TSizeTy>::GetMxValXY(TSizeTy& X, TSizeTy& Y) const {
2326  TSizeTy MxValN=ValV.GetMxValN();
2327  Y=MxValN%YDim;
2328  X=MxValN/YDim;
2329 }
2330 
2331 template <class TVal, class TSizeTy>
2333  TSizeTy CopyXDim = (GetXDim() < VVec.GetXDim()) ? GetXDim() : VVec.GetXDim();
2334  TSizeTy CopyYDim = (GetYDim() < VVec.GetYDim()) ? GetYDim() : VVec.GetYDim();
2335  for (TSizeTy X=0; X<CopyXDim; X++){
2336  for (TSizeTy Y=0; Y<CopyYDim; Y++){
2337  At(X, Y)=VVec.At(X, Y);
2338  }
2339  }
2340 }
2341 
2342 template <class TVal, class TSizeTy>
2344  TVVec<TVal, TSizeTy> NewVVec(XDim+1, YDim);
2345  NewVVec.CopyFrom(*this);
2346  *this=NewVVec;
2347 }
2348 
2349 template <class TVal, class TSizeTy>
2351  TVVec<TVal, TSizeTy> NewVVec(XDim, YDim+1);
2352  NewVVec.CopyFrom(*this);
2353  *this=NewVVec;
2354 }
2355 
2356 template <class TVal, class TSizeTy>
2357 void TVVec<TVal, TSizeTy>::DelX(const TSizeTy& X){
2358  TVVec<TVal, TSizeTy> NewVVec(XDim-1, YDim);
2359  for (TSizeTy Y=0; Y<YDim; Y++){
2360  for (TSizeTy LX=0; LX<X; LX++){
2361  NewVVec.At(LX, Y)=At(LX, Y);}
2362  for (TSizeTy RX=X+1; RX<XDim; RX++){
2363  NewVVec.At(RX-1, Y)=At(RX, Y);}
2364  }
2365  *this=NewVVec;
2366 }
2367 
2368 template <class TVal, class TSizeTy>
2369 void TVVec<TVal, TSizeTy>::DelY(const TSizeTy& Y){
2370  TVVec<TVal, TSizeTy> NewVVec(XDim, YDim-1);
2371  for (TSizeTy X=0; X<XDim; X++){
2372  for (TSizeTy LY=0; LY<Y; LY++){
2373  NewVVec.At(X, LY)=At(X, LY);}
2374  for (TSizeTy RY=Y+1; RY<YDim; RY++){
2375  NewVVec.At(X, RY-1)=At(X, RY);}
2376  }
2377  *this=NewVVec;
2378 }
2379 
2380 template <class TVal, class TSizeTy >
2381 void TVVec<TVal, TSizeTy>::GetRow(const TSizeTy& RowN, TVec<TVal, TSizeTy>& Vec) const {
2382  Vec.Gen(GetCols(), 0);
2383  for (TSizeTy col = 0; col < GetCols(); col++) {
2384  Vec.Add(At(RowN, col));
2385  }
2386 }
2387 
2388 template <class TVal, class TSizeTy>
2389 void TVVec<TVal, TSizeTy>::GetCol(const TSizeTy& ColN, TVec<TVal, TSizeTy>& Vec) const {
2390  Vec.Gen(GetRows(), 0);
2391  for (TSizeTy row = 0; row < GetRows(); row++) {
2392  Vec.Add(At(row, ColN));
2393  }
2394 }
2395 
2397 // Common-2D-Vector-Types
2405 
2407 // 3D-Vector
2408 template <class TVal, class TSizeTy = int>
2409 class TVVVec{
2410 private:
2413 public:
2414  TVVVec(): XDim(), YDim(), ZDim(), ValV(){}
2415  TVVVec(const TVVVec& Vec):
2416  XDim(Vec.XDim), YDim(Vec.YDim), ZDim(Vec.ZDim), ValV(Vec.ValV){}
2417  TVVVec(const TSizeTy& _XDim, const TSizeTy& _YDim, const TSizeTy& _ZDim):
2418  XDim(), YDim(), ZDim(), ValV(){Gen(_XDim, _YDim, _ZDim);}
2419  explicit TVVVec(TSIn& SIn):
2420  XDim(SIn), YDim(SIn), ZDim(SIn), ValV(SIn){}
2421  void Save(TSOut& SOut) const {
2422  XDim.Save(SOut); YDim.Save(SOut); ZDim.Save(SOut); ValV.Save(SOut);}
2423 
2425  XDim=Vec.XDim; YDim=Vec.YDim; ZDim=Vec.ZDim; ValV=Vec.ValV;
2426  return *this;
2427  }
2428  bool operator==(const TVVVec& Vec) const {
2429  return (XDim==Vec.XDim)&&(YDim==Vec.YDim)&&(ZDim==Vec.ZDim)&&
2430  (ValV==Vec.ValV);}
2431 
2432  bool Empty() const {return ValV.Len()==0;}
2433  void Clr(){XDim=0; YDim=0; ZDim=0; ValV.Clr();}
2434  void Gen(const TSizeTy& _XDim, const TSizeTy& _YDim, const TSizeTy& _ZDim){
2435  Assert((_XDim>=0)&&(_YDim>=0)&&(_ZDim>=0));
2436  XDim=_XDim; YDim=_YDim; ZDim=_ZDim; ValV.Gen(XDim*YDim*ZDim);}
2437  TVal& At(const TSizeTy& X, const TSizeTy& Y, const TSizeTy& Z){
2438  Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim))&&(0<=Z)&&(Z<TSizeTy(ZDim)));
2439  return ValV[X*YDim*ZDim+Y*ZDim+Z];}
2440  const TVal& At(const TSizeTy& X, const TSizeTy& Y, const TSizeTy& Z) const {
2441  Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim))&&(0<=Z)&&(Z<TSizeTy(ZDim)));
2442  return ValV[X*YDim*ZDim+Y*ZDim+Z];}
2443  TVal& operator()(const TSizeTy& X, const TSizeTy& Y, const TSizeTy& Z){
2444  return At(X, Y, Z);}
2445  const TVal& operator()(const TSizeTy& X, const TSizeTy& Y, const TSizeTy& Z) const {
2446  return At(X, Y, Z);}
2447  TSizeTy GetXDim() const {return XDim;}
2448  TSizeTy GetYDim() const {return YDim;}
2449  TSizeTy GetZDim() const {return ZDim;}
2450 };
2451 
2453 // Common-3D-Vector-Types
2456 
2458 // Tree
2459 template <class TVal>
2460 class TTree{
2461 private:
2462  TVec<TTriple<TInt, TIntV, TVal> > NodeV; // (ParentNodeId, ChildNodeIdV, NodeVal)
2463 public:
2464  TTree(): NodeV(){}
2465  TTree(const TTree& Tree): NodeV(Tree.NodeV){}
2466  explicit TTree(TSIn& SIn): NodeV(SIn){}
2467  void Save(TSOut& SOut) const {NodeV.Save(SOut);}
2468  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
2469  void SaveXml(TSOut& SOut, const TStr& Nm) const;
2470 
2471  TTree& operator=(const TTree& Tree){if (this!=&Tree){NodeV=Tree.NodeV;} return *this;}
2472  bool operator==(const TTree& Tree) const {return NodeV==Tree.NodeV;}
2473  bool operator<(const TTree& Tree) const {return false;}
2474 
2475  int GetPrimHashCd() const {return NodeV.GetPrimHashCd();}
2476  int GetSecHashCd() const {return NodeV.GetSecHashCd();}
2477 
2478  int GetMemUsed() const {return NodeV.GetMemUsed();}
2479 
2480  void Clr(){NodeV.Clr();}
2481 
2482  int AddNode(const int& ParentNodeId, const TVal& NodeVal=TVal()){
2483  IAssert(((ParentNodeId==-1)&&(NodeV.Len()==0))||(NodeV.Len()>0));
2484  if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.Add(NodeV.Len());}
2485  return NodeV.Add(TTriple<TInt, TIntV, TVal>(ParentNodeId, TIntV(), NodeVal));}
2486  int AddRoot(const TVal& NodeVal=TVal()){
2487  return AddNode(-1, NodeVal);}
2488 
2489  int GetNodes() const {return NodeV.Len();}
2490  void GetNodeIdV(TIntV& NodeIdV, const int& NodeId=0);
2491  int GetParentNodeId(const int& NodeId) const {return NodeV[NodeId].Val1;}
2492  int GetChildren(const int& NodeId) const {return NodeV[NodeId].Val2.Len();}
2493  int GetChildNodeId(const int& NodeId, const int& ChildN) const {return NodeV[NodeId].Val2[ChildN];}
2494  TVal& GetNodeVal(const int& NodeId){return NodeV[NodeId].Val3;}
2495 
2496  void GenRandomTree(const int& Nodes, TRnd& Rnd);
2497 
2498  void DelNode(const int& NodeId);
2499  void CopyTree(const int& SrcNodeId, TTree& DstTree, const int& DstParentNodeId=-1);
2500 
2501  void WrTree(const int& NodeId=0, const int& Lev=0);
2502 };
2503 
2504 template <class TVal>
2505 void TTree<TVal>::GetNodeIdV(TIntV& NodeIdV, const int& NodeId){
2506  if (NodeId==0){NodeIdV.Clr(); if (GetNodes()==0){return;}}
2507  else if (GetParentNodeId(NodeId)==-1){return;}
2508  NodeIdV.Add(NodeId);
2509  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2510  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2511  if (ChildNodeId!=-1){
2512  GetNodeIdV(NodeIdV, ChildNodeId);
2513  }
2514  }
2515 }
2516 
2517 template <class TVal>
2518 void TTree<TVal>::GenRandomTree(const int& Nodes, TRnd& Rnd){
2519  Clr();
2520  if (Nodes>0){
2521  AddRoot(TVal());
2522  for (int NodeN=1; NodeN<Nodes; NodeN++){
2523  int ParentNodeId=Rnd.GetUniDevInt(0, GetNodes()-1);
2524  AddNode(ParentNodeId, TVal());
2525  }
2526  }
2527 }
2528 
2529 template <class TVal>
2530 void TTree<TVal>::DelNode(const int& NodeId){
2531  if (NodeId==0){
2532  Clr();
2533  } else {
2534  TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2535  int ChildNodeIdN=ChildNodeIdV.SearchForw(NodeId);
2536  ChildNodeIdV[ChildNodeIdN]=-1;
2537  }
2538 }
2539 
2540 template <class TVal>
2541 void TTree<TVal>::CopyTree(const int& SrcNodeId, TTree& DstTree, const int& DstParentNodeId){
2542  int DstNodeId=DstTree.AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
2543  for (int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
2544  int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
2545  if (ChildNodeId!=-1){
2546  CopyTree(ChildNodeId, DstTree, DstNodeId);
2547  }
2548  }
2549 }
2550 
2551 template <class TVal>
2552 void TTree<TVal>::WrTree(const int& NodeId, const int& Lev){
2553  for (int LevN=0; LevN<Lev; LevN++){printf("| ");}
2554  printf("%d (%d)\n", NodeId, GetChildren(NodeId));
2555  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2556  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2557  if (ChildNodeId!=-1){
2558  WrTree(ChildNodeId, Lev+1);
2559  }
2560  }
2561 }
2562 
2564 // Common-Tree-Types
2570 
2572 // Stack
2573 template <class TVal>
2574 class TSStack{
2575 private:
2577 public:
2578  TSStack(): ValV(){}
2579  TSStack(const int& MxVals): ValV(MxVals, 0){}
2580  TSStack(const TSStack& Stack): ValV(Stack.ValV){}
2581  explicit TSStack(TSIn& SIn): ValV(SIn){}
2582  void Save(TSOut& SOut) const {ValV.Save(SOut);}
2583 
2584  TSStack& operator=(const TSStack& Stack){
2585  if (this!=&Stack){ValV=Stack.ValV;} return *this;}
2586  bool operator==(const TSStack& Stack) const {return this==&Stack;}
2587  const TVal& operator[](const int& ValN) const {return ValV[ValV.Len()-ValN-1];}
2588  TVal& operator[](const int& ValN) {return ValV[ValV.Len()-ValN-1];}
2589 
2590  bool Empty(){return ValV.Len()==0;}
2591  void Clr(const bool& DoDel=false) {ValV.Clr(DoDel);}
2592  bool IsIn(const TVal& Val) const {return ValV.IsIn(Val);}
2593  int Len(){return ValV.Len();}
2594  TVal& Top(){Assert(0<ValV.Len()); return ValV.Last();}
2595  const TVal& Top() const {Assert(0<ValV.Len()); return ValV.Last();}
2596  void Push(){ValV.Add();}
2597  void Push(const TVal& Val){ValV.Add(Val);}
2598  void Pop(){Assert(0<ValV.Len()); ValV.DelLast();}
2599 };
2600 
2602 // Common-Stack-Types
2605 
2607 // Queue
2608 template <class TVal>
2609 class TQQueue{
2610 private:
2614 public:
2615  TQQueue(const int& _MxLast=64, const int& _MxLen=-1):
2616  MxLast(_MxLast), MxLen(_MxLen), First(0), Last(0), ValV(){
2617  Assert(int(MxLast)>0); Assert((MxLen==-1)||(int(MxLen)>0));}
2618  TQQueue(const TQQueue& Queue):
2619  MxLast(Queue.MxLast), MxLen(Queue.MxLen),
2620  First(Queue.First), Last(Queue.Last), ValV(Queue.ValV){}
2621  explicit TQQueue(TSIn& SIn):
2622  MxLast(SIn), MxLen(SIn), First(SIn), Last(SIn), ValV(SIn){}
2623  void Save(TSOut& SOut) const {
2624  MxLast.Save(SOut); MxLen.Save(SOut);
2625  First.Save(SOut); Last.Save(SOut); ValV.Save(SOut);}
2626 
2627  TQQueue& operator=(const TQQueue& Queue){
2628  if (this!=&Queue){MxLast=Queue.MxLast; MxLen=Queue.MxLen;
2629  First=Queue.First; Last=Queue.Last; ValV=Queue.ValV;}
2630  return *this;}
2631  const TVal& operator[](const int& ValN) const {Assert((0<=ValN)&&(ValN<Len()));
2632  return ValV[Last+ValN];}
2633 
2634  void Clr(const bool& DoDel=true){ValV.Clr(DoDel); First=Last=0;}
2635  void Gen(const int& _MxLast=64, const int& _MxLen=-1){
2636  MxLast=_MxLast; MxLen=_MxLen; First=0; Last=0; ValV.Clr();}
2637  void GetSubValV(const int& _BValN, const int& _EValN, TVec<TVal>& SubValV) const {
2638  int BValN=TInt::GetMx(0, _BValN);
2639  int EValN=TInt::GetMn(Len()-1, _EValN);
2640  SubValV.Gen(EValN-BValN+1);
2641  for (int ValN=BValN; ValN<=EValN; ValN++){
2642  SubValV[ValN-BValN]=ValV[Last+ValN];}
2643  }
2644 
2645  bool Empty() const {return First==Last;}
2646  int Len() const {return First-Last;}
2647  const TVal& Top() const {
2648  Assert(First!=Last); return ValV[Last];}
2649  void Pop(){
2650  IAssert(First!=Last); Last++;
2651  if (First==Last){ValV.Clr(); First=Last=0;}}
2652  void Push(const TVal& Val){
2653  if (Last>MxLast){ValV.Del(0, Last-1); First-=Last; Last=0;}
2654  if ((MxLen!=-1)&&(MxLen==Len())){Pop();}
2655  First++; ValV.Add(Val);}
2656 
2657  void Shuffle(TRnd& Rnd){
2658  TVec<TVal> ValV(Len(), 0); while (!Empty()){ValV.Add(Top()); Pop();}
2659  ValV.Shuffle(Rnd); Clr();
2660  for (int ValN=0; ValN<ValV.Len(); ValN++){Push(ValV[ValN]);}}
2661 };
2662 
2664 // Common-Queue-Types
2673 
2675 // List-Node
2676 template <class TVal>
2677 class TLstNd{
2678 public:
2681  TVal Val;
2682 public:
2683  TLstNd(): PrevNd(NULL), NextNd(NULL), Val(){}
2684  TLstNd(const TLstNd&);
2685  TLstNd(TLstNd* _PrevNd, TLstNd* _NextNd, const TVal& _Val):
2686  PrevNd(_PrevNd), NextNd(_NextNd), Val(_Val){}
2687 
2688  TLstNd& operator=(const TLstNd&);
2689 
2690  bool IsPrev() const {return (PrevNd != NULL); }
2691  bool IsNext() const {return (NextNd != NULL); }
2692  TLstNd* Prev() const {Assert(this!=NULL); return PrevNd;}
2693  TLstNd* Next() const {Assert(this!=NULL); return NextNd;}
2694  TVal& GetVal(){Assert(this!=NULL); return Val;}
2695  const TVal& GetVal() const {Assert(this!=NULL); return Val;}
2696 };
2697 
2699 // List
2700 template <class TVal>
2701 class TLst{
2702 public:
2704 private:
2705  int Nds;
2708 public:
2709  TLst(): Nds(0), FirstNd(NULL), LastNd(NULL){}
2710  TLst(const TLst&);
2711  ~TLst(){Clr();}
2712  explicit TLst(TSIn& SIn);
2713  void Save(TSOut& SOut) const;
2714 
2715  TLst& operator=(const TLst&);
2716 
2717  void Clr(){
2718  PLstNd Nd=FirstNd;
2719  while (Nd!=NULL){PLstNd NextNd=Nd->NextNd; delete Nd; Nd=NextNd;}
2720  Nds=0; FirstNd=NULL; LastNd=NULL;}
2721 
2722  bool Empty() const {return Nds==0;}
2723  int Len() const {return Nds;}
2724  PLstNd First() const {return FirstNd;}
2725  PLstNd Last() const {return LastNd;}
2726  TVal& FirstVal() const {return FirstNd->GetVal();}
2727  TVal& LastVal() const {return LastNd->GetVal();}
2728 
2729  PLstNd AddFront(const TVal& Val);
2730  PLstNd AddBack(const TVal& Val);
2731  PLstNd AddFrontSorted(const TVal& Val, const bool& Asc=true);
2732  PLstNd AddBackSorted(const TVal& Val, const bool& Asc=true);
2733  void PutFront(const PLstNd& Nd);
2734  void PutBack(const PLstNd& Nd);
2735  PLstNd Ins(const PLstNd& Nd, const TVal& Val);
2736  void Del(const TVal& Val);
2737  void Del(const PLstNd& Nd);
2738  void DelFirst() { PLstNd DelNd = FirstNd; Del(DelNd); }
2739  void DelLast() { PLstNd DelNd = LastNd; Del(DelNd); }
2740 
2741  PLstNd SearchForw(const TVal& Val);
2742  PLstNd SearchBack(const TVal& Val);
2743 
2744  friend class TLstNd<TVal>;
2745 };
2746 
2747 template <class TVal>
2749  Nds(0), FirstNd(NULL), LastNd(NULL){
2750  int CheckNds=0; SIn.Load(CheckNds);
2751  for (int NdN=0; NdN<CheckNds; NdN++){AddBack(TVal(SIn));}
2752  Assert(Nds==CheckNds);
2753 }
2754 
2755 template <class TVal>
2756 void TLst<TVal>::Save(TSOut& SOut) const {
2757  SOut.Save(Nds);
2758  PLstNd Nd=FirstNd; int CheckNds=0;
2759  while (Nd!=NULL){
2760  Nd->Val.Save(SOut); Nd=Nd->NextNd; CheckNds++;}
2761  IAssert(Nds==CheckNds);
2762 }
2763 
2764 template <class TVal>
2766  PLstNd Nd=new TLstNd<TVal>(NULL, FirstNd, Val);
2767  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
2768  else {FirstNd=Nd; LastNd=Nd;}
2769  Nds++; return Nd;
2770 }
2771 
2772 template <class TVal>
2774  PLstNd Nd=new TLstNd<TVal>(LastNd, NULL, Val);
2775  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
2776  else {FirstNd=Nd; LastNd=Nd;}
2777  Nds++; return Nd;
2778 }
2779 
2780 template <class TVal>
2781 TLstNd<TVal>* TLst<TVal>::AddFrontSorted(const TVal& Val, const bool& Asc){
2782  PLstNd Nd=First();
2783  if (Nd==NULL){
2784  return Ins(Nd, Val);
2785  } else {
2786  while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
2787  Nd=Nd->Next();}
2788  if (Nd==NULL){return Ins(Nd->Last(), Val);}
2789  else {return Ins(Nd->Prev(), Val);}
2790  }
2791 }
2792 
2793 template <class TVal>
2794 TLstNd<TVal>* TLst<TVal>::AddBackSorted(const TVal& Val, const bool& Asc){
2795  PLstNd Nd=Last();
2796  while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->Val)))){
2797  Nd=Nd->Prev();}
2798  return Ins(Nd, Val);
2799 }
2800 
2801 template <class TVal>
2803  Assert(Nd!=NULL);
2804  // unchain
2805  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2806  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2807  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2808  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2809  // add to front
2810  Nd->PrevNd=NULL; Nd->NextNd=FirstNd;
2811  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
2812  else {FirstNd=Nd; LastNd=Nd;}
2813 }
2814 
2815 template <class TVal>
2816 void TLst<TVal>::PutBack(const PLstNd& Nd){
2817  Assert(Nd!=NULL);
2818  // unchain
2819  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2820  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2821  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2822  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2823  // add to back
2824  Nd->PrevNd=LastNd; Nd->NextNd=NULL;
2825  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
2826  else {FirstNd=Nd; LastNd=Nd;}
2827 }
2828 
2829 template <class TVal>
2830 TLstNd<TVal>* TLst<TVal>::Ins(const PLstNd& Nd, const TVal& Val){
2831  if (Nd==NULL){return AddFront(Val);}
2832  else if (Nd->NextNd==NULL){return AddBack(Val);}
2833  else {
2834  PLstNd NewNd=new TLstNd<TVal>(Nd, Nd->NextNd, Val);
2835  Nd->NextNd=NewNd; NewNd->NextNd->PrevNd=Nd;
2836  Nds++; return Nd;
2837  }
2838 }
2839 
2840 template <class TVal>
2841 void TLst<TVal>::Del(const TVal& Val){
2842  PLstNd Nd=SearchForw(Val);
2843  if (Nd!=NULL){Del(Nd);}
2844 }
2845 
2846 template <class TVal>
2847 void TLst<TVal>::Del(const PLstNd& Nd){
2848  Assert(Nd!=NULL);
2849  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
2850  else {Nd->PrevNd->NextNd=Nd->NextNd;}
2851  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
2852  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
2853  Nds--; delete Nd;
2854 }
2855 
2856 template <class TVal>
2858  PLstNd Nd=First();
2859  while (Nd!=NULL){
2860  if (Nd->GetVal()==Val){return Nd;}
2861  Nd=Nd->Next();
2862  }
2863  return NULL;
2864 }
2865 
2866 template <class TVal>
2868  PLstNd Nd=Last();
2869  while (Nd!=NULL){
2870  if (Nd->GetVal()==Val){return Nd;}
2871  Nd=Nd->Prev();
2872  }
2873  return NULL;
2874 }
2875 
2877 // Common-List-Types
2890 
2892 // Record-File
2893 template <class THd, class TRec>
2894 class TFRec{
2895 private:
2897 public:
2898  TFRec(const TStr& FNm, const TFAccess& FAccess, const bool& CreateIfNo):
2899  FRnd(PFRnd(new TFRnd(FNm, FAccess, CreateIfNo, sizeof(THd), sizeof(TRec)))){}
2900  TFRec(const TFRec&);
2901 
2902  TFRec& operator=(const TFRec&);
2903 
2904  void SetRecN(const int& RecN){FRnd->SetRecN(RecN);}
2905  int GetRecN(){return FRnd->GetRecN();}
2906  int GetRecs(){return FRnd->GetRecs();}
2907 
2908  void GetHd(THd& Hd){FRnd->GetHd(&Hd);}
2909  void PutHd(const THd& Hd){FRnd->PutHd(&Hd);}
2910  void GetRec(TRec& Rec, const int& RecN=-1){FRnd->GetRec(&Rec, RecN);}
2911  void PutRec(const TRec& Rec, const int& RecN=-1){FRnd->PutRec(&Rec, RecN);}
2912 };
2913 
2915 // Function
2916 template <class TFuncPt>
2917 class TFunc{
2918 private:
2919  TFuncPt FuncPt;
2920 public:
2921  TFunc(): FuncPt(NULL){}
2922  TFunc(const TFunc& Func): FuncPt(Func.FuncPt){}
2923  TFunc(const TFuncPt& _FuncPt): FuncPt(_FuncPt){}
2925  void Save(TSOut&) const {Fail;}
2926 
2927  TFunc& operator=(const TFunc& Func){
2928  if (this!=&Func){FuncPt=Func.FuncPt;} return *this;}
2929  bool operator==(const TFunc& Func) const {
2930  return FuncPt==Func.FuncPt;}
2931  bool operator<(const TFunc&) const {
2932  Fail; return false;}
2933  TFuncPt operator()() const {return FuncPt;}
2934 };
Definition: ds.h:346
TSizeTy AddUnique(const TVal &Val)
Adds element Val to a vector only if the element Val is not already in the vector.
Definition: ds.h:1162
~TVec()
Definition: ds.h:461
void Save(TSOut &SOut) const
Definition: ds.h:2075
bool operator==(const TTree &Tree) const
Definition: ds.h:2472
Definition: bd.h:440
#define IAssert(Cond)
Definition: bd.h:262
TQuad< TStr, TStr, TStr, TStr > TStrQu
Definition: ds.h:262
TVec< TFltIntKd > TFltIntKdV
Definition: ds.h:1639
TFuncPt FuncPt
Definition: ds.h:2919
TVec< TVal > V
Definition: ds.h:2179
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:113
void GetV(const int &VId, TValV &ValV) const
Returns ValV which is a reference (not a copy) to vector with id VId.
Definition: ds.h:1736
const TVal & GetVal() const
Definition: ds.h:2695
TQQueue< TAscFltV > TAscFltVQ
Definition: ds.h:2671
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
TStr GetTypeNm(const Type &Var)
Definition: ut.h:16
bool operator==(const PVec< TVal > &Vec) const
Definition: ds.h:2197
::TSize GetVecs() const
Definition: ds.h:1965
TTriple(const TTriple &Triple)
Definition: ds.h:137
TPair(const TPair &Pair)
Definition: ds.h:38
TVec< TUInt64IntPr > TUInt64IntPrV
Definition: ds.h:1632
::TSize Vals
Definition: ds.h:1945
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1212
TTree< TStrIntStrVTr > TStrIntStrVTrTree
Definition: ds.h:2569
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
Definition: ds.h:595
TStr GetStr() const
Definition: ds.h:62
TInt64 YDim
Definition: ds.h:2411
TPair< TUCh, TStr > TUChStrPr
Definition: ds.h:80
TVec< TSFlt > TSFltV
Definition: ds.h:1597
TVec< TUInt > TUIntV
Definition: ds.h:1593
TTriple(TSIn &SIn)
Definition: ds.h:141
bool operator()(const TTriple< TVal1, TVal2, TVal3 > &T1, const TTriple< TVal1, TVal2, TVal3 > &T2) const
Definition: ds.h:211
bool Empty()
Definition: ds.h:2590
void Clr()
Definition: ds.h:2245
TTriple< TStr, TStr, TInt > TStrStrIntTr
Definition: ds.h:189
TPair(const TVal1 &_Val1, const TVal2 &_Val2)
Definition: ds.h:39
void SwapX(const TSizeTy &X1, const TSizeTy &X2)
Definition: ds.h:2294
TVVec< TCh > TChVV
Definition: ds.h:2399
TSizeTy Reserved() const
Returns the size of allocated storage capacity.
Definition: ds.h:577
TVec< TIntIntVIntTr > TIntIntVIntTrV
Definition: ds.h:1630
TStr GetStr() const
Definition: dt.h:1197
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TPair< TUInt, TUInt > TUIntUIntPr
Definition: ds.h:91
void ShuffleX(TRnd &Rnd)
Definition: ds.h:2315
TVec< TFltIntIntTr > TFltIntIntTrV
Definition: ds.h:1645
TVec< TIntIntFltTr > TIntIntFltTrV
Definition: ds.h:1619
void Save(TSOut &) const
Definition: ds.h:2925
TPair< TFlt, TInt > TFltIntPr
Definition: ds.h:97
PVec< TStr > TStrVP
Definition: ds.h:2216
int GetPrimHashCd() const
Returns primary hash code of the vector. Used by THash.
Definition: ds.h:999
TTriple< TInt, TStr, TInt > TIntStrIntTr
Definition: ds.h:173
bool operator<(const TFunc &) const
Definition: ds.h:2931
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:99
bool operator==(const TQuad &Quad) const
Definition: ds.h:243
PLstNd Ins(const PLstNd &Nd, const TVal &Val)
Definition: ds.h:2830
TPair()
Definition: ds.h:37
bool operator()(const TPair< TVal1, TVal2 > &P1, const TPair< TVal1, TVal2 > &P2) const
Definition: ds.h:122
void Save(TSOut &SOut) const
Definition: ds.h:41
void Merge()
Sorts the vector and only keeps a single element of each value.
Definition: ds.h:1356
TVal & At(const TSizeTy &X, const TSizeTy &Y)
Definition: ds.h:2258
TVec< TAscFltIntKd > TAscFltIntKdV
Definition: ds.h:1648
TInt Last
Definition: ds.h:2612
TTree()
Definition: ds.h:2464
Definition: ds.h:2175
TTuple & operator=(const TTuple &Tup)
Definition: ds.h:286
int64 GetUniDevInt64(const int64 &Range=0)
Definition: dt.cpp:51
static int GetInRng(const int &Val, const int &Mn, const int &Mx)
Definition: dt.h:1194
TVec< TAscFlt > TAscFltV
Definition: ds.h:1598
TQQueue & operator=(const TQQueue &Queue)
Definition: ds.h:2627
TInt64 ZDim
Definition: ds.h:2411
Definition: ds.h:272
TLstNd< TFlt > * PFltLN
Definition: ds.h:2883
TTriple< TStr, TInt, TStrV > TStrIntStrVTr
Definition: ds.h:190
bool Empty() const
Definition: ds.h:2645
TPair< TStr, TStr > TStrPr
Definition: ds.h:107
TVec< TVal, TSizeTy > & Get1DVec()
Definition: ds.h:2253
TPair< TStr, TFlt > TStrFltPr
Definition: ds.h:106
PLstNd SearchBack(const TVal &Val)
Definition: ds.h:2867
Definition: dt.h:11
TSStack(const TSStack &Stack)
Definition: ds.h:2580
uint64 Reserved() const
Returns the total capacity of the pool.
Definition: ds.h:1710
TPair< TUInt64, TFlt > TUInt64FltPr
Definition: ds.h:95
void DelNode(const int &NodeId)
Definition: ds.h:2530
static PVecPool New(const TSize &ExpectVals=0, const TSize &GrowBy=1000000, const bool &FastCopy=false)
Definition: ds.h:1696
TFunc(TSIn &)
Definition: ds.h:2924
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:95
Definition: ds.h:130
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1189
TTuple(TSIn &SIn)
Definition: ds.h:279
TVVec(const TSizeTy &_XDim, const TSizeTy &_YDim)
Definition: ds.h:2230
TVec< TStrPr > TStrPrV
Definition: ds.h:1649
void Save(TSOut &SOut) const
Definition: ds.h:2193
TVec< TStrFltKd > TStrFltKdV
Definition: ds.h:1653
int AddV(const TValV &ValV)
Adds vector ValV to the pool and returns its id.
Definition: ds.h:1869
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2482
TKeyDat< TFlt, TBool > TFltBoolKd
Definition: ds.h:391
TTree< TStr > TStrTree
Definition: ds.h:2567
void ShuffleY(TRnd &Rnd)
Definition: ds.h:2320
TVVVec(const TVVVec &Vec)
Definition: ds.h:2415
TVec< TIntIntStrTr > TIntIntStrTrV
Definition: ds.h:1618
void Clr()
Definition: ds.h:2433
void Push(const TVal &Val)
Definition: ds.h:2597
TVal & FirstVal() const
Definition: ds.h:2726
void Save(TSOut &SOut) const
Definition: dt.h:1150
bool operator()(const TKeyDat< TVal1, TVal2 > &P1, const TKeyDat< TVal1, TVal2 > &P2) const
Definition: ds.h:415
bool operator==(const TSStack &Stack) const
Definition: ds.h:2586
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
Definition: ds.h:828
bool operator<(const TVec< TVal, TSizeTy > &Vec) const
Lexicographically compares two vectors.
Definition: ds.h:981
void GetHd(THd &Hd)
Definition: ds.h:2908
TVecPool & operator=(const TVecPool &Pool)
Definition: ds.h:2088
#define forever
Definition: bd.h:6
void Reserve(const ::TSize &MxVals)
Definition: ds.h:1968
int Nds
Definition: ds.h:2705
TKeyDat(const TKey &_Key)
Definition: ds.h:353
unsigned int uint
Definition: bd.h:11
TVec< TIntStrKd > TIntStrKdV
Definition: ds.h:1627
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2491
void Save(TSOut &) const
Definition: ds.h:12
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2493
TFunc(const TFuncPt &_FuncPt)
Definition: ds.h:2923
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1182
TVal & Top()
Definition: ds.h:2594
static const int Mx
Definition: dt.h:1139
#define Fail
Definition: bd.h:238
void QSort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Quick sorts the values between positions MnLValN...MxLValN.
Definition: ds.h:1305
PLstNd AddBackSorted(const TVal &Val, const bool &Asc=true)
Definition: ds.h:2794
char * AdvanceCursor(TSize N)
Return the current pointer and advance the cursor.
Definition: fl.h:425
::TSize GetVals() const
Definition: ds.h:1964
const TVal1 & GetVal1() const
Definition: ds.h:60
TVal * ValBf
Definition: ds.h:1681
uint64 GetMemUsed() const
Returns the total memory footprint (in bytes) of the pool.
Definition: ds.h:1718
bool IsSortedCmp(const TCmp &Cmp) const
Checks whether the vector is sorted according to the comparator Cmp.
Definition: ds.h:773
TKeyDat< TUInt64, TFlt > TUInt64FltKd
Definition: ds.h:389
void SetEmptyVal(const TVal &_EmptyVal)
Definition: ds.h:1970
PVec< TAscFlt > TAscFltVP
Definition: ds.h:2214
const TVal & operator()(const TSizeTy &X, const TSizeTy &Y) const
Definition: ds.h:2263
TVal2 Val2
Definition: ds.h:222
TFunc(const TFunc &Func)
Definition: ds.h:2922
TVal & LastVal() const
Definition: ds.h:2727
TVec< TVal > TValV
Definition: ds.h:1941
int Len() const
Definition: ds.h:2723
TVVVec< TVal, TSizeTy > & operator=(const TVVVec< TVal, TSizeTy > &Vec)
Definition: ds.h:2424
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TKeyDat< TInt, TFlt > TIntFltKd
Definition: ds.h:381
TVec< TIntIntIntVTr > TIntIntIntVTrV
Definition: ds.h:1631
TVec< TFltTr > TFltTrV
Definition: ds.h:1605
void PutRec(const void *Rec, const int &RecN=-1)
Definition: fl.h:614
TLstNd * Prev() const
Definition: ds.h:2692
int GetSecHashCd() const
Returns secondary hash code of the vector. Used by THash.
Definition: ds.h:1011
void GetSwitchedKdV(const TVec< TKeyDat< TKey, TDat >, int > &SrcKdV, TVec< TKeyDat< TDat, TKey >, int > &DstKdV)
Definition: ds.h:370
void Diff(const TVec< TVal, TSizeTy > &ValV)
Subtracts ValV from this vector. Assumes the vectors are sorted!
Definition: ds.h:1425
const TVal3 & GetVal3() const
Definition: ds.h:257
void Save(TSOut &SOut) const
Definition: ds.h:2756
const TVal & At(const TSizeTy &X, const TSizeTy &Y, const TSizeTy &Z) const
Definition: ds.h:2440
void GenExt(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
Definition: ds.h:534
TTriple< TInt, TInt, TFlt > TIntIntFltTr
Definition: ds.h:175
Definition: ds.h:2701
TVec< TIntKd > TIntKdV
Definition: ds.h:1606
void GetVal(TVal1 &_Val1, TVal2 &_Val2) const
Definition: ds.h:59
TKeyDat< TInt, TFltPr > TIntFltPrKd
Definition: ds.h:383
TVec< TFltStrPr > TFltStrPrV
Definition: ds.h:1615
TKeyDat< TUInt64, TStr > TUInt64StrKd
Definition: ds.h:390
TTree(TSIn &SIn)
Definition: ds.h:2466
TVec< TIntFltPrKd > TIntFltPrKdV
Definition: ds.h:1612
TLstNd * NextNd
Definition: ds.h:2680
TVec< TStrTr > TStrTrV
Definition: ds.h:1655
TTriple(const TVal1 &_Val1, const TVal2 &_Val2, const TVal3 &_Val3)
Definition: ds.h:139
TRec * operator->() const
Definition: ds.h:20
TKeyDat< TFlt, TStr > TFltStrKd
Definition: ds.h:397
void Save(TSOut &SOut) const
Definition: ds.h:142
bool IsVId(const int &VId) const
Definition: ds.h:1966
TSizeTy AddMP(const TVal &Val)
Adds element Val at the end of the vector in a thread safe manner, returns the element index in the v...
Definition: ds.h:617
TVal3 Val3
Definition: ds.h:223
void Save(TSOut &SOut) const
Definition: ds.h:2623
void PutRec(const TRec &Rec, const int &RecN=-1)
Definition: ds.h:2911
TVal & GetRndVal(TRnd &Rnd=TInt::Rnd)
Returns a reference to a random element in the vector.
Definition: ds.h:591
int AddV(const TValV &ValV)
Definition: ds.h:2108
TVec< TFltPr > TFltPrV
Definition: ds.h:1604
void SetEmptyVal(const TVal &_EmptyVal)
Sets the empty value.
Definition: ds.h:1716
void Swap(TVVec< TVal, TSizeTy > &Vec)
Definition: ds.h:2306
TVec< TStrQu > TStrQuV
Definition: ds.h:1656
Vector Pool.
Definition: ds.h:1672
void Load(TSIn &SIn)
Definition: ds.h:2235
void Save(TSOut &SOut) const
Definition: ds.h:1834
TCRef CRef
Definition: ds.h:2177
TVec< TStrAscFltKd > TStrAscFltKdV
Definition: ds.h:1654
TDat Dat
Definition: ds.h:349
TKeyDat< TStr, TInt > TStrIntKd
Definition: ds.h:402
void SetRecN(const int &RecN)
Definition: ds.h:2904
TTriple< TInt, TFlt, TInt > TIntFltIntTr
Definition: ds.h:176
TVec< TIntIntPrPr > TIntIntPrPrV
Definition: ds.h:1664
Definition: ds.h:2677
TPair< TStrV, TInt > TStrVIntPr
Definition: ds.h:109
void DelX(const TSizeTy &X)
Definition: ds.h:2357
int GetSecHashCd() const
Definition: ds.h:301
TVec< ::TSize > IdToOffV
Definition: ds.h:1948
Definition: fl.h:384
TQQueue< TIntPr > TIntPrQ
Definition: ds.h:2668
const TVal2 & GetVal2() const
Definition: ds.h:61
TVal1 Val1
Definition: ds.h:132
void Load(TSIn &SIn)
Definition: ds.h:281
TSizeTy Add(const TVal &Val, const TSizeTy &ResizeLen)
Adds element Val at the end of the vector. #TVec::Add2.
Definition: ds.h:613
PLstNd LastNd
Definition: ds.h:2707
TVec< TVal > ValV
Definition: ds.h:2613
TSizeTy SearchBinLeft(const TVal &Val, TSizeTy &InsValN) const
Returns the position of an element with value Val.
Definition: ds.h:1541
void Clr(const bool &DoDel=false)
Definition: ds.h:2591
bool operator==(const TKeyDat &KeyDat) const
Definition: ds.h:362
int GetSecHashCd() const
Definition: ds.h:251
void Swap(const TSizeTy &ValN1, const TSizeTy &ValN2)
Swaps elements at positions ValN1 and ValN2.
Definition: ds.h:674
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:396
TVec< TStrStrVPr > TStrStrVPrV
Definition: ds.h:1660
TTriple< TStr, TInt, TInt > TStrIntIntTr
Definition: ds.h:187
void CompactPool(const TVal &DelVal)
Deletes all elements of value DelVal from all vectors.
Definition: ds.h:1889
TSStack()
Definition: ds.h:2578
TPair< TUInt, TInt > TUIntIntPr
Definition: ds.h:92
void Load(TSIn &SIn)
Definition: ds.h:946
PLstNd AddFront(const TVal &Val)
Definition: ds.h:2765
TQQueue(TSIn &SIn)
Definition: ds.h:2621
void CopyUniqueFrom(TVec< TVal, TSizeTy > &Vec, TInt Offset, TInt Sz)
Copy Sz values from Vec starting at Offset.
Definition: ds.h:1082
void Resize(const TSize &_MxVals)
Definition: ds.h:1770
static TRnd Rnd
Definition: dt.h:1143
int FindMx() const
Definition: ds.h:320
TVec(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
Definition: ds.h:459
TPair< TInt, TVec< TInt, int > > TIntIntVPr
Definition: ds.h:86
::TSize GrowBy
Definition: ds.h:1945
TVal & LastLast()
Returns a reference to the one before last element of the vector.
Definition: ds.h:587
TRec * operator()() const
Definition: ds.h:24
void AddXDim()
Definition: ds.h:2343
TSizeTy GetMemUsed() const
Returns the memory footprint (the number of bytes) of the vector.
Definition: ds.h:511
TVal & operator[](const int &ValN)
Definition: ds.h:2588
void PutFront(const PLstNd &Nd)
Definition: ds.h:2802
Definition: fl.h:275
TVec< TIntTr > TIntTrV
Definition: ds.h:1602
TPair(TSIn &SIn)
Definition: ds.h:40
TSizeTy AddVMerged(const TVec< TVal, TSizeTy > &ValV)
Adds elements of ValV to a sorted vector only if a particular element is not already in the vector...
Definition: ds.h:1154
TVal1 Val1
Definition: ds.h:221
TLst & operator=(const TLst &)
bool operator<(const TKeyDat &KeyDat) const
Definition: ds.h:363
void Reduce(const TSizeTy &_Vals=-1)
Reduces the vector's length to _Vals elements, which must be less than the current length...
Definition: ds.h:556
static PVecPool Load(const TStr &FNm)
Definition: ds.h:1959
TPt< TVecPool< TVal, TSizeTy > > PVecPool
Definition: ds.h:1674
bool operator()(const TTriple< TVal1, TVal2, TVal3 > &T1, const TTriple< TVal1, TVal2, TVal3 > &T2) const
Definition: ds.h:199
TPair< TInt, TUInt64 > TIntUInt64Pr
Definition: ds.h:84
void GetNodeIdV(TIntV &NodeIdV, const int &NodeId=0)
Definition: ds.h:2505
TSize GetVals() const
Returns the total number of values stored in the vector pool.
Definition: ds.h:1706
void PutAll(const TVal &Val)
Definition: ds.h:2003
TVec< TStrKd > TStrKdV
Definition: ds.h:1659
TVecPool & operator=(const TVecPool &Pool)
Definition: ds.h:1847
TSize GrowBy
Definition: ds.h:1679
TKeyDat< TFlt, TIntBoolPr > TFltIntBoolPrKd
Definition: ds.h:399
const TVal & GetEmptyVal() const
Definition: ds.h:1969
bool operator==(const TAPt &Pt) const
Definition: ds.h:16
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1117
void DelLast()
Definition: ds.h:2739
TPair< TAscFlt, TInt > TAscFltIntPr
Definition: ds.h:101
TInt First
Definition: ds.h:2612
TKeyDat< TInt, TStr > TIntStrKd
Definition: ds.h:385
int GetSecHashCd() const
Definition: ds.h:157
int AddEmptyV(const int &ValVLen)
Adds a vector of length ValVLen to the pool and returns its id.
Definition: ds.h:1880
TQuad< TInt, TInt, TInt, TInt > TIntQu
Definition: ds.h:263
Definition: dt.h:1383
void Clr(bool DoDel=true)
Definition: ds.h:1998
TSStack(TSIn &SIn)
Definition: ds.h:2581
bool Empty() const
Definition: ds.h:2722
TPair< TInt, TBool > TIntBoolPr
Definition: ds.h:81
TVal & operator[](const int &ValN)
Definition: ds.h:284
Definition: fl.h:58
void Save(TSOut &SOut) const
Definition: ds.h:954
const TVal & Top() const
Definition: ds.h:2595
TVVVec(const TSizeTy &_XDim, const TSizeTy &_YDim, const TSizeTy &_ZDim)
Definition: ds.h:2417
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:570
int GetRecs()
Definition: ds.h:2906
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:87
void Save(TSOut &SOut) const
Definition: ds.h:234
TPair< TInt, TStrV > TIntStrVPr
Definition: ds.h:89
void Reverse(TSizeTy LValN, TSizeTy RValN)
Reverses the order of elements between LValN...RValN.
Definition: ds.h:723
TTriple< TFlt, TFlt, TStr > TFltFltStrTr
Definition: ds.h:184
void PutV(const int &VId, const TValV &ValV)
Sets the values of vector VId with those in ValV.
Definition: ds.h:1740
void DelAll(const TVal &Val)
Removes all occurrences of element Val.
Definition: ds.h:1221
TVVec(const TVec< TVal, TSizeTy > &_ValV, const TSizeTy &_XDim, const TSizeTy &_YDim)
Definition: ds.h:2232
void Intrs(const TVec< TVal, TSizeTy > &ValV)
Sets this vector to its intersection with ValV. Assumes the vectors are sorted!
Definition: ds.h:1411
TVec< TIntUInt64Pr > TIntUInt64PrV
Definition: ds.h:1609
int GetRecN()
Definition: ds.h:2905
TKeyDat< TStr, TFlt > TStrFltKd
Definition: ds.h:403
const TVal & operator[](const int &ValN) const
Definition: ds.h:2587
TLstNd & operator=(const TLstNd &)
int GetNodes() const
Definition: ds.h:2489
TPair< TInt, TFlt > TIntFltPr
Definition: ds.h:87
uint GetVLen(const int &VId) const
Definition: ds.h:1976
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1101
TVal Val
Definition: ds.h:2681
TVec< TIntFltPr > TIntFltPrV
Definition: ds.h:1611
void GetVal(TVal1 &_Val1, TVal2 &_Val2, TVal3 &_Val3, TVal4 &_Val4) const
Definition: ds.h:253
const TVal & GetRndVal(TRnd &Rnd=TInt::Rnd) const
Returns a reference to a random element in the vector.
Definition: ds.h:589
const TVal & operator()(const TSizeTy &X, const TSizeTy &Y, const TSizeTy &Z) const
Definition: ds.h:2445
void Shuffle(TRnd &Rnd)
Definition: ds.h:2657
int Len() const
Definition: ds.h:2202
TVec< TFltIntPrKd > TFltIntPrKdV
Definition: ds.h:1641
TSStack(const int &MxVals)
Definition: ds.h:2579
int FindMn() const
Definition: ds.h:332
TTree & operator=(const TTree &Tree)
Definition: ds.h:2471
TQQueue< TInt > TIntQ
Definition: ds.h:2665
TSizeTy Add(TVal &Val)
Definition: ds.h:610
void Pop()
Definition: ds.h:2649
TVec< TStrFltPr > TStrFltPrV
Definition: ds.h:1651
TQuad< TStr, TStr, TInt, TInt > TStrStrIntIntQu
Definition: ds.h:261
int GetMemUsed() const
Definition: ds.h:54
TKeyDat()
Definition: ds.h:351
int GetPrimHashCd() const
Definition: ds.h:250
TVec< TVal, TSizeTy > TValV
Definition: ds.h:1675
TSizeTy MoveLastMP(const TVal &Val, int Inc)
Reserves space after the current last element in a thread safe manner, returning the old vector size...
Definition: ds.h:622
TVal2 Val2
Definition: ds.h:133
TVal EmptyVal
Definition: ds.h:1680
TSizeTy GetPivotValN(const TSizeTy &LValN, const TSizeTy &RValN) const
Picks three random elements at positions LValN...RValN and returns the middle one.
Definition: ds.h:1265
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:649
TTriple< TFlt, TFlt, TInt > TFltFltIntTr
Definition: ds.h:183
void Gen(const int &_MxLast=64, const int &_MxLen=-1)
Definition: ds.h:2635
TVec< TStrFltFltTr > TStrFltFltTrV
Definition: ds.h:1657
bool Empty() const
Definition: ds.h:2432
TInt64 XDim
Definition: ds.h:2411
TAPt(TSIn &)
Definition: ds.h:11
TKeyDat< TAscFlt, TInt > TAscFltIntKd
Definition: ds.h:400
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:83
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
PLstNd FirstNd
Definition: ds.h:2706
TAPt()
Definition: ds.h:8
bool IsAsc
Definition: ds.h:208
::TSize MxVals
Definition: ds.h:1945
void PutHd(const void *Hd)
Definition: fl.h:610
TVec< TUInt64IntKd > TUInt64IntKdV
Definition: ds.h:1635
TPair< TFlt, TStrPr > TFltStrPrPr
Definition: ds.h:112
void Load(TSIn &SIn)
Definition: dt.h:903
bool operator==(const TFunc &Func) const
Definition: ds.h:2929
TVec< TIntPrFltKd > TIntPrFltKdV
Definition: ds.h:1626
TTriple< TCh, TCh, TCh > TChTr
Definition: ds.h:168
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:1730
TVec< TAscFltStrPr > TAscFltStrPrV
Definition: ds.h:1616
TVec< TStrVIntPr > TStrVIntPrV
Definition: ds.h:1661
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1180
TTree< TStrIntPr > TStrIntPrTree
Definition: ds.h:2568
void PutX(const TSizeTy &X, const TVal &Val)
Definition: ds.h:2268
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1318
bool operator==(const TTuple &Tup) const
Definition: ds.h:288
bool NextPerm()
Generates next permutation of the elements in the vector.
Definition: ds.h:1368
TVec< TIntPr > TIntPrV
Definition: ds.h:1601
TVec< TVal, TSizeTy > & operator=(const TVec< TVal, TSizeTy > &Vec)
Assigns new contents to the vector, replacing its current content.
Definition: ds.h:961
TVec< TUIntIntKd > TUIntIntKdV
Definition: ds.h:1624
Definition: ds.h:2222
TAPt(TRec *_Addr)
Definition: ds.h:10
TPt< TVecPool< TVal > > PVecPool
Definition: ds.h:1940
const TVal1 & GetVal1() const
Definition: ds.h:163
TPt< TFltVP > PFltV
Definition: ds.h:2213
~TLst()
Definition: ds.h:2711
int GetSecHashCd() const
Definition: ds.h:2476
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
Definition: ds.h:1229
TVec< TStrStrIntTr > TStrStrIntTrV
Definition: ds.h:1658
TSizeTy GetZDim() const
Definition: ds.h:2449
TFRec(const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)
Definition: ds.h:2898
unsigned long long uint64
Definition: bd.h:38
void GetHd(void *Hd)
Definition: fl.h:608
TLst< TFlt > TFltL
Definition: ds.h:2882
TVal & operator[](const int &ValN) const
Definition: ds.h:2199
const TVal & LastLast() const
Returns a reference to the one before last element of the vector.
Definition: ds.h:585
TVec< TFltFltStrTr > TFltFltStrTrV
Definition: ds.h:1646
bool operator==(const TPair &Pair) const
Definition: ds.h:49
void Save(TSOut &SOut) const
Definition: dt.h:904
TPair< TInt, TIntPr > TIntIntPrPr
Definition: ds.h:85
TSizeTy GetYDim() const
Definition: ds.h:2250
TInt MxLen
Definition: ds.h:2611
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:91
void Load(bool &Bool)
Definition: fl.h:84
TQuad< TFlt, TInt, TInt, TInt > TFltIntIntIntQu
Definition: ds.h:265
static PVecPool Load(TSIn &SIn)
Definition: ds.h:1958
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1728
TLstNd()
Definition: ds.h:2683
bool IsInBin(const TVal &Val) const
Checks whether element Val is a member of the vector.
Definition: ds.h:836
bool IsExt() const
Returns true if the vector was created using the GenExt().
Definition: ds.h:541
void CopyTree(const int &SrcNodeId, TTree &DstTree, const int &DstParentNodeId=-1)
Definition: ds.h:2541
TVec< TUInt64FltKd > TUInt64FltKdV
Definition: ds.h:1636
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
Definition: ds.h:838
void PutAll(const TVal &Val)
Definition: ds.h:2267
TQuad< TInt, TInt, TFlt, TFlt > TIntIntFltFltQu
Definition: ds.h:267
TPair< TBool, TCh > TBoolChPr
Definition: ds.h:76
TVec< TFltUInt64Kd > TFltUInt64KdV
Definition: ds.h:1640
#define TSizeMx
Definition: bd.h:59
void Clr(bool DoDel=true)
Clears the contents of the pool.
Definition: ds.h:1759
TCmpTripleByVal2(const bool &AscSort=true)
Definition: ds.h:198
TVVec< TFlt > TFltVV
Definition: ds.h:2402
int GetSecHashCd() const
Definition: ds.h:366
TCmpTripleByVal3(const bool &AscSort=true)
Definition: ds.h:210
bool IsNext() const
Definition: ds.h:2691
void AddYDim()
Definition: ds.h:2350
TVVVec< TFlt > TFltVVV
Definition: ds.h:2455
const TVal2 & GetVal2() const
Definition: ds.h:256
Definition: bd.h:402
static TIter GetPivotValNCmp(const TIter &BI, const TIter &EI, const TCmp &Cmp)
Picks three random elements at positions BI...EI and returns the middle one under the comparator Cmp...
Definition: ds.h:729
void Resize(const ::TSize &_MxVals)
Definition: ds.h:2010
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3)
Returns a vector on elements Val1...Val3.
Definition: ds.h:854
void Save(TSOut &SOut) const
Definition: ds.h:356
size_t TSize
Definition: bd.h:58
#define Assert(Cond)
Definition: bd.h:251
TTree< TFlt > TFltTree
Definition: ds.h:2566
TSStack< TInt > TIntS
Definition: ds.h:2603
int GetPrimHashCd() const
Definition: ds.h:2475
TVal & Last()
Returns a reference to the last element of the vector.
Definition: ds.h:581
TVec< TUInt64StrKd > TUInt64StrKdV
Definition: ds.h:1637
TSizeTy SearchVForw(const TVec< TVal, TSizeTy > &ValV, const TSizeTy &BValN=0) const
Returns the starting position of vector ValV.
Definition: ds.h:1566
TVec< TVal, TSizeTy > ValV
Definition: ds.h:2225
static void BSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Bubble sorts the values between positions BI...EI under the comparator Cmp.
Definition: ds.h:750
PVec< TVal > & operator=(const PVec< TVal > &Vec)
Definition: ds.h:2195
bool IsAsc
Definition: ds.h:119
const TVal & GetEmptyVal() const
Returns the reference to an empty value.
Definition: ds.h:1714
const TVal2 & GetVal2() const
Definition: ds.h:164
TTriple< TInt, TStr, TStr > TIntStrStrTr
Definition: ds.h:178
void Save(TSOut &SOut) const
Definition: ds.h:2582
TPair< TUInt64, TUInt64 > TUInt64Pr
Definition: ds.h:94
TVecPool< TInt > TIntVecPool
Definition: ds.h:2167
TVal4 Val4
Definition: ds.h:224
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5)
Returns a vector on elements Val1...Val5.
Definition: ds.h:860
void PutAll(const TVal &Val)
Sets the values of all elements in the pool to Val.
Definition: ds.h:1764
int Len() const
Definition: ds.h:2646
Compares the triple by the second value.
Definition: ds.h:194
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:579
TQQueue< TFlt > TFltQ
Definition: ds.h:2666
TPt< TAscFltVP > PAscFltV
Definition: ds.h:2215
static int GetHashCd(const int hc1, const int hc2)
Definition: bd.h:590
static PVecPool Load(TSIn &SIn)
Definition: ds.h:1698
TVal & At(const TSizeTy &X, const TSizeTy &Y, const TSizeTy &Z)
Definition: ds.h:2437
void Clr()
Definition: ds.h:2717
TLst< TStr > TStrL
Definition: ds.h:2888
TSizeTy MxVals
Vector capacity. Capacity is the size of allocated storage. If MxVals==-1, then ValT is not owned by ...
Definition: ds.h:434
bool operator==(const TVVec &Vec) const
Definition: ds.h:2241
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:71
Definition: ds.h:4
TVec< TCh > TChV
Definition: ds.h:1591
TTriple< TInt, TInt, TVec< TInt, int > > TIntIntIntVTr
Definition: ds.h:180
bool operator<(const TTuple &Tup) const
Definition: ds.h:291
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
TQuad< TFlt, TFlt, TFlt, TFlt > TFltQu
Definition: ds.h:264
TRec * Addr
Definition: ds.h:6
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:181
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:103
TQQueue(const TQQueue &Queue)
Definition: ds.h:2618
::TSize Reserved() const
Definition: ds.h:1967
TPair< TInt, TStr > TIntStrPr
Definition: ds.h:88
TVec< TStrIntKd > TStrIntKdV
Definition: ds.h:1652
const TVal & operator[](const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:503
int Len()
Definition: ds.h:2593
Definition: fl.h:569
TVal GetXY(const TSizeTy &X, const TSizeTy &Y) const
Definition: ds.h:2272
TAPt & operator=(TRec *_Addr)
Definition: ds.h:15
TTriple< TUInt64, TUInt64, TUInt64 > TUInt64Tr
Definition: ds.h:172
#define FailR(Reason)
Definition: bd.h:240
PVec< TFlt > TFltVP
Definition: ds.h:2212
TLstNd< TVal > * PLstNd
Definition: ds.h:2703
TSizeTy IntrsLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the intersection of vectors this and ValV. Assumes the vectors are sorted! ...
Definition: ds.h:1479
TFRec & operator=(const TFRec &)
TVal GetVal(const int &ValN) const
Definition: ds.h:2203
TVVec< TBool > TBoolVV
Definition: ds.h:2398
const TVal & Top() const
Definition: ds.h:2647
TPair< TInt, TCh > TIntChPr
Definition: ds.h:82
TPair< TIntPr, TInt > TIntPrIntPr
Definition: ds.h:90
TSizeTy GetRows() const
Definition: ds.h:2251
void PutHd(const THd &Hd)
Definition: ds.h:2909
Definition: ds.h:2609
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
Compares the triple by the third value.
Definition: ds.h:206
TVal & operator()(const TSizeTy &X, const TSizeTy &Y)
Definition: ds.h:2261
Definition: ds.h:2574
Definition: fl.h:128
TVec< TAscFltIntPr > TAscFltIntPrV
Definition: ds.h:1647
TVec< TFltUInt64Pr > TFltUInt64PrV
Definition: ds.h:1614
TPair< TBool, TFlt > TBoolFltPr
Definition: ds.h:77
int GetRecs()
Definition: fl.cpp:1045
PLstNd AddFrontSorted(const TVal &Val, const bool &Asc=true)
Definition: ds.h:2781
void GetRow(const TSizeTy &RowN, TVec< TVal, TSizeTy > &Vec) const
Definition: ds.h:2381
void Save(TSOut &SOut) const
Definition: ds.h:2421
TVal & GetNodeVal(const int &NodeId)
Definition: ds.h:2494
TKeyDat< TUInt, TInt > TUIntIntKd
Definition: ds.h:386
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1519
TTriple()
Definition: ds.h:136
TVal & GetAddDat(const TVal &Val)
Returns reference to the first occurrence of element Val.
Definition: ds.h:842
TSizeTy GetXDim() const
Definition: ds.h:2447
void SetVal(const TSizeTy &ValN, const TVal &Val)
Sets the value of element at position ValN to Val.
Definition: ds.h:653
int GetRecN()
Definition: fl.cpp:1038
TFunc()
Definition: ds.h:2921
void Save(const bool &Bool)
Definition: fl.h:173
static TPt< PVec< TVal > > Load(TSIn &SIn)
Definition: ds.h:2192
TPair< TStr, TStrV > TStrStrVPr
Definition: ds.h:108
TPair< TAscFlt, TAscFlt > TAscFltPr
Definition: ds.h:102
TVec< TIntStrIntIntQu > TIntStrIntIntQuV
Definition: ds.h:1663
TLstNd< TAscFltIntKd > * PAscFltIntKdLN
Definition: ds.h:2887
TPair< TUCh, TUInt64 > TUChUInt64Pr
Definition: ds.h:79
~TVecPool()
Definition: ds.h:1695
TTriple< TInt, TFlt, TFlt > TIntFltFltTr
Definition: ds.h:177
Definition: dt.h:1134
TQuad()
Definition: ds.h:226
TVal * TIter
Random access iterator to TVal.
Definition: ds.h:432
TVVec< TInt > TIntVV
Definition: ds.h:2400
PLstNd Last() const
Definition: ds.h:2725
int GetPrimHashCd() const
Definition: ds.h:156
TFuncPt operator()() const
Definition: ds.h:2933
static TPt< PVec< TVal > > New(const int &MxVals, const int &Vals)
Definition: ds.h:2186
TVec< TFltIntIntIntQu > TFltIntIntIntQuV
Definition: ds.h:1662
TVec< TUChIntPr > TUChIntPrV
Definition: ds.h:1607
TVec< TStrIntPr > TStrIntPrV
Definition: ds.h:1650
const TVal & operator[](const int &ValN) const
Definition: ds.h:2631
void ShuffleAll(TRnd &Rnd=TInt::Rnd)
Definition: ds.h:2158
TVec< TChA > TChAV
Definition: ds.h:1600
TPair< TAscFlt, TStr > TAscFltStrPr
Definition: ds.h:104
TLstNd< TStr > * PStrLN
Definition: ds.h:2889
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4)
Returns a vector on elements Val1...Val4.
Definition: ds.h:857
TVVec< TStr > TStrVV
Definition: ds.h:2403
TTriple< TInt, TVec< TInt, int >, TInt > TIntIntVIntTr
Definition: ds.h:179
TVec< TIntStrVPr > TIntStrVPrV
Definition: ds.h:1629
TQQueue< TIntStrPr > TIntStrPrQ
Definition: ds.h:2669
bool PrevPerm()
Generates previous permutation of the elements in the vector.
Definition: ds.h:1390
Definition: dt.h:201
TSizeTy Add(const TVal &Val)
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:608
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:75
Definition: ds.h:2409
TVal & GetVal(const TSizeTy &ValN)
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:651
int GetSecHashCd() const
Definition: ds.h:57
void ISort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Insertion sorts the values between positions MnLValN...MxLValN.
Definition: ds.h:1248
TKeyDat(const TKey &_Key, const TDat &_Dat)
Definition: ds.h:354
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
Definition: ds.h:1180
void LoadShM(TShMIn &ShMIn)
Constructs the vector from a shared memory input.
Definition: ds.h:932
int GetPrimHashCd() const
Definition: ds.h:365
TVec< TStr > TStrV
Definition: ds.h:1599
void Save(TSOut &SOut) const
Definition: ds.h:2467
void Push()
Definition: ds.h:2596
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6)
Returns a vector on elements Val1...Val6.
Definition: ds.h:863
void PutXY(const TSizeTy &X, const TSizeTy &Y, const TVal &Val)
Definition: ds.h:2266
TKeyDat< TFlt, TIntPr > TFltIntPrKd
Definition: ds.h:394
static TIter PartitionCmp(TIter BI, TIter EI, const TVal Pivot, const TCmp &Cmp)
Partitions the values between positions BI...EI under the comparator Cmp.
Definition: ds.h:743
static int GetRnd(const int &Range=0)
Definition: dt.h:1175
void Reserve(const TSize &MxVals)
Reserves enough capacity for the pool to store MxVals elements.
Definition: ds.h:1712
void DelFirst()
Definition: ds.h:2738
TLstNd< TIntKd > * PIntKdLN
Definition: ds.h:2881
TQuad(const TQuad &Quad)
Definition: ds.h:228
TKeyDat & operator=(const TKeyDat &KeyDat)
Definition: ds.h:360
Definition: ds.h:32
TKeyDat< TUInt64, TInt > TUInt64IntKd
Definition: ds.h:388
void GetRec(void *Rec, const int &RecN=-1)
Definition: fl.h:612
TVec< TFltBoolKd > TFltBoolKdV
Definition: ds.h:1638
void GetMxValXY(TSizeTy &X, TSizeTy &Y) const
Definition: ds.h:2325
TSizeTy LastValN() const
Returns the position of the last element.
Definition: ds.h:583
TVec< TUInt64StrPr > TUInt64StrPrV
Definition: ds.h:1634
PLstNd AddBack(const TVal &Val)
Definition: ds.h:2773
bool Empty() const
Definition: ds.h:2201
TVec< TIntStrPrPr > TIntStrPrPrV
Definition: ds.h:1628
void PutV(const int &VId, const TValV &ValV)
Definition: ds.h:1985
static PVecPool New(const ::TSize &ExpectVals=0, const ::TSize &GrowBy=1000000, const bool &FastCopy=false)
Definition: ds.h:1956
TKeyDat< TIntPr, TFlt > TIntPrFltKd
Definition: ds.h:382
TKeyDat< TStr, TBool > TStrBoolKd
Definition: ds.h:401
TStr GetStr() const
Definition: ds.h:306
TVec(const TSizeTy &_Vals)
Constructs a vector (an array) of length _Vals.
Definition: ds.h:446
bool Empty() const
Definition: ds.h:26
TKey Key
Definition: ds.h:348
TPt< TStrVP > PStrV
Definition: ds.h:2217
void GetSwitchedPrV(const TVec< TPair< TVal1, TVal2 >, TSizeTy > &SrcPrV, TVec< TPair< TVal2, TVal1 >, TSizeTy > &DstPrV)
Definition: ds.h:67
TTree< TInt > TIntTree
Definition: ds.h:2565
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7)
Returns a vector on elements Val1...Val7.
Definition: ds.h:866
void Load(TSIn &SIn)
Definition: ds.h:43
TVec< TUInt64 > TUInt64V
Definition: ds.h:1595
TVec< TFlt > TFltV
Definition: ds.h:1596
void DelY(const TSizeTy &Y)
Definition: ds.h:2369
int AddRoot(const TVal &NodeVal=TVal())
Definition: ds.h:2486
PFRnd FRnd
Definition: ds.h:2896
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:2462
int GetPrimHashCd() const
Definition: ds.h:56
TVal & operator[](const TSizeTy &ValN)
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:507
TSizeTy UnionLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the union of vectors this and ValV. Assumes the vectors are sorted! ...
Definition: ds.h:1493
void Del(const TVal &Val)
Definition: ds.h:2841
TVVec< TSFlt > TSFltVV
Definition: ds.h:2401
TLst()
Definition: ds.h:2709
void LoadShM(TShMIn &ShMIn, TLoadShMElem LoadFromShMFn)
Constructs vector from shared memory input passing in functor to initialize elements.
Definition: ds.h:472
TVec< TIntQu > TIntQuV
Definition: ds.h:1603
void Union(const TVec< TVal, TSizeTy > &ValV)
Sets this vector to its union with ValV. Assumes the vectors are sorted!
Definition: ds.h:1418
void Pop()
Definition: ds.h:2598
TLstNd(TLstNd *_PrevNd, TLstNd *_NextNd, const TVal &_Val)
Definition: ds.h:2685
TKeyDat< TUInt, TUInt > TUIntKd
Definition: ds.h:387
TVec< TUChUInt64Pr > TUChUInt64PrV
Definition: ds.h:1608
const TVal1 & GetVal1() const
Definition: ds.h:255
TSizeTy GetYDim() const
Definition: ds.h:2448
Definition: dt.h:412
Definition: ds.h:219
void PutBack(const PLstNd &Nd)
Definition: ds.h:2816
TSizeTy Partition(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Partitions the values between positions MnLValN...MxLValN.
Definition: ds.h:1286
TSStack< TBoolChPr > TBoolChS
Definition: ds.h:2604
TTriple< TStr, TStr, TStr > TStrTr
Definition: ds.h:186
TKeyDat(const TKeyDat &KeyDat)
Definition: ds.h:352
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Definition: ds.h:593
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TQuad & operator=(const TQuad &Quad)
Definition: ds.h:239
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
Definition: ds.h:1323
void Pack()
Reduces vector capacity (frees memory) to match its size.
Definition: ds.h:1057
TVVVec(TSIn &SIn)
Definition: ds.h:2419
TCRef CRef
Definition: ds.h:1677
bool IsPrev() const
Definition: ds.h:2690
bool operator<(const TAPt &Pt) const
Definition: ds.h:18
TQQueue(const int &_MxLast=64, const int &_MxLen=-1)
Definition: ds.h:2615
TSizeTy GetXDim() const
Definition: ds.h:2249
TVec< TVal, TSizeTy > ValV
Definition: ds.h:2412
TVec< TFltStrPrPr > TFltStrPrPrV
Definition: ds.h:1644
TAPt & operator=(const TAPt &Pt)
Definition: ds.h:14
void Save(TSOut &SOut) const
Definition: ds.h:2236
int Add(const TVal &Val)
Definition: ds.h:2205
TVec< TVal, TSizeTy > & operator+(const TVal &Val)
Appends value Val to the vector.
Definition: ds.h:495
int GetVecs() const
Returns the total number of vectors stored in the vector pool.
Definition: ds.h:1704
TPair< TInt, TStrPr > TIntStrPrPr
Definition: ds.h:111
int Len() const
Definition: ds.h:283
static void QSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Quick sorts the values between positions BI...EI under the comparator Cmp.
Definition: ds.h:762
TCmpPairByVal2(const bool &AscSort=true)
Definition: ds.h:121
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
Definition: ds.h:1335
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
Definition: ds.h:1552
static PVecPool Load(const TStr &FNm)
Definition: ds.h:1699
void GetCol(const TSizeTy &ColN, TVec< TVal, TSizeTy > &Vec) const
Definition: ds.h:2389
TPair< TStr, TInt > TStrIntPr
Definition: ds.h:105
TQQueue< TStr > TStrQ
Definition: ds.h:2667
void ShuffleAll(TRnd &Rnd=TInt::Rnd)
Shuffles the order of all elements in the pool.
Definition: ds.h:1918
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TBool FastCopy
Definition: ds.h:1678
bool IsShM
Definition: ds.h:437
TKeyDat< TFlt, TUInt > TFltUIntKd
Definition: ds.h:395
TTuple(const TVal &InitVal)
Definition: ds.h:277
TVecPool(const ::TSize &ExpectVals=0, const ::TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
Definition: ds.h:2037
TKeyDat< TInt, TInt > TIntKd
Definition: ds.h:379
bool IsIn(const TVal &Val, TSizeTy &ValN) const
Checks whether element Val is a member of the vector.
Definition: ds.h:832
TTriple< TCh, TInt, TInt > TChIntIntTr
Definition: ds.h:169
void GetV(const int &VId, TValV &ValV) const
Definition: ds.h:1982
TVal * ValBf
Definition: ds.h:1947
TVec< uint64, int > IdToOffV
Definition: ds.h:1682
TSStack & operator=(const TSStack &Stack)
Definition: ds.h:2584
TVecPool(const TSize &ExpectVals=0, const TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
Vector pool constructor.
Definition: ds.h:1798
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2)
Returns a vector on elements Val1, Val2.
Definition: ds.h:851
TVal1 Val1
Definition: ds.h:34
TVec< TInt > TIntV
Definition: ds.h:1594
TVal2 Val2
Definition: ds.h:35
TKeyDat< TInt, TSFlt > TIntSFltKd
Definition: ds.h:384
TAPt(const TAPt &Pt)
Definition: ds.h:9
TVal ValV[NVals]
Definition: ds.h:274
Definition: bd.h:196
TKeyDat(TSIn &SIn)
Definition: ds.h:355
void Push(const TVal &Val)
Definition: ds.h:2652
TInt64 XDim
Definition: ds.h:2224
void Sort(const bool &Asc=true)
Definition: ds.h:312
TCmpKeyDatByDat(const bool &AscSort=true)
Definition: ds.h:414
void Reverse()
Reverses the order of the elements in the vector.
Definition: ds.h:1350
bool operator<(const TPair &Pair) const
Definition: ds.h:51
void SwapY(const TSizeTy &Y1, const TSizeTy &Y2)
Definition: ds.h:2300
#define AssertR(Cond, Reason)
Definition: bd.h:258
TQuad< TInt, TStr, TInt, TInt > TIntStrIntIntQu
Definition: ds.h:266
void GenRandomTree(const int &Nodes, TRnd &Rnd)
Definition: ds.h:2518
TSizeTy AddMerged(const TVal &Val)
Adds element Val to a sorted vector only if the element Val is not already in the vector...
Definition: ds.h:1145
int GetChildren(const int &NodeId) const
Definition: ds.h:2492
TInt MxLast
Definition: ds.h:2611
TVec()
Definition: ds.h:443
TTriple< TInt, TInt, TInt > TIntTr
Definition: ds.h:171
TSizeTy AddBackSorted(const TVal &Val, const bool &Asc)
Adds element Val to a sorted vector.
Definition: ds.h:1133
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
TVal & GetVal()
Definition: ds.h:2694
TRec & operator[](const int &RecN) const
Definition: ds.h:22
TPair< TFlt, TStr > TFltStrPr
Definition: ds.h:100
void SetRecN(const int &RecN)
Definition: fl.cpp:1033
Definition: ds.h:2917
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
TVVec(const TVVec &Vec)
Definition: ds.h:2228
TSizeTy Count(const TVal &Val) const
Counts the number of occurrences of Val in the vector.
Definition: ds.h:1511
bool operator==(const TVec< TVal, TSizeTy > &Vec) const
Checks that the two vectors have the same contents.
Definition: ds.h:972
TQQueue< TFltV > TFltVQ
Definition: ds.h:2670
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
Definition: ds.h:543
void MoveFrom(TVec< TVal, TSizeTy > &Vec)
Takes over the data and the capacity from Vec.
Definition: ds.h:1073
bool operator==(const TTriple &Triple) const
Definition: ds.h:150
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
Definition: bd.h:426
void SaveXml(TSOut &SOut, const TStr &Nm) const
TLst< TIntKd > TIntKdL
Definition: ds.h:2880
TVec(const TSizeTy &_MxVals, const TSizeTy &_Vals)
Constructs a vector (an array) of length _Vals, while reserving enough memory to store _MxVals elemen...
Definition: ds.h:451
TVec< TIntFltIntTr > TIntFltIntTrV
Definition: ds.h:1620
static TPt< PVec< TVal > > New()
Definition: ds.h:2183
Definition: ds.h:2894
TTuple()
Definition: ds.h:276
void Clr(const bool &DoDel=true)
Definition: ds.h:2634
TLst< TFltIntKd > TFltIntKdL
Definition: ds.h:2884
TFunc & operator=(const TFunc &Func)
Definition: ds.h:2927
TVVec< TIntPr > TIntPrVV
Definition: ds.h:2404
void Resize(const TSizeTy &_MxVals=-1)
Resizes the vector so that it can store at least _MxVals.
Definition: ds.h:877
int GetMemUsed() const
Definition: ds.h:2478
static TVec< TVal, TSizeTy > GetV(const TVal &Val1)
Returns a vector on element Val1.
Definition: ds.h:848
TRec & operator*() const
Definition: ds.h:21
TVec< TUInt64FltPr > TUInt64FltPrV
Definition: ds.h:1633
TVec< TBool > TBoolV
Definition: ds.h:1590
static TPt< PVec< TVal > > New(const TVec< TVal > &V)
Definition: ds.h:2189
TKeyDat< TFlt, TInt > TFltIntKd
Definition: ds.h:392
void SortCmp(const TCmp &Cmp)
Sorts the elements of the vector using the comparator Cmp.
Definition: ds.h:770
TPair< TFlt, TUInt64 > TFltUInt64Pr
Definition: ds.h:98
char * CStr()
Definition: dt.h:476
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:79
bool operator<(const TQuad &Quad) const
Definition: ds.h:245
void Gen(const TSizeTy &_MxVals, const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements, while reserving enough memory for _MxVals elements...
Definition: ds.h:527
Definition: ds.h:2460
void GetVal(TVal1 &_Val1, TVal2 &_Val2, TVal3 &_Val3) const
Definition: ds.h:160
void BSort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Bubble sorts the values between positions MnLValN...MxLValN.
Definition: ds.h:1235
TKeyDat< TInt, TUInt64 > TIntUInt64Kd
Definition: ds.h:380
TSizeTy Vals
Vector length. Length is the number of elements stored in the vector.
Definition: ds.h:435
TVec(TSIn &SIn)
Definition: ds.h:462
TVec< TFltIntPr > TFltIntPrV
Definition: ds.h:1613
TVVec< TVal, TSizeTy > & operator=(const TVVec< TVal, TSizeTy > &Vec)
Definition: ds.h:2239
bool IsVId(const int &VId) const
Tests whether vector of id VId is in the pool.
Definition: ds.h:1708
void Clr()
Definition: ds.h:2480
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TTuple(const TTuple &Tup)
Definition: ds.h:278
TSizeTy GetMemSize() const
Returns the memory size (the number of bytes) of a binary representation.
Definition: ds.h:514
TPt< TIntVecPool > PIntVecPool
Definition: ds.h:2170
void CompactPool(const TVal &DelVal)
Definition: ds.h:2129
TLstNd< TInt > * PIntLN
Definition: ds.h:2879
TVVVec< TInt > TIntVVV
Definition: ds.h:2454
Definition: dt.h:971
#define MAX(a, b)
Definition: bd.h:350
TVec< TFltKd > TFltKdV
Definition: ds.h:1642
void DelLast()
Removes the last element of the vector.
Definition: ds.h:665
bool IsAsc
Definition: ds.h:412
TTree(const TTree &Tree)
Definition: ds.h:2465
PLstNd SearchForw(const TVal &Val)
Definition: ds.h:2857
TTriple< TInt, TInt, TStr > TIntIntStrTr
Definition: ds.h:174
void Trunc(const TSizeTy &_Vals=-1)
Truncates the vector's length and capacity to _Vals elements.
Definition: ds.h:1033
static void SwapI(TIter LVal, TIter RVal)
Swaps the elements that iterators LVal and RVal point to.
Definition: ds.h:677
bool IsAsc
Definition: ds.h:196
TVec< TIntFltKd > TIntFltKdV
Definition: ds.h:1625
TPair & operator=(const TPair &Pair)
Definition: ds.h:47
TKeyDat< TStr, TAscFlt > TStrAscFltKd
Definition: ds.h:404
TVec< TQQueue< TInt > > TIntQV
Definition: ds.h:2672
TBool FastCopy
Definition: ds.h:1944
bool operator<(const TTree &Tree) const
Definition: ds.h:2473
TFAccess
Definition: fl.h:347
TVec< TIntStrStrTr > TIntStrStrTrV
Definition: ds.h:1622
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
Definition: ds.h:597
TSizeTy GetCols() const
Definition: ds.h:2252
TVal * GetValVPt(const int &VId) const
Definition: ds.h:1979
TVVVec()
Definition: ds.h:2414
TVVec(TSIn &SIn)
Definition: ds.h:2234
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7, const TVal &Val8, const TVal &Val9)
Returns a vector on elements Val1...Val9.
Definition: ds.h:872
TPair< TUCh, TInt > TUChIntPr
Definition: ds.h:78
TLstNd * PrevNd
Definition: ds.h:2679
void CopyFrom(const TVVec< TVal, TSizeTy > &VVec)
Definition: ds.h:2332
TLst< TAscFltIntKd > TAscFltIntKdL
Definition: ds.h:2886
TPair< TUInt64, TInt > TUInt64IntPr
Definition: ds.h:93
TSize Vals
Definition: ds.h:1679
TSize MxVals
Definition: ds.h:1679
void GetRec(TRec &Rec, const int &RecN=-1)
Definition: ds.h:2910
TQuad(TSIn &SIn)
Definition: ds.h:232
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim, const TSizeTy &_ZDim)
Definition: ds.h:2434
int GetPrimHashCd() const
Definition: ds.h:298
TVec< TIntStrIntTr > TIntStrIntTrV
Definition: ds.h:1621
TLstNd< TFltIntKd > * PFltIntKdLN
Definition: ds.h:2885
void GetSubValV(const int &_BValN, const int &_EValN, TVec< TVal > &SubValV) const
Definition: ds.h:2637
TStr GetXOutOfBoundsErrMsg(const TSizeTy &ValN) const
Constructs the out of bounds error message.
Definition: ds.h:913
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim)
Definition: ds.h:2246
TSizeTy SearchBack(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1559
TKeyDat< TFlt, TUInt64 > TFltUInt64Kd
Definition: ds.h:393
::TSize GetMemUsed() const
Definition: ds.h:1971
TVVec()
Definition: ds.h:2227
TVal * ValT
Pointer to the memory where the elements of the vector are stored.
Definition: ds.h:436
TLst< TInt > TIntL
Definition: ds.h:2878
void Reserve(const TSizeTy &_MxVals, const TSizeTy &_Vals)
Reserves enough memory for the vector to store _MxVals elements and sets its length to _Vals...
Definition: ds.h:545
void PutY(const TSizeTy &Y, const TVal &Val)
Definition: ds.h:2270
TTriple< TFlt, TInt, TInt > TFltIntIntTr
Definition: ds.h:182
TQuad(const TVal1 &_Val1, const TVal2 &_Val2, const TVal3 &_Val3, const TVal4 &_Val4)
Definition: ds.h:230
bool operator!=(const TAPt &Pt) const
Definition: ds.h:17
bool IsIn(const TVal &Val) const
Definition: ds.h:2592
TVec< TIntStrPr > TIntStrPrV
Definition: ds.h:1617
TVal3 Val3
Definition: ds.h:134
bool operator==(const TVVVec &Vec) const
Definition: ds.h:2428
PLstNd First() const
Definition: ds.h:2724
TPair< TVec< TInt, int >, TVec< TFlt, int > > TIntVFltVPr
Definition: ds.h:113
Compares the pair by the second value.
Definition: ds.h:117
TVec< TIntUInt64Kd > TIntUInt64KdV
Definition: ds.h:1610
void Save(TSOut &SOut) const
Definition: ds.h:280
TSizeTy GetMxValN() const
Returns the position of the largest element in the vector.
Definition: ds.h:1579
TVec< TUCh > TUChV
Definition: ds.h:1592
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568
TKeyDat< TStr, TStr > TStrKd
Definition: ds.h:405
TTriple & operator=(const TTriple &Triple)
Definition: ds.h:147
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430
const TVal4 & GetVal4() const
Definition: ds.h:258
TInt64 YDim
Definition: ds.h:2224
TTriple< TUCh, TInt, TInt > TUChIntIntTr
Definition: ds.h:170
int AddEmptyV(const int &ValVLen)
Definition: ds.h:2119
TVec< TFltStrKd > TFltStrKdV
Definition: ds.h:1643
const TVal3 & GetVal3() const
Definition: ds.h:165
int GetMemUsed() const
Definition: ds.h:158
TPair< TUInt64, TStr > TUInt64StrPr
Definition: ds.h:96
void WrTree(const int &NodeId=0, const int &Lev=0)
Definition: ds.h:2552
TTriple< TStr, TFlt, TFlt > TStrFltFltTr
Definition: ds.h:188
TTriple< TChA, TChA, TChA > TChATr
Definition: ds.h:185
bool Empty() const
Definition: ds.h:2244
TVec< TVal > ValV
Definition: ds.h:2576
TSizeTy AddV(const TVec< TVal, TSizeTy > &ValV)
Adds the elements of the vector ValV to the to end of the vector.
Definition: ds.h:1110
void GetSubValV(const TSizeTy &BValN, const TSizeTy &EValN, TVec< TVal, TSizeTy > &ValV) const
Fills ValV with elements at positions BValN...EValN.
Definition: ds.h:1170
bool operator<(const TTriple &Triple) const
Definition: ds.h:152
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
Definition: ds.h:2255
TLstNd * Next() const
Definition: ds.h:2693
TVal & operator()(const TSizeTy &X, const TSizeTy &Y, const TSizeTy &Z)
Definition: ds.h:2443
static void ISortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Insertion sorts the values between positions BI...EI under the comparator Cmp.
Definition: ds.h:756
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7, const TVal &Val8)
Returns a vector on elements Val1...Val8.
Definition: ds.h:869