SNAP Library 2.3, Developer Reference  2014-06-16 11:58:46
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 
113 
115 template <class TVal1, class TVal2>
117 private:
118  bool IsAsc;
119 public:
120  TCmpPairByVal2(const bool& AscSort=true) : IsAsc(AscSort) { }
121  bool operator () (const TPair<TVal1, TVal2>& P1, const TPair<TVal1, TVal2>& P2) const {
122  if (IsAsc) { return P1.Val2 < P2.Val2; } else { return P2.Val2 < P1.Val2; }
123  }
124 };
125 
127 // Triple
128 template <class TVal1, class TVal2, class TVal3>
129 class TTriple{
130 public:
131  TVal1 Val1;
132  TVal2 Val2;
133  TVal3 Val3;
134 public:
135  TTriple(): Val1(), Val2(), Val3(){}
136  TTriple(const TTriple& Triple):
137  Val1(Triple.Val1), Val2(Triple.Val2), Val3(Triple.Val3){}
138  TTriple(const TVal1& _Val1, const TVal2& _Val2, const TVal3& _Val3):
139  Val1(_Val1), Val2(_Val2), Val3(_Val3){}
140  explicit TTriple(TSIn& SIn): Val1(SIn), Val2(SIn), Val3(SIn){}
141  void Save(TSOut& SOut) const {
142  Val1.Save(SOut); Val2.Save(SOut); Val3.Save(SOut);}
143  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
144  void SaveXml(TSOut& SOut, const TStr& Nm) const;
145 
146  TTriple& operator=(const TTriple& Triple){
147  if (this!=&Triple){Val1=Triple.Val1; Val2=Triple.Val2; Val3=Triple.Val3;}
148  return *this;}
149  bool operator==(const TTriple& Triple) const {
150  return (Val1==Triple.Val1)&&(Val2==Triple.Val2)&&(Val3==Triple.Val3);}
151  bool operator<(const TTriple& Triple) const {
152  return (Val1<Triple.Val1)||((Val1==Triple.Val1)&&(Val2<Triple.Val2))||
153  ((Val1==Triple.Val1)&&(Val2==Triple.Val2)&&(Val3<Triple.Val3));}
154 
155  int GetPrimHashCd() const {return TPairHashImpl::GetHashCd(TPairHashImpl::GetHashCd(Val1.GetPrimHashCd(), Val2.GetPrimHashCd()), Val3.GetPrimHashCd()); }
156  int GetSecHashCd() const {return TPairHashImpl::GetHashCd(TPairHashImpl::GetHashCd(Val2.GetSecHashCd(), Val3.GetSecHashCd()), Val1.GetSecHashCd()); }
157  int GetMemUsed() const {return Val1.GetMemUsed()+Val2.GetMemUsed()+Val3.GetMemUsed();}
158 
159  void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3) const {
160  _Val1=Val1; _Val2=Val2; _Val3=Val3;}
161 };
162 
185 
187 template <class TVal1, class TVal2, class TVal3>
189 private:
190  bool IsAsc;
191 public:
192  TCmpTripleByVal2(const bool& AscSort=true) : IsAsc(AscSort) { }
194  if (IsAsc) { return T1.Val2 < T2.Val2; } else { return T2.Val2 < T1.Val2; }
195  }
196 };
197 
199 template <class TVal1, class TVal2, class TVal3>
201 private:
202  bool IsAsc;
203 public:
204  TCmpTripleByVal3(const bool& AscSort=true) : IsAsc(AscSort) { }
206  if (IsAsc) { return T1.Val3 < T2.Val3; } else { return T2.Val3 < T1.Val3; }
207  }
208 };
209 
211 // Quad
212 template <class TVal1, class TVal2, class TVal3, class TVal4>
213 class TQuad{
214 public:
215  TVal1 Val1;
216  TVal2 Val2;
217  TVal3 Val3;
218  TVal4 Val4;
219 public:
220  TQuad():
221  Val1(), Val2(), Val3(), Val4(){}
222  TQuad(const TQuad& Quad):
223  Val1(Quad.Val1), Val2(Quad.Val2), Val3(Quad.Val3), Val4(Quad.Val4){}
224  TQuad(const TVal1& _Val1, const TVal2& _Val2, const TVal3& _Val3, const TVal4& _Val4):
225  Val1(_Val1), Val2(_Val2), Val3(_Val3), Val4(_Val4){}
226  explicit TQuad(TSIn& SIn):
227  Val1(SIn), Val2(SIn), Val3(SIn), Val4(SIn){}
228  void Save(TSOut& SOut) const {
229  Val1.Save(SOut); Val2.Save(SOut); Val3.Save(SOut); Val4.Save(SOut);}
230  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
231  void SaveXml(TSOut& SOut, const TStr& Nm) const;
232 
233  TQuad& operator=(const TQuad& Quad){
234  if (this!=&Quad){
235  Val1=Quad.Val1; Val2=Quad.Val2; Val3=Quad.Val3; Val4=Quad.Val4;}
236  return *this;}
237  bool operator==(const TQuad& Quad) const {
238  return (Val1==Quad.Val1)&&(Val2==Quad.Val2)&&(Val3==Quad.Val3)&&(Val4==Quad.Val4);}
239  bool operator<(const TQuad& Quad) const {
240  return (Val1<Quad.Val1)||((Val1==Quad.Val1)&&(Val2<Quad.Val2))||
241  ((Val1==Quad.Val1)&&(Val2==Quad.Val2)&&(Val3<Quad.Val3))||
242  ((Val1==Quad.Val1)&&(Val2==Quad.Val2)&&(Val3==Quad.Val3)&&(Val4<Quad.Val4));}
243 
244  int GetPrimHashCd() const {return TPairHashImpl::GetHashCd(TPairHashImpl::GetHashCd(Val1.GetPrimHashCd(), Val2.GetPrimHashCd()), TPairHashImpl::GetHashCd(Val3.GetPrimHashCd(), Val4.GetPrimHashCd())); }
245  int GetSecHashCd() const {return TPairHashImpl::GetHashCd(TPairHashImpl::GetHashCd(Val2.GetSecHashCd(), Val3.GetSecHashCd()), TPairHashImpl::GetHashCd(Val4.GetSecHashCd(), Val1.GetSecHashCd())); }
246 
247  void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3, TVal4& _Val4) const {
248  _Val1=Val1; _Val2=Val2; _Val3=Val3; _Val4=Val4;}
249 };
250 
258 
260 // Tuple
261 template<class TVal, int NVals>
262 class TTuple {
263 private:
264  TVal ValV [NVals];
265 public:
266  TTuple(){}
267  TTuple(const TVal& InitVal) { for (int i=0; i<Len(); i++) ValV[i]=InitVal; }
268  TTuple(const TTuple& Tup) { for (int i=0; i<Len(); i++) ValV[i]=Tup[i]; }
269  TTuple(TSIn& SIn) { for (int i=0; i<Len(); i++) ValV[i].Load(SIn); }
270  void Save(TSOut& SOut) const { for (int i=0; i<Len(); i++) ValV[i].Save(SOut); }
271  void Load(TSIn& SIn) { for (int i=0; i<Len(); i++) ValV[i].Load(SIn); }
272 
273  int Len() const { return NVals; }
274  TVal& operator[] (const int& ValN) { return ValV[ValN]; }
275  const TVal& operator[] (const int& ValN) const { return ValV[ValN]; }
276  TTuple& operator = (const TTuple& Tup) { if (this != & Tup) {
277  for (int i=0; i<Len(); i++) ValV[i]=Tup[i]; } return *this; }
278  bool operator == (const TTuple& Tup) const {
279  if (Len()!=Tup.Len()) { return false; } if (&Tup==this) { return true; }
280  for (int i=0; i<Len(); i++) if(ValV[i]!=Tup[i]){return false;} return true; }
281  bool operator < (const TTuple& Tup) const {
282  if (Len() == Tup.Len()) { for (int i=0; i<Len(); i++) {
283  if(ValV[i]<Tup[i]){return true;} else if(ValV[i]>Tup[i]){return false;} } return false; }
284  else { return Len() < Tup.Len(); } }
285  void Sort(const bool& Asc=true);
286  int FindMx() const;
287  int FindMn() const;
288  int GetPrimHashCd() const { int hc = 0;
289  for (int i = 0; i < NVals; i++) { hc = TPairHashImpl::GetHashCd(hc, ValV[i].GetPrimHashCd()); }
290  return hc; }
291  int GetSecHashCd() const { int hc = 0;
292  for (int i = 1; i < NVals; i++) { hc = TPairHashImpl::GetHashCd(hc, ValV[i].GetSecHashCd()); }
293  if (NVals > 0) { hc = TPairHashImpl::GetHashCd(hc, ValV[0].GetSecHashCd()); }
294  return hc; }
295 
296  TStr GetStr() const { TChA ValsStr;
297  for (int i=0; i<Len(); i++) { ValsStr+=" "+ValV[i].GetStr(); }
298  return TStr::Fmt("Tuple(%d):", Len())+ValsStr; }
299 };
300 
301 template<class TVal, int NVals>
302 void TTuple<TVal, NVals>::Sort(const bool& Asc) {
303  TVec<TVal, int> V(NVals);
304  for (int i=0; i<NVals; i++) { V.Add(ValV[i]); }
305  V.Sort(Asc);
306  for (int i=0; i<NVals; i++) { ValV[i] = V[i]; }
307 }
308 
309 template<class TVal, int NVals>
311  TVal MxVal = ValV[0];
312  int ValN = 0;
313  for (int i = 1; i < NVals; i++) {
314  if (MxVal<ValV[i]) {
315  MxVal=ValV[i]; ValN=i;
316  }
317  }
318  return ValN;
319 }
320 
321 template<class TVal, int NVals>
323  TVal MnVal = ValV[0];
324  int ValN = 0;
325  for (int i = 1; i < NVals; i++) {
326  if (MnVal>ValV[i]) {
327  MnVal=ValV[i]; ValN=i;
328  }
329  }
330  return ValN;
331 }
332 
334 // Key-Data
335 template <class TKey, class TDat>
336 class TKeyDat{
337 public:
338  TKey Key;
339  TDat Dat;
340 public:
341  TKeyDat(): Key(), Dat(){}
342  TKeyDat(const TKeyDat& KeyDat): Key(KeyDat.Key), Dat(KeyDat.Dat){}
343  explicit TKeyDat(const TKey& _Key): Key(_Key), Dat(){}
344  TKeyDat(const TKey& _Key, const TDat& _Dat): Key(_Key), Dat(_Dat){}
345  explicit TKeyDat(TSIn& SIn): Key(SIn), Dat(SIn){}
346  void Save(TSOut& SOut) const {Key.Save(SOut); Dat.Save(SOut);}
347  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
348  void SaveXml(TSOut& SOut, const TStr& Nm) const;
349 
350  TKeyDat& operator=(const TKeyDat& KeyDat){
351  if (this!=&KeyDat){Key=KeyDat.Key; Dat=KeyDat.Dat;} return *this;}
352  bool operator==(const TKeyDat& KeyDat) const {return Key==KeyDat.Key;}
353  bool operator<(const TKeyDat& KeyDat) const {return Key<KeyDat.Key;}
354 
355  int GetPrimHashCd() const {return Key.GetPrimHashCd();}
356  int GetSecHashCd() const {return Key.GetSecHashCd();}
357 };
358 
359 template <class TKey, class TDat>
360 void GetSwitchedKdV(const TVec<TKeyDat<TKey, TDat>, int>& SrcKdV, TVec<TKeyDat<TDat, TKey>, int>& DstKdV){
361  const int Kds=SrcKdV.Len();
362  DstKdV.Gen(Kds, 0);
363  for (int KdN=0; KdN<Kds; KdN++){
364  const TKeyDat<TKey, TDat>& SrcKd=SrcKdV[KdN];
365  DstKdV.Add(TKeyDat<TDat, TKey>(SrcKd.Dat, SrcKd.Key));
366  }
367 }
368 
396 
397 // Key-Data comparator
398 
399 template <class TVal1, class TVal2>
401 private:
402  bool IsAsc;
403 public:
404  TCmpKeyDatByDat(const bool& AscSort=true) : IsAsc(AscSort) { }
405  bool operator () (const TKeyDat<TVal1, TVal2>& P1, const TKeyDat<TVal1, TVal2>& P2) const {
406  if (IsAsc) { return P1.Dat < P2.Dat; } else { return P2.Dat < P1.Dat; }
407  }
408 };
409 
410 //#//////////////////////////////////////////////
412 
419 template <class TVal, class TSizeTy = int>
420 class TVec{
421 public:
422  typedef TVal* TIter;
423 protected:
424  TSizeTy MxVals;
425  TSizeTy Vals;
426  TVal* ValT;
427  void Resize(const TSizeTy& _MxVals=-1);
430  TStr GetXOutOfBoundsErrMsg(const TSizeTy& ValN) const;
431 public:
432  TVec(): MxVals(0), Vals(0), ValT(NULL){}
433  TVec(const TVec<TVal, TSizeTy>& Vec);
435  explicit TVec(const TSizeTy& _Vals){
436  IAssert(0<=_Vals); MxVals=Vals=_Vals;
437  if (_Vals==0){ValT=NULL;} else {ValT=new TVal[_Vals];}}
439  TVec(const TSizeTy& _MxVals, const TSizeTy& _Vals){
440  IAssert((0<=_Vals)&&(_Vals<=_MxVals)); MxVals=_MxVals; Vals=_Vals;
441  if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
443 
446  explicit TVec(TVal *_ValT, const TSizeTy& _Vals):
447  MxVals(-1), Vals(_Vals), ValT(_ValT){}
448  ~TVec(){if ((ValT!=NULL) && (MxVals!=-1)){delete[] ValT;}}
449  explicit TVec(TSIn& SIn): MxVals(0), Vals(0), ValT(NULL){Load(SIn);}
450  void Load(TSIn& SIn);
451  void Save(TSOut& SOut) const;
452  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
453  void SaveXml(TSOut& SOut, const TStr& Nm) const;
454 
458  TVec<TVal, TSizeTy>& operator+(const TVal& Val){Add(Val); return *this;}
460  bool operator==(const TVec<TVal, TSizeTy>& Vec) const;
462 
464  bool operator<(const TVec<TVal, TSizeTy>& Vec) const;
466  const TVal& operator[](const TSizeTy& ValN) const {
467  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
468  return ValT[ValN];}
470  TVal& operator[](const TSizeTy& ValN){
471  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
472  return ValT[ValN];}
474  TSizeTy GetMemUsed() const {
475  return TSizeTy(2*sizeof(TSizeTy)+sizeof(TVal*)+MxVals*sizeof(TVal));}
477  TSizeTy GetMemSize() const {
478  return TSizeTy(2*sizeof(TVal)+sizeof(TSizeTy)*Vals);}
479 
481  int GetPrimHashCd() const;
483  int GetSecHashCd() const;
484 
486  void Gen(const TSizeTy& _Vals){ IAssert(0<=_Vals);
487  if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=Vals=_Vals;
488  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}}
490  void Gen(const TSizeTy& _MxVals, const TSizeTy& _Vals){ IAssert((0<=_Vals)&&(_Vals<=_MxVals));
491  if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=_MxVals; Vals=_Vals;
492  if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
494 
497  void GenExt(TVal *_ValT, const TSizeTy& _Vals){
498  if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
499  MxVals=-1; Vals=_Vals; ValT=_ValT;}
501 
504  bool IsExt() const {return MxVals==-1;}
506  void Reserve(const TSizeTy& _MxVals){Resize(_MxVals);}
508  void Reserve(const TSizeTy& _MxVals, const TSizeTy& _Vals){ IAssert((0<=_Vals)&&(_Vals<=_MxVals)); Resize(_MxVals); Vals=_Vals;}
510 
513  void Clr(const bool& DoDel=true, const TSizeTy& NoDelLim=-1);
515 
517  void Trunc(const TSizeTy& _Vals=-1);
519  void Pack();
521 
523  void MoveFrom(TVec<TVal, TSizeTy>& Vec);
525  void Swap(TVec<TVal, TSizeTy>& Vec);
526 
528 
530  bool Empty() const {return Vals==0;}
532 
535  TSizeTy Len() const {return Vals;}
537  TSizeTy Reserved() const {return MxVals;}
539  const TVal& Last() const {return GetVal(Len()-1);}
541  TVal& Last(){return GetVal(Len()-1);}
543  TSizeTy LastValN() const {return Len()-1;}
545  const TVal& LastLast() const { AssertR(1<Vals, GetXOutOfBoundsErrMsg(Vals-2)); return ValT[Vals-2];}
547  TVal& LastLast(){ AssertR(1<Vals, GetXOutOfBoundsErrMsg(Vals-2)); return ValT[Vals-2];}
548 
550  TIter BegI() const {return ValT;}
552  TIter EndI() const {return ValT+Vals;}
554  TIter GetI(const TSizeTy& ValN) const {return ValT+ValN;}
555 
557 
559  TSizeTy Add(){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
560  if (Vals==MxVals){Resize();} return Vals++;}
562 
564  TSizeTy Add(const TVal& Val){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
565  if (Vals==MxVals){Resize();} ValT[Vals]=Val; return Vals++;}
566  TSizeTy Add(TVal& Val){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
567  if (Vals==MxVals){Resize();} ValT[Vals]=Val; return Vals++;}
569  TSizeTy Add(const TVal& Val, const TSizeTy& ResizeLen){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
570  if (Vals==MxVals){Resize(MxVals+ResizeLen);} ValT[Vals]=Val; return Vals++;}
572  TSizeTy AddV(const TVec<TVal, TSizeTy>& ValV);
574 
576  TSizeTy AddSorted(const TVal& Val, const bool& Asc=true, const TSizeTy& _MxVals=-1);
578 
580  TSizeTy AddBackSorted(const TVal& Val, const bool& Asc);
582 
584  TSizeTy AddMerged(const TVal& Val);
586 
588  TSizeTy AddVMerged(const TVec<TVal, TSizeTy>& ValV);
590 
593  TSizeTy AddUnique(const TVal& Val);
595  const TVal& GetVal(const TSizeTy& ValN) const {return operator[](ValN);}
597  TVal& GetVal(const TSizeTy& ValN){return operator[](ValN);}
599  void SetVal(const TSizeTy& ValN, const TVal& Val){AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN)); ValT[ValN] = Val;}
601  void GetSubValV(const TSizeTy& BValN, const TSizeTy& EValN, TVec<TVal, TSizeTy>& ValV) const;
603  void Ins(const TSizeTy& ValN, const TVal& Val);
605  void Del(const TSizeTy& ValN);
607  void Del(const TSizeTy& MnValN, const TSizeTy& MxValN);
609  void DelLast(){Del(Len()-1);}
611  bool DelIfIn(const TVal& Val);
613  void DelAll(const TVal& Val);
615  void PutAll(const TVal& Val);
616 
618  void Swap(const TSizeTy& ValN1, const TSizeTy& ValN2){ const TVal Val=ValT[ValN1]; ValT[ValN1]=ValT[ValN2]; ValT[ValN2]=Val;}
620  static void SwapI(TIter LVal, TIter RVal){ const TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
621 
623 
627  bool NextPerm();
629 
631  bool PrevPerm();
632 
633  // Sorting functions
635  TSizeTy GetPivotValN(const TSizeTy& LValN, const TSizeTy& RValN) const;
637 
639  void BSort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc);
641 
643  void ISort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc);
645 
648  TSizeTy Partition(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc);
650 
653  void QSort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc);
655 
658  void Sort(const bool& Asc=true);
660  bool IsSorted(const bool& Asc=true) const;
662  void Shuffle(TRnd& Rnd);
664  void Reverse();
666  void Reverse(TSizeTy LValN, TSizeTy RValN){ Assert(LValN>=0 && RValN<Len()); while (LValN < RValN){Swap(LValN++, RValN--);} }
668  void Merge();
669 
671  template <class TCmp>
672  static TIter GetPivotValNCmp(const TIter& BI, const TIter& EI, const TCmp& Cmp) {
673  TSizeTy SubVals=TSizeTy(EI-BI); if (SubVals > TInt::Mx-1) { SubVals = TInt::Mx-1; }
674  const TSizeTy ValN1=TInt::GetRnd(SubVals), ValN2=TInt::GetRnd(SubVals), ValN3=TInt::GetRnd(SubVals);
675  const TVal& Val1 = *(BI+ValN1); const TVal& Val2 = *(BI+ValN2); const TVal& Val3 = *(BI+ValN3);
676  if (Cmp(Val1, Val2)) {
677  if (Cmp(Val2, Val3)) return BI+ValN2;
678  else if (Cmp(Val3, Val1)) return BI+ValN1;
679  else return BI+ValN3;
680  } else {
681  if (Cmp(Val1, Val3)) return BI+ValN1;
682  else if (Cmp(Val3, Val2)) return BI+ValN2;
683  else return BI+ValN3; } }
685  template <class TCmp>
686  static TIter PartitionCmp(TIter BI, TIter EI, const TVal Pivot, const TCmp& Cmp) {
687  forever {
688  while (Cmp(*BI, Pivot)){++BI;} --EI;
689  while (Cmp(Pivot, *EI)){--EI;}
690  if (!(BI<EI)){return BI;} SwapI(BI, EI); ++BI; } }
692  template <class TCmp>
693  static void BSortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
694  for (TIter i = BI; i != EI; ++i) {
695  for (TIter j = EI-1; j != i; --j) {
696  if (Cmp(*j, *(j-1))) { SwapI(j, j-1); } } } }
698  template <class TCmp>
699  static void ISortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
700  if (BI + 1 < EI) {
701  for (TIter i = BI, j; i != EI; ++i) { TVal Tmp=*i; j=i;
702  while (j > BI && Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; } *j=Tmp; } } }
704  template <class TCmp>
705  static void QSortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
706  if (BI + 1 < EI) {
707  if (EI - BI < 20) { ISortCmp(BI, EI, Cmp); }
708  else { const TVal Val = *GetPivotValNCmp(BI, EI, Cmp);
709  TIter Split = PartitionCmp(BI, EI, Val, Cmp);
710  QSortCmp(BI, Split, Cmp); QSortCmp(Split, EI, Cmp); } } }
712  template <class TCmp>
713  void SortCmp(const TCmp& Cmp){ QSortCmp(BegI(), EndI(), Cmp);}
715  template <class TCmp>
716  bool IsSortedCmp(const TCmp& Cmp) const {
717  if (EndI() == BegI()) return true;
718  for (TIter i = BegI(); i != EndI()-1; ++i) {
719  if (Cmp(*(i+1), *i)){return false;} } return true; }
720 
722 
724  void Intrs(const TVec<TVal, TSizeTy>& ValV);
726 
728  void Union(const TVec<TVal, TSizeTy>& ValV);
730 
733  void Diff(const TVec<TVal, TSizeTy>& ValV);
735 
737  void Intrs(const TVec<TVal, TSizeTy>& ValV, TVec<TVal, TSizeTy>& DstValV) const;
739 
741  void Union(const TVec<TVal, TSizeTy>& ValV, TVec<TVal, TSizeTy>& DstValV) const;
743 
746  void Diff(const TVec<TVal, TSizeTy>& ValV, TVec<TVal, TSizeTy>& DstValV) const;
748 
750  TSizeTy IntrsLen(const TVec<TVal, TSizeTy>& ValV) const;
752 
754  TSizeTy UnionLen(const TVec<TVal, TSizeTy>& ValV) const;
755 
757  TSizeTy Count(const TVal& Val) const;
759 
762  TSizeTy SearchBin(const TVal& Val) const;
764 
766  TSizeTy SearchBin(const TVal& Val, TSizeTy& InsValN) const;
768 
771  TSizeTy SearchForw(const TVal& Val, const TSizeTy& BValN=0) const;
773 
775  TSizeTy SearchBack(const TVal& Val) const;
777 
779  TSizeTy SearchVForw(const TVec<TVal, TSizeTy>& ValV, const TSizeTy& BValN=0) const;
780 
782  bool IsIn(const TVal& Val) const {return SearchForw(Val)!=-1;}
784 
786  bool IsIn(const TVal& Val, TSizeTy& ValN) const { ValN=SearchForw(Val); return ValN!=-1;}
788 
790  bool IsInBin(const TVal& Val) const {return SearchBin(Val)!=-1;}
792  const TVal& GetDat(const TVal& Val) const { return GetVal(SearchForw(Val));}
794 
796  TVal& GetAddDat(const TVal& Val){ AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
797  const TSizeTy ValN=SearchForw(Val); if (ValN==-1){Add(Val); return Last();} else {return GetVal(ValN);}}
799  TSizeTy GetMxValN() const;
800 
802  static TVec<TVal, TSizeTy> GetV(const TVal& Val1){
803  TVec<TVal, TSizeTy> V(1, 0); V.Add(Val1); return V;}
805  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2){
806  TVec<TVal, TSizeTy> V(2, 0); V.Add(Val1); V.Add(Val2); return V;}
808  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3){
809  TVec<TVal, TSizeTy> V(3, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); return V;}
811  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4){
812  TVec<TVal, TSizeTy> V(4, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); return V;}
814  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5){
815  TVec<TVal, TSizeTy> V(5, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); return V;}
817  static TVec<TVal, TSizeTy> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5, const TVal& Val6){
818  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;}
820  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){
821  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;}
823  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){
824  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;}
826  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){
827  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;}
828 };
829 
830 template <class TVal, class TSizeTy>
831 void TVec<TVal, TSizeTy>::Resize(const TSizeTy& _MxVals){
832  IAssertR(MxVals!=-1, 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());
833  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());
834  if (_MxVals==-1){
835  if (Vals==0){MxVals=16;} else {MxVals*=2;}
836  } else {
837  if (_MxVals<=MxVals){return;} else {MxVals=_MxVals;}
838  }
839  if (MxVals < 0) {
840  MxVals = TInt::Mx-1024;
841  }
842  if (ValT==NULL){
843  try {ValT=new TVal[MxVals];}
844  catch (std::exception Ex){
845  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.]",
846  Ex.what(), TInt::GetStr(Vals).CStr(), TInt::GetStr(MxVals).CStr(), TInt::GetStr(_MxVals).CStr(), GetTypeNm(*this).CStr()).CStr());}
847  } else {
848  TVal* NewValT = NULL;
849  try {
850  NewValT=new TVal[MxVals];}
851  catch (std::exception Ex){
852  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.]",
853  Ex.what(), TInt::GetStr(Vals).CStr(), TInt::GetStr(MxVals).CStr(), TInt::GetStr(_MxVals).CStr(), GetTypeNm(*this).CStr()).CStr());}
854  IAssert(NewValT!=NULL);
855  for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
856  delete[] ValT; ValT=NewValT;
857  }
858 }
859 
860 template <class TVal, class TSizeTy>
862  return TStr()+
863  "Index:"+TInt::GetStr(ValN)+
864  " Vals:"+TInt::GetStr(Vals)+
865  " MxVals:"+TInt::GetStr(MxVals)+
866  " Type:"+GetTypeNm(*this);
867 }
868 
869 template <class TVal, class TSizeTy>
871  MxVals=Vec.MxVals; Vals=Vec.Vals;
872  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
873  for (TSizeTy ValN=0; ValN<Vec.Vals; ValN++){ValT[ValN]=Vec.ValT[ValN];}
874 }
875 
876 template <class TVal, class TSizeTy>
878  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
879  SIn.Load(MxVals); SIn.Load(Vals); MxVals=Vals;
880  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
881  for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=TVal(SIn);}
882 }
883 
884 template <class TVal, class TSizeTy>
885 void TVec<TVal, TSizeTy>::Save(TSOut& SOut) const {
886  if (MxVals!=-1){SOut.Save(MxVals);} else {SOut.Save(Vals);}
887  SOut.Save(Vals);
888  for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
889 }
890 
891 template <class TVal, class TSizeTy>
893  if (this!=&Vec){
894  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
895  MxVals=Vals=Vec.Vals;
896  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
897  for (TSizeTy ValN=0; ValN<Vec.Vals; ValN++){ValT[ValN]=Vec.ValT[ValN];}
898  }
899  return *this;
900 }
901 
902 template <class TVal, class TSizeTy>
904  if (this==&Vec){return true;}
905  if (Len()!=Vec.Len()){return false;}
906  for (TSizeTy ValN=0; ValN<Vals; ValN++){
907  if (ValT[ValN]!=Vec.ValT[ValN]){return false;}}
908  return true;
909 }
910 
911 template <class TVal, class TSizeTy>
913  if (this==&Vec){return false;}
914  if (Len()==Vec.Len()){
915  for (TSizeTy ValN=0; ValN<Vals; ValN++){
916  if (ValT[ValN]<Vec.ValT[ValN]){return true;}
917  else if (ValT[ValN]>Vec.ValT[ValN]){return false;}
918  else {}
919  }
920  return false;
921  } else {
922  return Len()<Vec.Len();
923  }
924 }
925 
926 // Improved hashing of vectors (Jure Apr 20 2013)
927 // This change makes binary representation of vectors incompatible with previous code.
928 // Previous hash functions are available for compatibility in class TVecHashF_OldGLib
929 template <class TVal, class TSizeTy>
931  int hc = 0;
932  for (TSizeTy i=0; i<Vals; i++){
933  hc = TPairHashImpl::GetHashCd(hc, ValT[i].GetPrimHashCd());
934  }
935  return hc;
936 }
937 
938 // Improved hashing of vectors (Jure Apr 20 2013)
939 // This change makes binary representation of vectors incompatible with previous code.
940 // Previous hash functions are available for compatibility in class TVecHashF_OldGLib
941 template <class TVal, class TSizeTy>
943  int hc = 0;
944  for (TSizeTy i=0; i<Vals; i++){
945  hc = TPairHashImpl::GetHashCd(hc, ValT[i].GetSecHashCd());
946  }
947  if (Vals > 0) {
948  hc = TPairHashImpl::GetHashCd(hc, ValT[0].GetSecHashCd()); }
949  return hc;
950 }
951 
952 template <class TVal, class TSizeTy>
953 void TVec<TVal, TSizeTy>::Clr(const bool& DoDel, const TSizeTy& NoDelLim){
954  if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){
955  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
956  MxVals=Vals=0; ValT=NULL;
957  } else {
958  IAssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
959  Vals=0;
960  }
961 }
962 
963 template <class TVal, class TSizeTy>
964 void TVec<TVal, TSizeTy>::Trunc(const TSizeTy& _Vals){
965  IAssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
966  IAssert((_Vals==-1)||(_Vals>=0));
967  if ((_Vals!=-1)&&(_Vals>=Vals)){
968  return;
969  } else
970  if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){
971  if (ValT!=NULL){delete[] ValT;}
972  MxVals=Vals=0; ValT=NULL;
973  } else {
974  if (_Vals==-1){
975  if (MxVals==Vals){return;} else {MxVals=Vals;}
976  } else {
977  MxVals=Vals=_Vals;
978  }
979  TVal* NewValT=new TVal[MxVals];
980  IAssert(NewValT!=NULL);
981  for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
982  delete[] ValT; ValT=NewValT;
983  }
984 }
985 
986 template <class TVal, class TSizeTy>
988  IAssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
989  if (Vals==0){
990  if (ValT!=NULL){delete[] ValT;} ValT=NULL;
991  } else
992  if (Vals<MxVals){
993  MxVals=Vals;
994  TVal* NewValT=new TVal[MxVals];
995  IAssert(NewValT!=NULL);
996  for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
997  delete[] ValT; ValT=NewValT;
998  }
999 }
1000 
1001 template <class TVal, class TSizeTy>
1003  if (this!=&Vec){
1004  if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
1005  MxVals=Vec.MxVals; Vals=Vec.Vals; ValT=Vec.ValT;
1006  Vec.MxVals=0; Vec.Vals=0; Vec.ValT=NULL;
1007  }
1008 }
1009 
1010 template <class TVal, class TSizeTy>
1012  if (this!=&Vec){
1013  ::Swap(MxVals, Vec.MxVals);
1014  ::Swap(Vals, Vec.Vals);
1015  ::Swap(ValT, Vec.ValT);
1016  }
1017 }
1018 
1019 template <class TVal, class TSizeTy>
1021  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1022  for (TSizeTy ValN=0; ValN<ValV.Vals; ValN++){Add(ValV[ValN]);}
1023  return Len();
1024 }
1025 
1026 template <class TVal, class TSizeTy>
1027 TSizeTy TVec<TVal, TSizeTy>::AddSorted(const TVal& Val, const bool& Asc, const TSizeTy& _MxVals){
1028  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1029  TSizeTy ValN=Add(Val);
1030  if (Asc){
1031  while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){
1032  Swap(ValN, ValN-1); ValN--;}
1033  } else {
1034  while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){
1035  Swap(ValN, ValN-1); ValN--;}
1036  }
1037  if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);}
1038  return ValN;
1039 }
1040 
1041 template <class TVal, class TSizeTy>
1042 TSizeTy TVec<TVal, TSizeTy>::AddBackSorted(const TVal& Val, const bool& Asc){
1043  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1044  Add();
1045  TSizeTy ValN=Vals-2;
1046  while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
1047  ValT[ValN+1]=ValT[ValN]; ValN--;}
1048  ValT[ValN+1]=Val;
1049  return ValN+1;
1050 }
1051 
1052 template <class TVal, class TSizeTy>
1053 TSizeTy TVec<TVal, TSizeTy>::AddMerged(const TVal& Val){
1054  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1055  TSizeTy ValN=SearchBin(Val);
1056  if (ValN==-1){return AddSorted(Val);}
1057  else {GetVal(ValN)=Val; return -1;}
1058 }
1059 
1060 template <class TVal, class TSizeTy>
1062  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1063  for (TSizeTy ValN=0; ValN<ValV.Vals; ValN++){AddMerged(ValV[ValN]);}
1064  return Len();
1065 }
1066 
1067 template <class TVal, class TSizeTy>
1068 TSizeTy TVec<TVal, TSizeTy>::AddUnique(const TVal& Val){
1069  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1070  TSizeTy ValN=SearchForw(Val);
1071  if (ValN==-1){return Add(Val);}
1072  else {GetVal(ValN)=Val; return -1;}
1073 }
1074 
1075 template <class TVal, class TSizeTy>
1076 void TVec<TVal, TSizeTy>::GetSubValV(const TSizeTy& _BValN, const TSizeTy& _EValN, TVec<TVal, TSizeTy>& SubValV) const {
1077  const TSizeTy BValN=TInt::GetInRng(_BValN, 0, Len()-1);
1078  const TSizeTy EValN=TInt::GetInRng(_EValN, 0, Len()-1);
1079  const TSizeTy SubVals=TInt::GetMx(0, EValN-BValN+1);
1080  SubValV.Gen(SubVals, 0);
1081  for (TSizeTy ValN=BValN; ValN<=EValN; ValN++){
1082  SubValV.Add(GetVal(ValN));}
1083 }
1084 
1085 template <class TVal, class TSizeTy>
1086 void TVec<TVal, TSizeTy>::Ins(const TSizeTy& ValN, const TVal& Val){
1087  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1088  Add(); Assert((0<=ValN)&&(ValN<Vals));
1089  for (TSizeTy MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
1090  ValT[ValN]=Val;
1091 }
1092 
1093 template <class TVal, class TSizeTy>
1094 void TVec<TVal, TSizeTy>::Del(const TSizeTy& ValN){
1095  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1096  Assert((0<=ValN)&&(ValN<Vals));
1097  for (TSizeTy MValN=ValN+1; MValN<Vals; MValN++){
1098  ValT[MValN-1]=ValT[MValN];}
1099  ValT[--Vals]=TVal();
1100 }
1101 
1102 template <class TVal, class TSizeTy>
1103 void TVec<TVal, TSizeTy>::Del(const TSizeTy& MnValN, const TSizeTy& MxValN){
1104  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1105  Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
1106  Assert(MnValN<=MxValN);
1107  for (TSizeTy ValN=MxValN+1; ValN<Vals; ValN++){
1108  ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
1109  for (TSizeTy ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
1110  ValT[ValN]=TVal();}
1111  Vals-=MxValN-MnValN+1;
1112 }
1113 
1114 template <class TVal, class TSizeTy>
1115 bool TVec<TVal, TSizeTy>::DelIfIn(const TVal& Val){
1116  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1117  TSizeTy ValN=SearchForw(Val);
1118  if (ValN!=-1){Del(ValN); return true;}
1119  else {return false;}
1120 }
1121 
1122 template <class TVal, class TSizeTy>
1123 void TVec<TVal, TSizeTy>::DelAll(const TVal& Val){
1124  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1125  TSizeTy ValN;
1126  while ((ValN=SearchForw(Val))!=-1){Del(ValN);}
1127 }
1128 
1129 template <class TVal, class TSizeTy>
1130 void TVec<TVal, TSizeTy>::PutAll(const TVal& Val){
1131  for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
1132 }
1133 
1134 template <class TVal, class TSizeTy>
1135 void TVec<TVal, TSizeTy>::BSort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc){
1136  for (TSizeTy ValN1=MnLValN; ValN1<=MxRValN; ValN1++){
1137  for (TSizeTy ValN2=MxRValN; ValN2>ValN1; ValN2--){
1138  if (Asc){
1139  if (ValT[ValN2]<ValT[ValN2-1]){Swap(ValN2, ValN2-1);}
1140  } else {
1141  if (ValT[ValN2]>ValT[ValN2-1]){Swap(ValN2, ValN2-1);}
1142  }
1143  }
1144  }
1145 }
1146 
1147 template <class TVal, class TSizeTy>
1148 void TVec<TVal, TSizeTy>::ISort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc){
1149  if (MnLValN<MxRValN){
1150  for (TSizeTy ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){
1151  TVal Val=ValT[ValN1]; TSizeTy ValN2=ValN1;
1152  if (Asc){
1153  while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){
1154  ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1155  } else {
1156  while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){
1157  ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1158  }
1159  ValT[ValN2]=Val;
1160  }
1161  }
1162 }
1163 
1164 template <class TVal, class TSizeTy>
1165 TSizeTy TVec<TVal, TSizeTy>::GetPivotValN(const TSizeTy& LValN, const TSizeTy& RValN) const {
1166  TSizeTy SubVals=RValN-LValN+1;
1167  if (SubVals > TInt::Mx-1) { SubVals = TInt::Mx-1; }
1168  const TSizeTy ValN1=LValN+TInt::GetRnd(int(SubVals));
1169  const TSizeTy ValN2=LValN+TInt::GetRnd(int(SubVals));
1170  const TSizeTy ValN3=LValN+TInt::GetRnd(int(SubVals));
1171  const TVal& Val1=ValT[ValN1];
1172  const TVal& Val2=ValT[ValN2];
1173  const TVal& Val3=ValT[ValN3];
1174  if (Val1<Val2){
1175  if (Val2<Val3){return ValN2;}
1176  else if (Val3<Val1){return ValN1;}
1177  else {return ValN3;}
1178  } else {
1179  if (Val1<Val3){return ValN1;}
1180  else if (Val3<Val2){return ValN2;}
1181  else {return ValN3;}
1182  }
1183 }
1184 
1185 template <class TVal, class TSizeTy>
1186 TSizeTy TVec<TVal, TSizeTy>::Partition(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc){
1187  TSizeTy PivotValN=GetPivotValN(MnLValN, MxRValN);
1188  Swap(PivotValN, MnLValN);
1189  TVal PivotVal=ValT[MnLValN];
1190  TSizeTy LValN=MnLValN-1; TSizeTy RValN=MxRValN+1;
1191  forever {
1192  if (Asc){
1193  do {RValN--;} while (ValT[RValN]>PivotVal);
1194  do {LValN++;} while (ValT[LValN]<PivotVal);
1195  } else {
1196  do {RValN--;} while (ValT[RValN]<PivotVal);
1197  do {LValN++;} while (ValT[LValN]>PivotVal);
1198  }
1199  if (LValN<RValN){Swap(LValN, RValN);}
1200  else {return RValN;}
1201  };
1202 }
1203 
1204 template <class TVal, class TSizeTy>
1205 void TVec<TVal, TSizeTy>::QSort(const TSizeTy& MnLValN, const TSizeTy& MxRValN, const bool& Asc){
1206  if (MnLValN<MxRValN){
1207  if (MxRValN-MnLValN<20){
1208  ISort(MnLValN, MxRValN, Asc);
1209  } else {
1210  TSizeTy SplitValN=Partition(MnLValN, MxRValN, Asc);
1211  QSort(MnLValN, SplitValN, Asc);
1212  QSort(SplitValN+1, MxRValN, Asc);
1213  }
1214  }
1215 }
1216 
1217 template <class TVal, class TSizeTy>
1218 void TVec<TVal, TSizeTy>::Sort(const bool& Asc){
1219  QSort(0, Len()-1, Asc);
1220 }
1221 
1222 template <class TVal, class TSizeTy>
1223 bool TVec<TVal, TSizeTy>::IsSorted(const bool& Asc) const {
1224  if (Asc){
1225  for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1226  if (ValT[ValN]>ValT[ValN+1]){return false;}}
1227  } else {
1228  for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1229  if (ValT[ValN]<ValT[ValN+1]){return false;}}
1230  }
1231  return true;
1232 }
1233 
1234 template <class TVal, class TSizeTy>
1236  if (Len() < TInt::Mx) {
1237  for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1238  const int Range = int(Vals-ValN);
1239  Swap(ValN, ValN+Rnd.GetUniDevInt(Range));
1240  }
1241  } else {
1242  for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1243  const TSizeTy Range = Vals-ValN;
1244  Swap(ValN, TSizeTy(ValN+Rnd.GetUniDevInt64(Range)));
1245  }
1246  }
1247 }
1248 
1249 template <class TVal, class TSizeTy>
1251  for (TSizeTy ValN=0; ValN<Vals/2; ValN++){
1252  Swap(ValN, Vals-ValN-1);}
1253 }
1254 
1255 template <class TVal, class TSizeTy>
1257  AssertR(MxVals!=-1, "This vector was obtained from TVecPool. Such vectors cannot change its size!");
1258  TVec<TVal, TSizeTy> SortedVec(*this); SortedVec.Sort();
1259  Clr();
1260  for (TSizeTy ValN=0; ValN<SortedVec.Len(); ValN++){
1261  if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){
1262  Add(SortedVec[ValN]);}
1263  }
1264 }
1265 
1266 template <class TVal, class TSizeTy>
1268  // start with a sorted sequence to obtain all permutations
1269  TSizeTy First = 0, Last = Len(), Next = Len()-1;
1270  if (Last < 2) return false;
1271  for(; ; ) {
1272  // find rightmost element smaller than successor
1273  TSizeTy Next1 = Next;
1274  if (GetVal(--Next) < GetVal(Next1)) { // swap with rightmost element that's smaller, flip suffix
1275  TSizeTy Mid = Last;
1276  for (; GetVal(Next) >= GetVal(--Mid); ) { }
1277  Swap(Next, Mid);
1278  Reverse(Next1, Last-1);
1279  return true;
1280  }
1281  if (Next == First) { // pure descending, flip all
1282  Reverse();
1283  return false;
1284  }
1285  }
1286 }
1287 
1288 template <class TVal, class TSizeTy>
1290  TSizeTy First = 0, Last = Len(), Next = Len()-1;
1291  if (Last < 2) return false;
1292  for(; ; ) {
1293  // find rightmost element not smaller than successor
1294  TSizeTy Next1 = Next;
1295  if (GetVal(--Next) >= GetVal(Next1)) { // swap with rightmost element that's not smaller, flip suffix
1296  TSizeTy Mid = Last;
1297  for (; GetVal(Next) < GetVal(--Mid); ) { }
1298  Swap(Next, Mid);
1299  Reverse(Next1, Last);
1300  return true;
1301  }
1302  if (Next == First) { // pure descending, flip all
1303  Reverse();
1304  return false;
1305  }
1306  }
1307 }
1308 
1309 template <class TVal, class TSizeTy>
1311  TVec<TVal, TSizeTy> IntrsVec;
1312  Intrs(ValV, IntrsVec);
1313  MoveFrom(IntrsVec);
1314 }
1315 
1316 template <class TVal, class TSizeTy>
1318  TVec<TVal, TSizeTy> UnionVec;
1319  Union(ValV, UnionVec);
1320  MoveFrom(UnionVec);
1321 }
1322 
1323 template <class TVal, class TSizeTy>
1325  TVec<TVal, TSizeTy> DiffVec;
1326  Diff(ValV, DiffVec);
1327  MoveFrom(DiffVec);
1328 }
1329 
1330 template <class TVal, class TSizeTy>
1332  DstValV.Clr();
1333  TSizeTy ValN1=0, ValN2=0;
1334  while ((ValN1<Len())&&(ValN2<ValV.Len())){
1335  const TVal& Val1=GetVal(ValN1);
1336  while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){
1337  ValN2++;}
1338  if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){
1339  DstValV.Add(Val1); ValN2++;}
1340  ValN1++;
1341  }
1342 }
1343 
1344 template <class TVal, class TSizeTy>
1346  DstValV.Gen(TInt::GetMx(Len(), ValV.Len()), 0);
1347  TSizeTy ValN1=0, ValN2=0;
1348  while ((ValN1<Len())&&(ValN2<ValV.Len())){
1349  const TVal& Val1=GetVal(ValN1);
1350  const TVal& Val2=ValV.GetVal(ValN2);
1351  if (Val1<Val2){DstValV.Add(Val1); ValN1++;}
1352  else if (Val1>Val2){DstValV.Add(Val2); ValN2++;}
1353  else {DstValV.Add(Val1); ValN1++; ValN2++;}
1354  }
1355  for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1356  DstValV.Add(GetVal(RestValN1));}
1357  for (TSizeTy RestValN2=ValN2; RestValN2<ValV.Len(); RestValN2++){
1358  DstValV.Add(ValV.GetVal(RestValN2));}
1359 }
1360 
1361 template <class TVal, class TSizeTy>
1363  DstValV.Clr();
1364  TSizeTy ValN1=0, ValN2=0;
1365  while (ValN1<Len() && ValN2<ValV.Len()) {
1366  const TVal& Val1 = GetVal(ValN1);
1367  while (ValN2<ValV.Len() && Val1>ValV.GetVal(ValN2)) ValN2++;
1368  if (ValN2<ValV.Len()) {
1369  if (Val1!=ValV.GetVal(ValN2)) { DstValV.Add(Val1); }
1370  ValN1++;
1371  }
1372  }
1373  for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1374  DstValV.Add(GetVal(RestValN1));}
1375 }
1376 
1377 template <class TVal, class TSizeTy>
1379  TSizeTy Cnt=0, ValN1=0, ValN2=0;
1380  while ((ValN1<Len())&&(ValN2<ValV.Len())){
1381  const TVal& Val1=GetVal(ValN1);
1382  while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){
1383  ValN2++;}
1384  if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){
1385  ValN2++; Cnt++;}
1386  ValN1++;
1387  }
1388  return Cnt;
1389 }
1390 
1391 template <class TVal, class TSizeTy>
1393  TSizeTy Cnt = 0, ValN1 = 0, ValN2 = 0;
1394  while ((ValN1 < Len()) && (ValN2 < ValV.Len())) {
1395  const TVal& Val1 = GetVal(ValN1);
1396  const TVal& Val2 = ValV.GetVal(ValN2);
1397  if (Val1 < Val2) {
1398  Cnt++; ValN1++;
1399  } else if (Val1 > Val2) {
1400  Cnt++; ValN2++;
1401  } else {
1402  Cnt++; ValN1++; ValN2++;
1403  }
1404  }
1405  Cnt += (Len() - ValN1) + (ValV.Len() - ValN2);
1406  return Cnt;
1407 }
1408 
1409 template <class TVal, class TSizeTy>
1410 TSizeTy TVec<TVal, TSizeTy>::Count(const TVal& Val) const {
1411  TSizeTy Count = 0;
1412  for (TSizeTy i = 0; i < Len(); i++){
1413  if (Val == ValT[i]){Count++;}}
1414  return Count;
1415 }
1416 
1417 template <class TVal, class TSizeTy>
1418 TSizeTy TVec<TVal, TSizeTy>::SearchBin(const TVal& Val) const {
1419  TSizeTy LValN=0, RValN=Len()-1;
1420  while (RValN>=LValN){
1421  TSizeTy ValN=(LValN+RValN)/2;
1422  if (Val==ValT[ValN]){return ValN;}
1423  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
1424  }
1425  return -1;
1426 }
1427 
1428 template <class TVal, class TSizeTy>
1429 TSizeTy TVec<TVal, TSizeTy>::SearchBin(const TVal& Val, TSizeTy& InsValN) const {
1430  TSizeTy LValN=0, RValN=Len()-1;
1431  while (RValN>=LValN){
1432  TSizeTy ValN=(LValN+RValN)/2;
1433  if (Val==ValT[ValN]){InsValN=ValN; return ValN;}
1434  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
1435  }
1436  InsValN=LValN; return -1;
1437 }
1438 
1439 template <class TVal, class TSizeTy>
1440 TSizeTy TVec<TVal, TSizeTy>::SearchForw(const TVal& Val, const TSizeTy& BValN) const {
1441  for (TSizeTy ValN=BValN; ValN<Vals; ValN++){
1442  if (Val==ValT[ValN]){return ValN;}}
1443  return -1;
1444 }
1445 
1446 template <class TVal, class TSizeTy>
1447 TSizeTy TVec<TVal, TSizeTy>::SearchBack(const TVal& Val) const {
1448  for (TSizeTy ValN=Vals-1; ValN>=0; ValN--){
1449  if (Val==ValT[ValN]){return ValN;}}
1450  return -1;
1451 }
1452 
1453 template <class TVal, class TSizeTy>
1454 TSizeTy TVec<TVal, TSizeTy>::SearchVForw(const TVec<TVal, TSizeTy>& ValV, const TSizeTy& BValN) const {
1455  TSizeTy ValVLen=ValV.Len();
1456  for (TSizeTy ValN=BValN; ValN<Vals-ValVLen+1; ValN++){
1457  bool Found=true;
1458  for (TSizeTy SubValN=0; SubValN<ValVLen; SubValN++){
1459  if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=false; break;}
1460  }
1461  if (Found){return ValN;}
1462  }
1463  return -1;
1464 }
1465 
1466 template <class TVal, class TSizeTy>
1468  if (Vals==0){return -1;}
1469  TSizeTy MxValN=0;
1470  for (TSizeTy ValN=1; ValN<Vals; ValN++){
1471  if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
1472  }
1473  return MxValN;
1474 }
1475 
1477 // Vector
1478 namespace TGLib_OLD {
1479 
1480 template <class TVal>
1481 class TVec{
1482 public:
1483  typedef TVal* TIter;
1484 protected:
1485  int MxVals; // if MxVals==-1, then ValT is not owned by us, we don't free it!
1486  int Vals;
1487  TVal* ValT;
1488  void Resize(const int& _MxVals=-1);
1489  TStr GetXOutOfBoundsErrMsg(const int& ValN) const;
1490 public:
1491  TVec(): MxVals(0), Vals(0), ValT(NULL){}
1492  TVec(const TVec& Vec);
1493  explicit TVec(const int& _Vals){
1494  IAssert(0<=_Vals); MxVals=Vals=_Vals;
1495  if (_Vals==0){ValT=NULL;} else {ValT=new TVal[_Vals];}}
1496  TVec(const int& _MxVals, const int& _Vals){
1497  IAssert((0<=_Vals)&&(_Vals<=_MxVals)); MxVals=_MxVals; Vals=_Vals;
1498  if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
1499  explicit TVec(TVal *_ValT, const int& _Vals):
1500  MxVals(-1), Vals(_Vals), ValT(_ValT){}
1501  ~TVec(){if ((ValT!=NULL) && (MxVals!=-1)){delete[] ValT;}}
1502  explicit TVec(TSIn& SIn): MxVals(0), Vals(0), ValT(NULL){Load(SIn);}
1503  void Load(TSIn& SIn);
1504  void Save(TSOut& SOut) const;
1505  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
1506  void SaveXml(TSOut& SOut, const TStr& Nm) const;
1507 
1508  TVec<TVal>& operator=(const TVec<TVal>& Vec);
1509  TVec<TVal>& operator+(const TVal& Val){Add(Val); return *this;}
1510  bool operator==(const TVec<TVal>& Vec) const;
1511  bool operator<(const TVec<TVal>& Vec) const;
1512  const TVal& operator[](const int& ValN) const {
1513  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
1514  return ValT[ValN];}
1515  TVal& operator[](const int& ValN){
1516  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
1517  return ValT[ValN];}
1518  int GetMemUsed() const {
1519  return int(2*sizeof(int)+sizeof(TVal*)+MxVals*sizeof(TVal));}
1520 
1521  int GetPrimHashCd() const;
1522  int GetSecHashCd() const;
1523 
1524  void Gen(const int& _Vals){
1525  IAssert(0<=_Vals);
1526  if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=Vals=_Vals;
1527  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}}
1528  void Gen(const int& _MxVals, const int& _Vals){
1529  IAssert((0<=_Vals)&&(_Vals<=_MxVals));
1530  if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=_MxVals; Vals=_Vals;
1531  if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
1532  void GenExt(TVal *_ValT, const int& _Vals){
1533  if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
1534  MxVals=-1; Vals=_Vals; ValT=_ValT;}
1535  bool IsExt() const {return MxVals==-1;}
1536  void Reserve(const int& _MxVals){Resize(_MxVals);}
1537  void Reserve(const int& _MxVals, const int& _Vals){
1538  IAssert((0<=_Vals)&&(_Vals<=_MxVals));
1539  Resize(_MxVals); Vals=_Vals;}
1540  void Clr(const bool& DoDel=true, const int& NoDelLim=-1);
1541  void Trunc(const int& _Vals=-1);
1542  void Pack();
1543  void MoveFrom(TVec<TVal>& Vec);
1544  void Swap(TVec<TVal>& Vec);
1545 
1546  bool Empty() const {return Vals==0;}
1547  int Len() const {return Vals;}
1548  int Reserved() const {return MxVals;}
1549  const TVal& Last() const {return GetVal(Len()-1);}
1550  TVal& Last(){return GetVal(Len()-1);}
1551  int LastValN() const {return Len()-1;}
1552  const TVal& LastLast() const {
1554  return ValT[Vals-2];}
1555  TVal& LastLast(){
1557  return ValT[Vals-2];}
1558 
1559  TIter BegI() const {return ValT;}
1560  TIter EndI() const {return ValT+Vals;}
1561  TIter GetI(const int& ValN) const {return ValT+ValN;}
1562 
1563  int Add(){
1564  Assert(MxVals!=-1); if (Vals==MxVals){Resize();} return Vals++;}
1565  int Add(const TVal& Val){
1566  Assert(MxVals!=-1); if (Vals==MxVals){Resize();} ValT[Vals]=Val; return Vals++;}
1567  int Add(const TVal& Val, const int& ResizeLen){
1568  Assert(MxVals!=-1); if (Vals==MxVals){Resize(MxVals+ResizeLen);} ValT[Vals]=Val; return Vals++;}
1569  int AddV(const TVec<TVal>& ValV);
1570  int AddSorted(const TVal& Val, const bool& Asc=true, const int& _MxVals=-1);
1571  int AddBackSorted(const TVal& Val, const bool& Asc);
1572  int AddMerged(const TVal& Val);
1573  int AddVMerged(const TVec<TVal>& ValV);
1574  int AddUnique(const TVal& Val);
1575  const TVal& GetVal(const int& ValN) const {return operator[](ValN);}
1576  TVal& GetVal(const int& ValN){return operator[](ValN);}
1577  void GetSubValV(const int& BValN, const int& EValN, TVec<TVal>& ValV) const;
1578  void Ins(const int& ValN, const TVal& Val);
1579  void Del(const int& ValN);
1580  void Del(const int& MnValN, const int& MxValN);
1581  void DelLast(){Del(Len()-1);}
1582  bool DelIfIn(const TVal& Val);
1583  void DelAll(const TVal& Val);
1584  void PutAll(const TVal& Val);
1585 
1586  void Swap(const int& ValN1, const int& ValN2){
1587  TVal Val=ValT[ValN1]; ValT[ValN1]=ValT[ValN2]; ValT[ValN2]=Val;}
1588  static void SwapI(TIter LVal, TIter RVal){
1589  TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
1590 
1591  int GetPivotValN(const int& LValN, const int& RValN) const;
1592  void BSort(const int& MnLValN, const int& MxRValN, const bool& Asc);
1593  void ISort(const int& MnLValN, const int& MxRValN, const bool& Asc);
1594  int Partition(const int& MnLValN, const int& MxRValN, const bool& Asc);
1595  void QSort(const int& MnLValN, const int& MxRValN, const bool& Asc);
1596  void Sort(const bool& Asc=true);
1597  bool IsSorted(const bool& Asc=true) const;
1598  void Shuffle(TRnd& Rnd);
1599  void Reverse();
1600  void Reverse(int First, int Last){
1601  Last--; while (First < Last){Swap(First++, Last--);}}
1602  void Merge();
1603  // permutations
1604  bool NextPerm();
1605  bool PrevPerm();
1606 
1607  // binary heap //J:
1608  void MakeHeap() { MakeHeap(TLss<TVal>()); } // build a heap
1609  void PushHeap(const TVal& Val) { PushHeap(Val, TLss<TVal>()); } // add element to the heap
1610  const TVal& TopHeap() const { return ValT[0]; } // get largest element
1611  TVal PopHeap() { return PopHeap(TLss<TVal>()); } // remove largest element
1612  template <class TCmp> void MakeHeap(const TCmp& Cmp) { MakeHeap(0, Len(), Cmp); }
1613  template <class TCmp> void PushHeap(const TVal& Val, const TCmp& Cmp) { Add(Val); PushHeap(0, Len()-1, 0, Val, Cmp); }
1614  template <class TCmp> TVal PopHeap(const TCmp& Cmp) { IAssert(! Empty()); const TVal Top=ValT[0];
1615  ValT[0]=Last(); DelLast(); if (! Empty()) { AdjustHeap(0, 0, Len(), ValT[0], Cmp); } return Top; }
1616  // heap helper functions
1617  template <class TCmp>
1618  void PushHeap(const int& First, int HoleIdx, const int& Top, TVal Val, const TCmp& Cmp) {
1619  int Parent = (HoleIdx-1)/2;
1620  while (HoleIdx > Top && Cmp(ValT[First+Parent], Val)) {
1621  ValT[First+HoleIdx] = ValT[First+Parent];
1622  HoleIdx = Parent; Parent = (HoleIdx-1)/2; }
1623  ValT[First+HoleIdx] = Val;
1624  }
1625  template <class TCmp>
1626  void AdjustHeap(const int& First, int HoleIdx, const int& Len, TVal Val, const TCmp& Cmp) {
1627  const int Top = HoleIdx;
1628  int Right = 2*HoleIdx+2;
1629  while (Right < Len) {
1630  if (Cmp(ValT[First+Right], ValT[First+Right-1])) { Right--; }
1631  ValT[First+HoleIdx] = ValT[First+Right];
1632  HoleIdx = Right; Right = 2*(Right+1); }
1633  if (Right == Len) {
1634  ValT[First+HoleIdx] = ValT[First+Right-1];
1635  HoleIdx = Right-1; }
1636  PushHeap(First, HoleIdx, Top, Val, Cmp);
1637  }
1638  template <class TCmp>
1639  void MakeHeap(const int& First, const int& Len, const TCmp& Cmp) {
1640  if (Len < 2) { return; }
1641  int Parent = (Len-2)/2;
1642  while (true) {
1643  AdjustHeap(First, Parent, Len, ValT[First+Parent], Cmp);
1644  if (Parent == 0) { return; } Parent--; }
1645  }
1646 
1647  template <class TCmp>
1648  static TIter GetPivotValNCmp(const TIter& BI, const TIter& EI, const TCmp& Cmp) {
1649  const int SubVals=int(EI-BI);
1650  const int ValN1=TInt::GetRnd(SubVals);
1651  const int ValN2=TInt::GetRnd(SubVals);
1652  const int ValN3=TInt::GetRnd(SubVals);
1653  const TVal& Val1 = *(BI+ValN1);
1654  const TVal& Val2 = *(BI+ValN2);
1655  const TVal& Val3 = *(BI+ValN3);
1656  if (Cmp(Val1, Val2)) {
1657  if (Cmp(Val2, Val3)) return BI+ValN2;
1658  else if (Cmp(Val3, Val1)) return BI+ValN1;
1659  else return BI+ValN3;
1660  } else {
1661  if (Cmp(Val1, Val3)) return BI+ValN1;
1662  else if (Cmp(Val3, Val2)) return BI+ValN2;
1663  else return BI+ValN3;
1664  }
1665  }
1666 
1667  template <class TCmp>
1668  static TIter PartitionCmp(TIter BI, TIter EI, const TVal Pivot, const TCmp& Cmp) {
1669  forever {
1670  while (Cmp(*BI, Pivot)) ++BI;
1671  --EI;
1672  while (Cmp(Pivot, *EI)) --EI;
1673  if (!(BI < EI)) return BI;
1674  SwapI(BI, EI);
1675  ++BI;
1676  }
1677  }
1678 
1679  template <class TCmp>
1680  static void BSortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
1681  for (TIter i = BI; i != EI; ++i) {
1682  for (TIter j = EI-1; j != i; --j) {
1683  if (Cmp(*j, *(j-1))) SwapI(j, j-1); }
1684  }
1685  }
1686 
1687  template <class TCmp>
1688  static void ISortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
1689  if (BI + 1 < EI) {
1690  for (TIter i = BI, j; i != EI; ++i) {
1691  TVal Tmp = *i; j = i;
1692  while (j > BI && Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; }
1693  *j = Tmp;
1694  }
1695  }
1696  }
1697 
1698  template <class TCmp>
1699  static void QSortCmp(TIter BI, TIter EI, const TCmp& Cmp) {
1700  if (BI + 1 < EI) {
1701  if (EI - BI < 20) {
1702  ISortCmp(BI, EI, Cmp); }
1703  else {
1704  const TVal Val = *GetPivotValNCmp(BI, EI, Cmp);
1705  TIter Split = PartitionCmp(BI, EI, Val, Cmp);
1706  QSortCmp(BI, Split, Cmp);
1707  QSortCmp(Split, EI, Cmp);
1708  }
1709  }
1710  }
1711 
1712  // void Sort(const bool& Asc = true) {
1713  // if (Asc){QSortCmp(Beg(), End(), TLss<TVal>());}
1714  // else {QSortCmp(Beg(), End(), TGtr<TVal>());}}
1715 
1716  template <class TCmp>
1717  void SortCmp(const TCmp& Cmp){
1718  QSortCmp(BegI(), EndI(), Cmp);}
1719 
1720  // bool IsSorted(const bool& Asc = true) const {
1721  // if (Asc){return IsSortedCmp(TLss<TVal>());}
1722  // else {return IsSortedCmp(TGtr<TVal>());}}
1723 
1724  template <class TCmp>
1725  bool IsSortedCmp(const TCmp& Cmp) const {
1726  if (EndI() == BegI()) return true;
1727  for (TIter i = BegI(); i != EndI()-1; ++i) {
1728  if (Cmp(*(i+1), *i)){return false;}}
1729  return true;
1730  }
1731 
1732  void Intrs(const TVec<TVal>& ValV);
1733  void Union(const TVec<TVal>& ValV);
1734  void Diff(const TVec<TVal>& ValV); // union without intersection
1735  void Minus(const TVec<TVal>& ValV); // this without intersection
1736  void Intrs(const TVec<TVal>& ValV, TVec<TVal>& DstValV) const;
1737  void Union(const TVec<TVal>& ValV, TVec<TVal>& DstValV) const;
1738  void Diff(const TVec<TVal>& ValV, TVec<TVal>& DstValV) const;
1740  int IntrsLen(const TVec<TVal>& ValV) const;
1742  int UnionLen(const TVec<TVal>& ValV) const;
1743  void Minus(const TVec<TVal>& ValV, TVec<TVal>& DstValV) const;
1744 
1745  int Count(const TVal& Val) const;
1746  int SearchBin(const TVal& Val) const;
1747  int SearchBin(const TVal& Val, int& InsValN) const;
1748  int SearchForw(const TVal& Val, const int& BValN=0) const;
1749  int SearchBack(const TVal& Val) const;
1750  int SearchVForw(const TVec<TVal>& ValV, const int& BValN=0) const;
1751  bool IsIn(const TVal& Val) const {return SearchForw(Val)!=-1;}
1752  bool IsIn(const TVal& Val, int& ValN) const {
1753  ValN=SearchForw(Val); return ValN!=-1;}
1754  bool IsInBin(const TVal& Val) const {return SearchBin(Val)!=-1;}
1755  int GetMxValN() const;
1756  TVal& GetDat(const TVal& Val) const {
1757  int ValN=SearchForw(Val);
1758  return operator[](ValN);}
1759  TVal& GetAddDat(const TVal& Val){
1760  Assert(MxVals!=-1);
1761  int ValN=SearchForw(Val);
1762  if (ValN==-1){Add(Val); return Last();}
1763  else {return operator[](ValN);}}
1764 
1765  // short vectors
1766  static TVec<TVal> GetV(const TVal& Val1){
1767  TVec<TVal> V(1, 0); V.Add(Val1); return V;}
1768  static TVec<TVal> GetV(const TVal& Val1, const TVal& Val2){
1769  TVec<TVal> V(2, 0); V.Add(Val1); V.Add(Val2); return V;}
1770  static TVec<TVal> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3){
1771  TVec<TVal> V(3, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); return V;}
1772  static TVec<TVal> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4){
1773  TVec<TVal> V(4, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); return V;}
1774  static TVec<TVal> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5){
1775  TVec<TVal> V(5, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); return V;}
1776  static TVec<TVal> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5, const TVal& Val6){
1777  TVec<TVal> V(6, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); return V;}
1778  static TVec<TVal> GetV(const TVal& Val1, const TVal& Val2, const TVal& Val3, const TVal& Val4, const TVal& Val5, const TVal& Val6, const TVal& Val7){
1779  TVec<TVal> 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;}
1780  static TVec<TVal> 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){
1781  TVec<TVal> 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;}
1782  static TVec<TVal> 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){
1783  TVec<TVal> 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;}
1784  //static TVec<TVal> GetV(const TVal* ValPt, const TVal& EndVal){
1785  // TVec<TVal> V; while(*ValPt!=EndVal){V.Add(*ValPt); ValPt++;} return V;}
1786 };
1787 
1788 template <class TVal>
1789 void TVec<TVal>::Resize(const int& _MxVals){
1790  IAssertR(MxVals!=-1, TStr::Fmt("Can not resize buffer. %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", GetTypeNm(*this).CStr()).CStr());
1791  IAssertR(MxVals!=(TInt::Mx-1024), TStr::Fmt("Buffer size at maximum. %s. [Program refuses to allocate more memory. Solution-2: Send your test case to developers.]", GetTypeNm(*this).CStr()).CStr());
1792  if (_MxVals==-1){
1793  if (Vals==0){MxVals=16;} else {MxVals*=2;}
1794  } else {
1795  if (_MxVals<=MxVals){return;} else {MxVals=_MxVals;}
1796  }
1797  if (MxVals < 0) {
1798  MxVals = TInt::Mx-1024;
1799  }
1800  if (ValT==NULL){
1801  try {ValT=new TVal[MxVals];}
1802  catch (std::exception Ex){
1803  FailR(TStr::Fmt("TVec::Resize 1: %s, Vals:%d, MxVals:%d, _MxVals:%d, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
1804  Ex.what(), Vals, MxVals, _MxVals, GetTypeNm(*this).CStr()).CStr());}
1805  } else {
1806  //if (Vals > 1000000) {
1807  // printf("%s resize %d -> %d\n", GetTypeNm(*this).CStr(), Vals, MxVals); }
1808  TVal* NewValT = NULL;
1809  try {
1810  NewValT=new TVal[MxVals];}
1811  catch (std::exception Ex){
1812  FailR(TStr::Fmt("TVec::Resize 2: %s, Vals:%d, MxVals:%d, _MxVals:%d, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
1813  Ex.what(), Vals, MxVals, _MxVals, GetTypeNm(*this).CStr()).CStr());}
1814  Assert(NewValT!=NULL);
1815  for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1816  delete[] ValT; ValT=NewValT;
1817  }
1818 }
1819 
1820 template <class TVal>
1821 TStr TVec<TVal>::GetXOutOfBoundsErrMsg(const int& ValN) const {
1822  return TStr()+
1823  "Index:"+TInt::GetStr(ValN)+
1824  " Vals:"+TInt::GetStr(Vals)+
1825  " MxVals:"+TInt::GetStr(MxVals)+
1826  " Type:"+GetTypeNm(*this);
1827 }
1828 
1829 template <class TVal>
1830 TVec<TVal>::TVec(const TVec<TVal>& Vec){
1831  MxVals=Vec.MxVals; Vals=Vec.Vals;
1832  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
1833  for (int ValN=0; ValN<Vec.Vals; ValN++){ValT[ValN]=Vec.ValT[ValN];}
1834 }
1835 
1836 template <class TVal>
1838  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
1839  SIn.Load(MxVals); SIn.Load(Vals); MxVals=Vals;
1840  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
1841  for (int ValN=0; ValN<Vals; ValN++){
1842  ValT[ValN]=TVal(SIn);}
1843 }
1844 
1845 template <class TVal>
1846 void TVec<TVal>::Save(TSOut& SOut) const {
1847  if (MxVals!=-1){SOut.Save(MxVals);} else {SOut.Save(Vals);}
1848  SOut.Save(Vals);
1849  for (int ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
1850 }
1851 
1852 template <class TVal>
1854  if (this!=&Vec){
1855  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
1856  MxVals=Vals=Vec.Vals;
1857  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
1858  for (int ValN=0; ValN<Vec.Vals; ValN++){ValT[ValN]=Vec.ValT[ValN];}
1859  }
1860  return *this;
1861 }
1862 
1863 template <class TVal>
1864 bool TVec<TVal>::operator==(const TVec<TVal>& Vec) const {
1865  if (this==&Vec){return true;}
1866  if (Len()!=Vec.Len()){return false;}
1867  for (int ValN=0; ValN<Vals; ValN++){
1868  if (ValT[ValN]!=Vec.ValT[ValN]){return false;}}
1869  return true;
1870 }
1871 
1872 template <class TVal>
1873 bool TVec<TVal>::operator<(const TVec<TVal>& Vec) const {
1874  if (this==&Vec){return false;}
1875  if (Len()==Vec.Len()){
1876  for (int ValN=0; ValN<Vals; ValN++){
1877  if (ValT[ValN]<Vec.ValT[ValN]){return true;}
1878  else if (ValT[ValN]>Vec.ValT[ValN]){return false;}
1879  else {}
1880  }
1881  return false;
1882  } else {
1883  return Len()<Vec.Len();
1884  }
1885 }
1886 
1887 template <class TVal>
1889  int HashCd=0;
1890  for (int ValN=0; ValN<Vals; ValN++){
1891  HashCd+=ValT[ValN].GetPrimHashCd();}
1892  return abs(HashCd);
1893 }
1894 
1895 template <class TVal>
1897  int HashCd=0;
1898  for (int ValN=0; ValN<Vals; ValN++){
1899  HashCd+=ValT[ValN].GetSecHashCd();}
1900  return abs(HashCd);
1901 }
1902 
1903 template <class TVal>
1904 void TVec<TVal>::Clr(const bool& DoDel, const int& NoDelLim){
1905  if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){
1906  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
1907  MxVals=Vals=0; ValT=NULL;
1908  } else {
1909  IAssert(MxVals!=-1); Vals=0;
1910  }
1911 }
1912 
1913 template <class TVal>
1914 void TVec<TVal>::Trunc(const int& _Vals){
1915  IAssert(MxVals!=-1);
1916  IAssert((_Vals==-1)||(_Vals>=0));
1917  if ((_Vals!=-1)&&(_Vals>=Vals)){
1918  return;
1919  } else
1920  if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){
1921  if (ValT!=NULL){delete[] ValT;}
1922  MxVals=Vals=0; ValT=NULL;
1923  } else {
1924  if (_Vals==-1){
1925  if (MxVals==Vals){return;} else {MxVals=Vals;}
1926  } else {
1927  MxVals=Vals=_Vals;
1928  }
1929  TVal* NewValT=new TVal[MxVals];
1930  IAssert(NewValT!=NULL);
1931  for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1932  delete[] ValT; ValT=NewValT;
1933  }
1934 }
1935 
1936 template <class TVal>
1938  IAssert(MxVals!=-1);
1939  if (Vals==0){
1940  if (ValT!=NULL){delete[] ValT;} ValT=NULL;
1941  } else
1942  if (Vals<MxVals){
1943  MxVals=Vals;
1944  TVal* NewValT=new TVal[MxVals];
1945  IAssert(NewValT!=NULL);
1946  for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1947  delete[] ValT; ValT=NewValT;
1948  }
1949 }
1950 
1951 template <class TVal>
1953  if (this!=&Vec){
1954  if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
1955  MxVals=Vec.MxVals; Vals=Vec.Vals; ValT=Vec.ValT;
1956  Vec.MxVals=0; Vec.Vals=0; Vec.ValT=NULL;
1957  }
1958 }
1959 
1960 template <class TVal>
1962  if (this!=&Vec){
1963  ::Swap(MxVals, Vec.MxVals);
1964  ::Swap(Vals, Vec.Vals);
1965  ::Swap(ValT, Vec.ValT);
1966  }
1967 }
1968 
1969 template <class TVal>
1970 int TVec<TVal>::AddV(const TVec<TVal>& ValV){
1971  Assert(MxVals!=-1);
1972  for (int ValN=0; ValN<ValV.Vals; ValN++){Add(ValV[ValN]);}
1973  return Len();
1974 }
1975 
1976 template <class TVal>
1977 int TVec<TVal>::AddSorted(const TVal& Val, const bool& Asc, const int& _MxVals){
1978  Assert(MxVals!=-1);
1979  int ValN=Add(Val);
1980  if (Asc){
1981  while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){
1982  Swap(ValN, ValN-1); ValN--;}
1983  } else {
1984  while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){
1985  Swap(ValN, ValN-1); ValN--;}
1986  }
1987  if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);}
1988  return ValN;
1989 }
1990 
1991 template <class TVal>
1992 int TVec<TVal>::AddBackSorted(const TVal& Val, const bool& Asc){
1993  Assert(MxVals!=-1);
1994  Add();
1995  int ValN=Vals-2;
1996  while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
1997  ValT[ValN+1]=ValT[ValN]; ValN--;}
1998  ValT[ValN+1]=Val;
1999  return ValN+1;
2000 }
2001 
2002 template <class TVal>
2003 int TVec<TVal>::AddMerged(const TVal& Val){
2004  Assert(MxVals!=-1);
2005  int ValN=SearchBin(Val);
2006  if (ValN==-1){return AddSorted(Val);}
2007  else {GetVal(ValN)=Val; return -1;}
2008 }
2009 
2010 template <class TVal>
2012  Assert(MxVals!=-1);
2013  for (int ValN=0; ValN<ValV.Vals; ValN++){AddMerged(ValV[ValN]);}
2014  return Len();
2015 }
2016 
2017 template <class TVal>
2018 int TVec<TVal>::AddUnique(const TVal& Val){
2019  Assert(MxVals!=-1);
2020  int ValN=SearchForw(Val);
2021  if (ValN==-1){return Add(Val);}
2022  else {GetVal(ValN)=Val; return -1;}
2023 }
2024 
2025 template <class TVal>
2027  const int& _BValN, const int& _EValN, TVec<TVal>& SubValV) const {
2028  int BValN=TInt::GetInRng(_BValN, 0, Len()-1);
2029  int EValN=TInt::GetInRng(_EValN, 0, Len()-1);
2030  int SubVals=TInt::GetMx(0, EValN-BValN+1);
2031  SubValV.Gen(SubVals, 0);
2032  for (int ValN=BValN; ValN<=EValN; ValN++){
2033  SubValV.Add(GetVal(ValN));}
2034 }
2035 
2036 template <class TVal>
2037 void TVec<TVal>::Ins(const int& ValN, const TVal& Val){
2038  Assert(MxVals!=-1);
2039  Add(); Assert((0<=ValN)&&(ValN<Vals));
2040  for (int MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
2041  ValT[ValN]=Val;
2042 }
2043 
2044 template <class TVal>
2045 void TVec<TVal>::Del(const int& ValN){
2046  Assert(MxVals!=-1);
2047  Assert((0<=ValN)&&(ValN<Vals));
2048  for (int MValN=ValN+1; MValN<Vals; MValN++){
2049  ValT[MValN-1]=ValT[MValN];}
2050  ValT[--Vals]=TVal();
2051 }
2052 
2053 template <class TVal>
2054 void TVec<TVal>::Del(const int& MnValN, const int& MxValN){
2055  Assert(MxVals!=-1);
2056  Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
2057  Assert(MnValN<=MxValN);
2058  for (int ValN=MxValN+1; ValN<Vals; ValN++){
2059  ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
2060  for (int ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
2061  ValT[ValN]=TVal();}
2062  Vals-=MxValN-MnValN+1;
2063 }
2064 
2065 template <class TVal>
2066 bool TVec<TVal>::DelIfIn(const TVal& Val){
2067  Assert(MxVals!=-1);
2068  int ValN=SearchForw(Val);
2069  if (ValN!=-1){Del(ValN); return true;}
2070  else {return false;}
2071 }
2072 
2073 template <class TVal>
2074 void TVec<TVal>::DelAll(const TVal& Val){
2075  Assert(MxVals!=-1);
2076  int ValN;
2077  while ((ValN=SearchForw(Val))!=-1){
2078  Del(ValN);}
2079 }
2080 
2081 template <class TVal>
2082 void TVec<TVal>::PutAll(const TVal& Val){
2083  for (int ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
2084 }
2085 
2086 template <class TVal>
2088  const int& MnLValN, const int& MxRValN, const bool& Asc){
2089  for (int ValN1=MnLValN; ValN1<=MxRValN; ValN1++){
2090  for (int ValN2=MxRValN; ValN2>ValN1; ValN2--){
2091  if (Asc){
2092  if (ValT[ValN2]<ValT[ValN2-1]){Swap(ValN2, ValN2-1);}
2093  } else {
2094  if (ValT[ValN2]>ValT[ValN2-1]){Swap(ValN2, ValN2-1);}
2095  }
2096  }
2097  }
2098 }
2099 
2100 template <class TVal>
2102  const int& MnLValN, const int& MxRValN, const bool& Asc){
2103  if (MnLValN<MxRValN){
2104  for (int ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){
2105  TVal Val=ValT[ValN1]; int ValN2=ValN1;
2106  if (Asc){
2107  while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){
2108  ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
2109  } else {
2110  while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){
2111  ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
2112  }
2113  ValT[ValN2]=Val;
2114  }
2115  }
2116 }
2117 
2118 template <class TVal>
2119 int TVec<TVal>::GetPivotValN(const int& LValN, const int& RValN) const {
2120  int SubVals=RValN-LValN+1;
2121  int ValN1=LValN+TInt::GetRnd(SubVals);
2122  int ValN2=LValN+TInt::GetRnd(SubVals);
2123  int ValN3=LValN+TInt::GetRnd(SubVals);
2124  const TVal& Val1=ValT[ValN1];
2125  const TVal& Val2=ValT[ValN2];
2126  const TVal& Val3=ValT[ValN3];
2127  if (Val1<Val2){
2128  if (Val2<Val3){return ValN2;}
2129  else if (Val3<Val1){return ValN1;}
2130  else {return ValN3;}
2131  } else {
2132  if (Val1<Val3){return ValN1;}
2133  else if (Val3<Val2){return ValN2;}
2134  else {return ValN3;}
2135  }
2136 }
2137 
2138 template <class TVal>
2140  const int& MnLValN, const int& MxRValN, const bool& Asc){
2141  int PivotValN=GetPivotValN(MnLValN, MxRValN);
2142  Swap(PivotValN, MnLValN);
2143  TVal PivotVal=ValT[MnLValN];
2144  int LValN=MnLValN-1; int RValN=MxRValN+1;
2145  forever {
2146  if (Asc){
2147  do {RValN--;} while (ValT[RValN]>PivotVal);
2148  do {LValN++;} while (ValT[LValN]<PivotVal);
2149  } else {
2150  do {RValN--;} while (ValT[RValN]<PivotVal);
2151  do {LValN++;} while (ValT[LValN]>PivotVal);
2152  }
2153  if (LValN<RValN){Swap(LValN, RValN);}
2154  else {return RValN;}
2155  };
2156 }
2157 
2158 template <class TVal>
2160  const int& MnLValN, const int& MxRValN, const bool& Asc){
2161  if (MnLValN<MxRValN){
2162  if (MxRValN-MnLValN<20){
2163  ISort(MnLValN, MxRValN, Asc);
2164  } else {
2165  int SplitValN=Partition(MnLValN, MxRValN, Asc);
2166  QSort(MnLValN, SplitValN, Asc);
2167  QSort(SplitValN+1, MxRValN, Asc);
2168  }
2169  }
2170 }
2171 
2172 template <class TVal>
2173 void TVec<TVal>::Sort(const bool& Asc){
2174  QSort(0, Len()-1, Asc);
2175 }
2176 
2177 template <class TVal>
2178 bool TVec<TVal>::IsSorted(const bool& Asc) const {
2179  if (Asc){
2180  for (int ValN=0; ValN<Vals-1; ValN++){
2181  if (ValT[ValN]>ValT[ValN+1]){return false;}}
2182  } else {
2183  for (int ValN=0; ValN<Vals-1; ValN++){
2184  if (ValT[ValN]<ValT[ValN+1]){return false;}}
2185  }
2186  return true;
2187 }
2188 
2189 template <class TVal>
2191  for (int ValN=0; ValN<Vals-1; ValN++){
2192  Swap(ValN, ValN+Rnd.GetUniDevInt(Vals-ValN));}
2193 }
2194 
2195 template <class TVal>
2197  for (int ValN=0; ValN<Vals/2; ValN++){
2198  Swap(ValN, Vals-ValN-1);}
2199 }
2200 
2201 template <class TVal>
2203  Assert(MxVals!=-1);
2204  TVec<TVal> SortedVec(*this); SortedVec.Sort();
2205  Clr();
2206  for (int ValN=0; ValN<SortedVec.Len(); ValN++){
2207  if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){
2208  Add(SortedVec[ValN]);}
2209  }
2210 }
2211 
2212 template <class TVal>
2214  // start with a sorted sequence to obtain all permutations
2215  int First = 0, Last = Len(), Next = Len()-1;
2216  if (Last < 2) return false;
2217  for(; ; ) {
2218  // find rightmost element smaller than successor
2219  int Next1 = Next;
2220  if (GetVal(--Next) < GetVal(Next1)) { // swap with rightmost element that's smaller, flip suffix
2221  int Mid = Last;
2222  for (; GetVal(Next) >= GetVal(--Mid); ) { }
2223  Swap(Next, Mid);
2224  Reverse(Next1, Last);
2225  return true;
2226  }
2227  if (Next == First) { // pure descending, flip all
2228  Reverse();
2229  return false;
2230  }
2231  }
2232 }
2233 
2234 template <class TVal>
2236  int First = 0, Last = Len(), Next = Len()-1;
2237  if (Last < 2) return false;
2238  for(; ; ) {
2239  // find rightmost element not smaller than successor
2240  int Next1 = Next;
2241  if (GetVal(--Next) >= GetVal(Next1)) { // swap with rightmost element that's not smaller, flip suffix
2242  int Mid = Last;
2243  for (; GetVal(Next) < GetVal(--Mid); ) { }
2244  Swap(Next, Mid);
2245  Reverse(Next1, Last);
2246  return true;
2247  }
2248  if (Next == First) { // pure descending, flip all
2249  Reverse();
2250  return false;
2251  }
2252  }
2253 }
2254 
2255 template <class TVal>
2256 void TVec<TVal>::Intrs(const TVec<TVal>& ValV){
2257  TVec<TVal> IntrsVec;
2258  Intrs(ValV, IntrsVec);
2259  MoveFrom(IntrsVec);
2260 }
2261 
2262 template <class TVal>
2263 void TVec<TVal>::Union(const TVec<TVal>& ValV){
2264  TVec<TVal> UnionVec;
2265  Union(ValV, UnionVec);
2266  MoveFrom(UnionVec);
2267 }
2268 
2269 template <class TVal>
2270 void TVec<TVal>::Diff(const TVec<TVal>& ValV){
2271  TVec<TVal> DiffVec;
2272  Diff(ValV, DiffVec);
2273  MoveFrom(DiffVec);
2274 }
2275 
2276 template <class TVal>
2277 void TVec<TVal>::Minus(const TVec<TVal>& ValV){
2278  TVec<TVal> MinusVec;
2279  Minus(ValV, MinusVec);
2280  MoveFrom(MinusVec);
2281 }
2282 
2283 template <class TVal>
2284 void TVec<TVal>::Intrs(const TVec<TVal>& ValV, TVec<TVal>& DstValV) const {
2285  DstValV.Clr();
2286  int ValN1=0; int ValN2=0;
2287  while ((ValN1<Len())&&(ValN2<ValV.Len())){
2288  const TVal& Val1=GetVal(ValN1);
2289  while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){
2290  ValN2++;}
2291  if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){
2292  DstValV.Add(Val1); ValN2++;}
2293  ValN1++;
2294  }
2295 }
2296 
2297 template <class TVal>
2298 void TVec<TVal>::Union(const TVec<TVal>& ValV, TVec<TVal>& DstValV) const {
2299  DstValV.Gen(TInt::GetMx(Len(), ValV.Len()), 0);
2300  int ValN1=0; int ValN2=0;
2301  while ((ValN1<Len())&&(ValN2<ValV.Len())){
2302  const TVal& Val1=GetVal(ValN1);
2303  const TVal& Val2=ValV.GetVal(ValN2);
2304  if (Val1<Val2){DstValV.Add(Val1); ValN1++;}
2305  else if (Val1>Val2){DstValV.Add(Val2); ValN2++;}
2306  else {DstValV.Add(Val1); ValN1++; ValN2++;}
2307  }
2308  for (int RestValN1=ValN1; RestValN1<Len(); RestValN1++){
2309  DstValV.Add(GetVal(RestValN1));}
2310  for (int RestValN2=ValN2; RestValN2<ValV.Len(); RestValN2++){
2311  DstValV.Add(ValV.GetVal(RestValN2));}
2312 }
2313 
2314 /*
2315 template <class TVal>
2316 void TVec<TVal>::Union(const TVec<TVal>& ValV, TVec<TVal>& DstValV){
2317  DstValV.Clr();
2318  int ValN1=0; int ValN2=0;
2319  while ((ValN1<Len())&&(ValN2<ValV.Len())){
2320  const TVal& Val1=GetVal(ValN1);
2321  const TVal& Val2=ValV.GetVal(ValN2);
2322  if (DstValV.Len()==0){
2323  if (Val1<Val2){DstValV.Add(Val1);} else {DstValV.Add(Val2);}
2324  } else {
2325  if (Val1<Val2){
2326  if (DstValV.Last()<Val1){DstValV.Add(Val1);} ValN1++;
2327  } else {
2328  if (DstValV.Last()<Val2){DstValV.Add(Val2);} ValN2++;
2329  }
2330  }
2331  }
2332  for (int RestValN1=ValN1; RestValN1<Len(); RestValN1++){
2333  const TVal& Val1=GetVal(RestValN1);
2334  if (DstValV.Len()==0){DstValV.Add(Val1);}
2335  else {if (DstValV.Last()<Val1){DstValV.Add(Val1);}}
2336  }
2337  for (int RestValN2=ValN2; RestValN2<ValV.Len(); RestValN2++){
2338  const TVal& Val2=ValV.GetVal(RestValN2);
2339  if (DstValV.Len()==0){DstValV.Add(Val2);}
2340  else {if (DstValV.Last()<Val2){DstValV.Add(Val2);}}
2341  }
2342 }
2343 */
2344 
2345 template <class TVal>
2346 void TVec<TVal>::Diff(const TVec<TVal>& ValV, TVec<TVal>& DstValV) const {
2347  DstValV.Clr();
2348  int ValN1=0; int ValN2=0;
2349  while (ValN1<Len() && ValN2<ValV.Len()) {
2350  const TVal& Val1 = GetVal(ValN1);
2351  while (ValN2<ValV.Len() && Val1>ValV.GetVal(ValN2)) ValN2++;
2352  if (ValN2<ValV.Len()) {
2353  if (Val1!=ValV.GetVal(ValN2)) { DstValV.Add(Val1); }
2354  ValN1++;
2355  }
2356  }
2357  for (int RestValN1=ValN1; RestValN1<Len(); RestValN1++){
2358  DstValV.Add(GetVal(RestValN1));}
2359 }
2360 
2361 template <class TVal>
2362 int TVec<TVal>::IntrsLen(const TVec<TVal>& ValV) const {
2363  int Cnt=0, ValN1=0; int ValN2=0;
2364  while ((ValN1<Len())&&(ValN2<ValV.Len())){
2365  const TVal& Val1=GetVal(ValN1);
2366  while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){
2367  ValN2++;}
2368  if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){
2369  ValN2++; Cnt++;}
2370  ValN1++;
2371  }
2372  return Cnt;
2373 }
2374 
2375 template <class TVal>
2376 int TVec<TVal>::UnionLen(const TVec<TVal>& ValV) const {
2377  int Cnt = 0, ValN1 = 0, ValN2 = 0;
2378  while ((ValN1 < Len()) && (ValN2 < ValV.Len())) {
2379  const TVal& Val1 = GetVal(ValN1);
2380  const TVal& Val2 = ValV.GetVal(ValN2);
2381  if (Val1 < Val2) {
2382  Cnt++; ValN1++;
2383  } else if (Val1 > Val2) {
2384  Cnt++; ValN2++;
2385  } else {
2386  Cnt++; ValN1++; ValN2++;
2387  }
2388  }
2389  Cnt += (Len() - ValN1) + (ValV.Len() - ValN2);
2390  return Cnt;
2391 }
2392 
2393 template <class TVal>
2394 void TVec<TVal>::Minus(const TVec<TVal>& ValV, TVec<TVal>& DstValV) const {
2395  Diff(ValV, DstValV);
2396 }
2397 
2398 template <class TVal>
2399 int TVec<TVal>::Count(const TVal& Val) const {
2400  int Count = 0;
2401  for (int i = 0; i < Len(); i++){
2402  if (Val == ValT[i]){Count++;}}
2403  return Count;
2404 }
2405 
2406 template <class TVal>
2407 int TVec<TVal>::SearchBin(const TVal& Val) const {
2408  int LValN=0; int RValN=Len()-1;
2409  while (RValN>=LValN){
2410  int ValN=(LValN+RValN)/2;
2411  if (Val==ValT[ValN]){return ValN;}
2412  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
2413  }
2414  return -1;
2415 }
2416 
2417 template <class TVal>
2418 int TVec<TVal>::SearchBin(const TVal& Val, int& InsValN) const {
2419  int LValN=0; int RValN=Len()-1;
2420  while (RValN>=LValN){
2421  int ValN=(LValN+RValN)/2;
2422  if (Val==ValT[ValN]){InsValN=ValN; return ValN;}
2423  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
2424  }
2425  InsValN=LValN; return -1;
2426 }
2427 
2428 template <class TVal>
2429 int TVec<TVal>::SearchForw(const TVal& Val, const int& BValN) const {
2430  for (int ValN=BValN; ValN<Vals; ValN++){
2431  if (Val==ValT[ValN]){return ValN;}}
2432  return -1;
2433 }
2434 
2435 template <class TVal>
2436 int TVec<TVal>::SearchBack(const TVal& Val) const {
2437  for (int ValN=Vals-1; ValN>=0; ValN--){
2438  if (Val==ValT[ValN]){return ValN;}}
2439  return -1;
2440 }
2441 
2442 template <class TVal>
2443 int TVec<TVal>::SearchVForw(const TVec<TVal>& ValV, const int& BValN) const {
2444  int ValVLen=ValV.Len();
2445  for (int ValN=BValN; ValN<Vals-ValVLen+1; ValN++){
2446  bool Found=true;
2447  for (int SubValN=0; SubValN<ValVLen; SubValN++){
2448  if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=false; break;}
2449  }
2450  if (Found){return ValN;}
2451  }
2452  return -1;
2453 }
2454 
2455 template <class TVal>
2457  if (Vals==0){return -1;}
2458  int MxValN=0;
2459  for (int ValN=1; ValN<Vals; ValN++){
2460  if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
2461  }
2462  return MxValN;
2463 }
2464 
2465 }; // namespace TGLib_OLD
2466 
2468 // Common-Vector-Types
2469 typedef TVec<TBool> TBoolV;
2470 typedef TVec<TCh> TChV;
2501 typedef TVec<TIntKd> TIntKdV;
2543 
2544 //#//////////////////////////////////////////////
2546 
2549 template <class TVal, class TSizeTy=int>
2550 class TVecPool {
2551 public:
2554 private:
2558  TVal EmptyVal; // Empty value/vector
2559  TVal *ValBf; // Buffer for storing all the values
2560  TVec<uint64, int> IdToOffV; // Id to one past last (Vector starts at [id-1]). Vector length is IdToOff[id]-IdToOff[id-1]
2561 private:
2562  void Resize(const TSize& _MxVals);
2563 public:
2565 
2570  TVecPool(const TSize& ExpectVals=0, const TSize& _GrowBy=1000000, const bool& _FastCopy=false, const TVal& _EmptyVal=TVal());
2571  TVecPool(const TVecPool<TVal, TSizeTy>& Pool);
2572  TVecPool(TSIn& SIn);
2573  ~TVecPool() { if (ValBf != NULL) { delete [] ValBf; } ValBf=NULL; }
2574  static PVecPool New(const TSize& ExpectVals=0, const TSize& GrowBy=1000000, const bool& FastCopy=false) {
2575  return new TVecPool(ExpectVals, GrowBy, FastCopy); }
2576  static PVecPool Load(TSIn& SIn) { return new TVecPool(SIn); }
2577  static PVecPool Load(const TStr& FNm) { TFIn FIn(FNm); return Load(FIn); }
2578  void Save(TSOut& SOut) const;
2579  TVecPool& operator = (const TVecPool& Pool);
2580 
2582  int GetVecs() const { return IdToOffV.Len(); }
2584  TSize GetVals() const { return Vals; }
2586  bool IsVId(const int& VId) const { return (0 <= VId) && (VId < IdToOffV.Len()); }
2588  uint64 Reserved() const { return MxVals; }
2590  void Reserve(const TSize& MxVals) { Resize(MxVals); }
2592  const TVal& GetEmptyVal() const { return EmptyVal; }
2594  void SetEmptyVal(const TVal& _EmptyVal) { EmptyVal = _EmptyVal; }
2596  uint64 GetMemUsed() const {
2597  return sizeof(TCRef)+sizeof(TBool)+3*sizeof(TSize)+sizeof(TVal*)+MxVals*sizeof(TVal);}
2598 
2600  int AddV(const TValV& ValV);
2602 
2604  int AddEmptyV(const int& ValVLen);
2606  int GetVLen(const int& VId) const { if (VId==0){return 0;} else {return int(IdToOffV[VId]-IdToOffV[VId-1]);}}
2608  TVal* GetValVPt(const int& VId) const {
2609  if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
2610  else {return ValBf+IdToOffV[VId-1];}}
2612 
2614  void GetV(const int& VId, TValV& ValV) const {
2615  if (GetVLen(VId)==0){ValV.Clr();}
2616  else { ValV.GenExt(GetValVPt(VId), GetVLen(VId)); } }
2618  void PutV(const int& VId, const TValV& ValV) {
2619  IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
2620  if (FastCopy) {
2621  memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
2622  else { TVal* ValPt = GetValVPt(VId);
2623  for (::TSize ValN=0; ValN < ::TSize(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
2624  } }
2626 
2628  void CompactPool(const TVal& DelVal);
2630 
2632  void ShuffleAll(TRnd& Rnd=TInt::Rnd);
2633 
2635 
2637  void Clr(bool DoDel = true) {
2638  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
2639  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
2640  if (! DoDel) { PutAll(EmptyVal); } }
2642  void PutAll(const TVal& Val) {
2643  for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }
2644  friend class TPt<TVecPool<TVal> >;
2645 };
2646 
2647 template <class TVal, class TSizeTy>
2649  if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
2650  if (ValBf == NULL) {
2651  try { ValBf = new TVal [MxVals]; }
2652  catch (std::exception Ex) {
2653  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()); }
2654  IAssert(ValBf != NULL);
2655  if (EmptyVal != TVal()) { PutAll(EmptyVal); }
2656  } else {
2657  // printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
2658  TVal* NewValBf = NULL;
2659  try { NewValBf = new TVal [MxVals]; }
2660  catch (std::exception Ex) {
2661  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()); }
2662  IAssert(NewValBf != NULL);
2663  if (FastCopy) {
2664  memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
2665  else {
2666  for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
2667  if (EmptyVal != TVal()) { // init empty values
2668  for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
2669  }
2670  delete [] ValBf;
2671  ValBf = NewValBf;
2672  }
2673 }
2674 
2675 template <class TVal, class TSizeTy>
2676 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) {
2677  IdToOffV.Add(0);
2678  Resize(ExpectVals);
2679 }
2680 
2681 template <class TVal, class TSizeTy>
2682 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) {
2683  try {
2684  ValBf = new TVal [MxVals]; }
2685  catch (std::exception Ex) {
2686  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()); }
2687  IAssert(ValBf != NULL);
2688  if (FastCopy) {
2689  memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); }
2690  else {
2691  for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
2692 }
2693 
2694 template <class TVal, class TSizeTy>
2696  uint64 _GrowBy, _MxVals, _Vals;
2697  SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals);
2698  IAssertR(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx, "This is a 64-bit vector pool. Use a 64-bit compiler.");
2699  GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals
2700  EmptyVal = TVal(SIn);
2701  if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; }
2702  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
2703  { TInt MxVals(SIn), Vals(SIn);
2704  IdToOffV.Gen(Vals);
2705  for (int ValN = 0; ValN < Vals; ValN++) {
2706  uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx);
2707  IdToOffV[ValN]=TSize(Offset);
2708  } }
2709 }
2710 
2711 template <class TVal, class TSizeTy>
2713  SOut.Save(FastCopy);
2714  uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2715  SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
2716  SOut.Save(EmptyVal);
2717  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2718  { SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
2719  for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
2720  const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
2721  } }
2722 }
2723 
2724 template <class TVal, class TSizeTy>
2726  if (this!=&Pool) {
2727  FastCopy = Pool.FastCopy;
2728  GrowBy = Pool.GrowBy;
2729  MxVals = Pool.MxVals;
2730  Vals = Pool.Vals;
2731  EmptyVal = Pool.EmptyVal;
2732  IdToOffV=Pool.IdToOffV;
2733  try {
2734  ValBf = new TVal [MxVals]; }
2735  catch (std::exception Ex) {
2736  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()); }
2737  IAssert(ValBf != NULL);
2738  if (FastCopy) {
2739  memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
2740  else {
2741  for (TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
2742  }
2743  return *this;
2744 }
2745 
2746 template <class TVal, class TSizeTy>
2748  const TSizeTy ValVLen = ValV.Len();
2749  if (ValVLen == 0) { return 0; }
2750  if (MxVals < Vals+ValVLen) { Resize(Vals+max(ValVLen, GrowBy)); }
2751  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
2752  else { for (uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2753  Vals+=ValVLen; IdToOffV.Add(Vals);
2754  return IdToOffV.Len()-1;
2755 }
2756 
2757 template <class TVal, class TSizeTy>
2758 int TVecPool<TVal, TSizeTy>::AddEmptyV(const int& ValVLen) {
2759  if (ValVLen==0){return 0;}
2760  if (MxVals < Vals+ValVLen){Resize(Vals+max(TSize(ValVLen), GrowBy)); }
2761  Vals+=ValVLen; IdToOffV.Add(Vals);
2762  return IdToOffV.Len()-1;
2763 }
2764 
2765 // Delete all elements of value DelVal from all vectors. Empty space is left at the end of the pool.
2766 template <class TVal, class TSizeTy>
2767 void TVecPool<TVal, TSizeTy>::CompactPool(const TVal& DelVal) {
2768  ::TSize TotalDel=0, NDel=0;
2769  // printf("Compacting %d vectors\n", IdToOffV.Len());
2770  for (int vid = 1; vid < IdToOffV.Len(); vid++) {
2771  // if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
2772  const uint Len = GetVLen(vid);
2773  TVal* ValV = GetValVPt(vid);
2774  if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
2775  if (Len == 0) { continue; }
2776  NDel = 0;
2777  for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
2778  if (*v == DelVal) {
2779  TVal* Beg = v;
2780  while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
2781  memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
2782  v -= NDel;
2783  }
2784  }
2785  memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
2786  TotalDel += NDel;
2787  }
2788  IdToOffV.Last() -= TotalDel;
2789  for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
2790  Vals -= TotalDel;
2791  // printf(" deleted %llu elements from the pool\n", TotalDel);
2792 }
2793 
2794 // shuffles all the order of elements in the pool (does not respect vector boundaries)
2795 template <class TVal, class TSizeTy>
2797  for (::TSize n = Vals-1; n > 0; n--) {
2798  const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
2799  const TVal Tmp = ValBf[n];
2800  ValBf[n] = ValBf[k];
2801  ValBf[k] = Tmp;
2802  }
2803 }
2804 
2805 
2807 // Below are old 32-bit implementations of TVec and other classes.
2808 // Old TVec takes at most 2G elements.
2809 // The new vector class supports 64-bits for the number of elements,
2810 // but also allows 32-bits for backward compatibility.
2811 // by Jure (Jan 2013)
2812 namespace TGLib_OLD {
2814 // Vector Pool
2815 template<class TVal>
2816 class TVecPool {
2817 public:
2820 private:
2824  TVal EmptyVal; // empty vector
2825  TVal *ValBf; // buffer storing all the values
2826  TVec< ::TSize> IdToOffV; // id to one past last (vector starts at [id-1])
2827 private:
2828  void Resize(const ::TSize& _MxVals);
2829 public:
2830  TVecPool(const ::TSize& ExpectVals=0, const ::TSize& _GrowBy=1000000, const bool& _FastCopy=false, const TVal& _EmptyVal=TVal());
2831  TVecPool(const TVecPool& Pool);
2832  TVecPool(TSIn& SIn);
2833  ~TVecPool() { if (ValBf != NULL) { delete [] ValBf; } ValBf=NULL; }
2834  static PVecPool New(const ::TSize& ExpectVals=0, const ::TSize& GrowBy=1000000, const bool& FastCopy=false) {
2835  return new TVecPool(ExpectVals, GrowBy, FastCopy); }
2836  static PVecPool Load(TSIn& SIn) { return new TVecPool(SIn); }
2837  static PVecPool Load(const TStr& FNm) { TFIn FIn(FNm); return Load(FIn); }
2838  void Save(TSOut& SOut) const;
2839 
2840  TVecPool& operator = (const TVecPool& Pool);
2841 
2842  ::TSize GetVals() const { return Vals; }
2843  ::TSize GetVecs() const { return IdToOffV.Len(); }
2844  bool IsVId(const int& VId) const { return (0 <= VId) && (VId < IdToOffV.Len()); }
2845  ::TSize Reserved() const { return MxVals; }
2846  void Reserve(const ::TSize& MxVals) { Resize(MxVals); }
2847  const TVal& GetEmptyVal() const { return EmptyVal; }
2848  void SetEmptyVal(const TVal& _EmptyVal) { EmptyVal = _EmptyVal; }
2850  return sizeof(TCRef)+sizeof(TBool)+3*sizeof(TSize)+sizeof(TVal*)+MxVals*sizeof(TVal);}
2851 
2852  int AddV(const TValV& ValV);
2853  int AddEmptyV(const int& ValVLen);
2854  uint GetVLen(const int& VId) const {
2855  if (VId==0){return 0;}
2856  else {return uint(IdToOffV[VId]-IdToOffV[VId-1]);}}
2857  TVal* GetValVPt(const int& VId) const {
2858  if (GetVLen(VId)==0){return (TVal*)&EmptyVal;}
2859  else {return ValBf+IdToOffV[VId-1];}}
2860  void GetV(const int& VId, TValV& ValV) const {
2861  if (GetVLen(VId)==0){ValV.Clr();}
2862  else { ValV.GenExt(GetValVPt(VId), GetVLen(VId)); } }
2863  void PutV(const int& VId, const TValV& ValV) {
2864  IAssert(IsVId(VId) && GetVLen(VId) == ValV.Len());
2865  if (FastCopy) {
2866  memcpy(GetValVPt(VId), ValV.BegI(), sizeof(TVal)*ValV.Len()); }
2867  else { TVal* ValPt = GetValVPt(VId);
2868  for (uint ValN=0; ValN < uint(ValV.Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
2869  }
2870  }
2871  void CompactPool(const TVal& DelVal); // delete all elements of value DelVal from all vectors
2872  void ShuffleAll(TRnd& Rnd=TInt::Rnd); // shuffles all the order of elements in the Pool (does not respect vector boundaries)
2873 
2874  //bool HasIdMap() const { return ! IdToOffV.Empty(); }
2875  //void ClrIdMap() { IdToOffV.Clr(true); }
2876  void Clr(bool DoDel = true) {
2877  IdToOffV.Clr(DoDel); MxVals=0; Vals=0;
2878  if (DoDel && ValBf!=NULL) { delete [] ValBf; ValBf=NULL;}
2879  if (! DoDel) { PutAll(EmptyVal); }
2880  }
2881  void PutAll(const TVal& Val) {
2882  for (TSize ValN = 0; ValN < MxVals; ValN++) { ValBf[ValN]=Val; } }
2883 
2884  friend class TPt<TVecPool<TVal> >;
2885 };
2886 
2887 template <class TVal>
2889  if (_MxVals <= MxVals){ return; } else { MxVals = _MxVals; }
2890  if (ValBf == NULL) {
2891  try { ValBf = new TVal [MxVals]; }
2892  catch (std::exception Ex) {
2893  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()); }
2894  IAssert(ValBf != NULL);
2895  if (EmptyVal != TVal()) { PutAll(EmptyVal); }
2896  } else {
2897  // printf("*** Resize vector pool: %llu -> %llu\n", uint64(Vals), uint64(MxVals));
2898  TVal* NewValBf = NULL;
2899  try { NewValBf = new TVal [MxVals]; }
2900  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()); }
2901  IAssert(NewValBf != NULL);
2902  if (FastCopy) {
2903  memcpy(NewValBf, ValBf, Vals*sizeof(TVal)); }
2904  else {
2905  for (TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
2906  if (EmptyVal != TVal()) { // init empty values
2907  for (TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
2908  }
2909  delete [] ValBf;
2910  ValBf = NewValBf;
2911  }
2912 }
2913 
2914 template <class TVal>
2915 TVecPool<TVal>::TVecPool(const ::TSize& ExpectVals, const ::TSize& _GrowBy, const bool& _FastCopy, const TVal& _EmptyVal) :
2916  GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
2917  IdToOffV.Add(0);
2918  Resize(ExpectVals);
2919 }
2920 
2921 template <class TVal>
2923  FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy),
2924  MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
2925  try { ValBf = new TVal [MxVals]; }
2926  catch (std::exception Ex) { FailR(TStr::Fmt("TVecPool::TVecPool: %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
2927  IAssert(ValBf != NULL);
2928  if (FastCopy) {
2929  memcpy(ValBf, Pool.ValBf, MxVals*sizeof(TVal)); }
2930  else {
2931  for (TSize ValN = 0; ValN < MxVals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
2932 }
2933 
2934 template <class TVal>
2936  FastCopy(SIn) {
2937  uint64 _GrowBy, _MxVals, _Vals;
2938  SIn.Load(_GrowBy); SIn.Load(_MxVals); SIn.Load(_Vals);
2939  IAssert(_GrowBy<TSizeMx && _MxVals<TSizeMx && _Vals<TSizeMx);
2940  GrowBy=TSize(_GrowBy); MxVals=TSize(_Vals); Vals=TSize(_Vals); //note MxVals==Vals
2941  EmptyVal = TVal(SIn);
2942  if (MxVals==0) { ValBf = NULL; } else { ValBf = new TVal [MxVals]; }
2943  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
2944  { TInt MxVals(SIn), Vals(SIn);
2945  IdToOffV.Gen(Vals);
2946  for (int ValN = 0; ValN < Vals; ValN++) {
2947  uint64 Offset; SIn.Load(Offset); IAssert(Offset < TSizeMx);
2948  IdToOffV[ValN]=TSize(Offset);
2949  } }
2950 }
2951 
2952 template <class TVal>
2953 void TVecPool<TVal>::Save(TSOut& SOut) const {
2954  SOut.Save(FastCopy);
2955  uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2956  SOut.Save(_GrowBy); SOut.Save(_MxVals); SOut.Save(_Vals);
2957  SOut.Save(EmptyVal);
2958  for (TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2959  { SOut.Save(IdToOffV.Len()); SOut.Save(IdToOffV.Len());
2960  for (int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
2961  const uint64 Offset=IdToOffV[ValN]; SOut.Save(Offset);
2962  } }
2963 }
2964 
2965 template <class TVal>
2967  if (this!=&Pool) {
2968  FastCopy = Pool.FastCopy;
2969  GrowBy = Pool.GrowBy;
2970  MxVals = Pool.MxVals;
2971  Vals = Pool.Vals;
2972  EmptyVal = Pool.EmptyVal;
2973  IdToOffV=Pool.IdToOffV;
2974  try { ValBf = new TVal [MxVals]; }
2975  catch (std::exception Ex) { FailR(TStr::Fmt("TVec::operator= : %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
2976  IAssert(ValBf != NULL);
2977  if (FastCopy) {
2978  memcpy(ValBf, Pool.ValBf, Vals*sizeof(TVal)); }
2979  else {
2980  for (uint64 ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.ValBf[ValN]; } }
2981  }
2982  return *this;
2983 }
2984 
2985 template<class TVal>
2986 int TVecPool<TVal>::AddV(const TValV& ValV) {
2987  const ::TSize ValVLen = ValV.Len();
2988  if (ValVLen == 0) { return 0; }
2989  if (MxVals < Vals+ValVLen) { Resize(Vals+max(ValVLen, GrowBy)); }
2990  if (FastCopy) { memcpy(ValBf+Vals, ValV.BegI(), sizeof(TVal)*ValV.Len()); }
2991  else { for (uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2992  Vals+=ValVLen; IdToOffV.Add(Vals);
2993  return IdToOffV.Len()-1;
2994 }
2995 
2996 template<class TVal>
2997 int TVecPool<TVal>::AddEmptyV(const int& ValVLen) {
2998  if (ValVLen==0){return 0;}
2999  if (MxVals < Vals+ValVLen){Resize(Vals+max(TSize(ValVLen), GrowBy)); }
3000  Vals+=ValVLen; IdToOffV.Add(Vals);
3001  return IdToOffV.Len()-1;
3002 }
3003 
3004 // delete all elements of value DelVal from all vectors
3005 // empty space is left at the end of the pool
3006 template<class TVal>
3007 void TVecPool<TVal>::CompactPool(const TVal& DelVal) {
3008  ::TSize TotalDel=0, NDel=0;
3009  // printf("Compacting %d vectors\n", IdToOffV.Len());
3010  for (int vid = 1; vid < IdToOffV.Len(); vid++) {
3011  // if (vid % 10000000 == 0) { printf(" %dm", vid/1000000); fflush(stdout); }
3012  const uint Len = GetVLen(vid);
3013  TVal* ValV = GetValVPt(vid);
3014  if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; } // update end of vector
3015  if (Len == 0) { continue; }
3016  NDel = 0;
3017  for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
3018  if (*v == DelVal) {
3019  TVal* Beg = v;
3020  while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
3021  memcpy(Beg, v, sizeof(TVal)*int(Len - ::TSize(v - ValV)));
3022  v -= NDel;
3023  }
3024  }
3025  memcpy(ValV-TotalDel, ValV, sizeof(TVal)*Len); // move data
3026  TotalDel += NDel;
3027  }
3028  IdToOffV.Last() -= TotalDel;
3029  for (::TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
3030  Vals -= TotalDel;
3031  // printf(" deleted %llu elements from the pool\n", TotalDel);
3032 }
3033 
3034 // shuffles all the order of elements in the pool (does not respect vector boundaries)
3035 template<class TVal>
3037  for (::TSize n = Vals-1; n > 0; n--) {
3038  const ::TSize k = ::TSize(((uint64(Rnd.GetUniDevInt())<<32) | uint64(Rnd.GetUniDevInt())) % (n+1));
3039  const TVal Tmp = ValBf[n];
3040  ValBf[n] = ValBf[k];
3041  ValBf[k] = Tmp;
3042  }
3043 }
3044 
3045 }; // namespace TGLib_OLD
3046 
3047 typedef TVecPool<TInt> TIntVecPool;
3049 
3051 // Vector-Pointer
3052 template <class TVal>
3053 class PVec{
3054 private:
3056 public:
3058 public:
3059  PVec<TVal>(): V(){}
3060  PVec<TVal>(const PVec<TVal>& Vec): V(Vec.V){}
3061  static TPt<PVec<TVal> > New(){
3062  return new PVec<TVal>();}
3063  PVec<TVal>(const int& MxVals, const int& Vals): V(MxVals, Vals){}
3064  static TPt<PVec<TVal> > New(const int& MxVals, const int& Vals){
3065  return new PVec<TVal>(MxVals, Vals);}
3066  PVec<TVal>(const TVec<TVal>& _V): V(_V){}
3067  static TPt<PVec<TVal> > New(const TVec<TVal>& V){
3068  return new PVec<TVal>(V);}
3069  explicit PVec<TVal>(TSIn& SIn): V(SIn){}
3070  static TPt<PVec<TVal> > Load(TSIn& SIn){return new PVec<TVal>(SIn);}
3071  void Save(TSOut& SOut) const {V.Save(SOut);}
3072 
3074  if (this!=&Vec){V=Vec.V;} return *this;}
3075  bool operator==(const PVec<TVal>& Vec) const {return V==Vec.V;}
3076  bool operator<(const PVec<TVal>& Vec) const {return V<Vec.V;}
3077  TVal& operator[](const int& ValN) const {return V[ValN];}
3078 
3079  bool Empty() const {return V.Empty();}
3080  int Len() const {return V.Len();}
3081  TVal GetVal(const int& ValN) const {return V[ValN];}
3082 
3083  int Add(const TVal& Val){return V.Add(Val);}
3084 
3085  friend class TPt<PVec<TVal> >;
3086 };
3087 
3089 // Common-Vector-Pointer-Types
3096 
3098 // 2D-Vector
3099 template <class TVal>
3100 class TVVec{
3101 private:
3104 public:
3105  TVVec(): XDim(), YDim(), ValV(){}
3106  TVVec(const TVVec& Vec):
3107  XDim(Vec.XDim), YDim(Vec.YDim), ValV(Vec.ValV){}
3108  TVVec(const int& _XDim, const int& _YDim):
3109  XDim(), YDim(), ValV(){Gen(_XDim, _YDim);}
3110  explicit TVVec(const TVec<TVal>& _ValV, const int& _XDim, const int& _YDim):
3111  XDim(_XDim), YDim(_YDim), ValV(_ValV){ IAssert(ValV.Len()==XDim*YDim); }
3112  explicit TVVec(TSIn& SIn) {Load(SIn);}
3113  void Load(TSIn& SIn){XDim.Load(SIn); YDim.Load(SIn); ValV.Load(SIn);}
3114  void Save(TSOut& SOut) const {
3115  XDim.Save(SOut); YDim.Save(SOut); ValV.Save(SOut);}
3116 
3118  if (this!=&Vec){XDim=Vec.XDim; YDim=Vec.YDim; ValV=Vec.ValV;} return *this;}
3119  bool operator==(const TVVec& Vec) const {
3120  return (XDim==Vec.XDim)&&(YDim==Vec.YDim)&&(ValV==Vec.ValV);}
3121 
3122  bool Empty() const {return ValV.Len()==0;}
3123  void Clr(){XDim=0; YDim=0; ValV.Clr();}
3124  void Gen(const int& _XDim, const int& _YDim){
3125  Assert((_XDim>=0)&&(_YDim>=0));
3126  XDim=_XDim; YDim=_YDim; ValV.Gen(XDim*YDim);}
3127  int GetXDim() const {return XDim;}
3128  int GetYDim() const {return YDim;}
3129  int GetRows() const {return XDim;}
3130  int GetCols() const {return YDim;}
3132 
3133  const TVal& At(const int& X, const int& Y) const {
3134  Assert((0<=X)&&(X<int(XDim))&&(0<=Y)&&(Y<int(YDim)));
3135  return ValV[X*YDim+Y];}
3136  TVal& At(const int& X, const int& Y){
3137  Assert((0<=X)&&(X<int(XDim))&&(0<=Y)&&(Y<int(YDim)));
3138  return ValV[X*YDim+Y];}
3139  TVal& operator()(const int& X, const int& Y){
3140  return At(X, Y);}
3141  const TVal& operator()(const int& X, const int& Y) const {
3142  return At(X, Y);}
3143 
3144  void PutXY(const int& X, const int& Y, const TVal& Val){At(X, Y)=Val;}
3145  void PutAll(const TVal& Val){ValV.PutAll(Val);}
3146  void PutX(const int& X, const TVal& Val){
3147  for (int Y=0; Y<int(YDim); Y++){At(X, Y)=Val;}}
3148  void PutY(const int& Y, const TVal& Val){
3149  for (int X=0; X<int(XDim); X++){At(X, Y)=Val;}}
3150  TVal GetXY(const int& X, const int& Y) const {
3151  Assert((0<=X)&&(X<int(XDim))&&(0<=Y)&&(Y<int(YDim)));
3152  return ValV[X*YDim+Y];}
3153  void GetRow(const int& RowN, TVec<TVal>& Vec) const;
3154  void GetCol(const int& ColN, TVec<TVal>& Vec) const;
3155 
3156  void SwapX(const int& X1, const int& X2);
3157  void SwapY(const int& Y1, const int& Y2);
3158  void Swap(TVVec<TVal>& Vec);
3159 
3160  void ShuffleX(TRnd& Rnd);
3161  void ShuffleY(TRnd& Rnd);
3162  void GetMxValXY(int& X, int& Y) const;
3163 
3164  void CopyFrom(const TVVec<TVal>& VVec);
3165  void AddXDim();
3166  void AddYDim();
3167  void DelX(const int& X);
3168  void DelY(const int& Y);
3169 };
3170 
3171 template <class TVal>
3172 void TVVec<TVal>::SwapX(const int& X1, const int& X2){
3173  for (int Y=0; Y<int(YDim); Y++){
3174  TVal Val=At(X1, Y); At(X1, Y)=At(X2, Y); At(X2, Y)=Val;}
3175 }
3176 
3177 template <class TVal>
3178 void TVVec<TVal>::SwapY(const int& Y1, const int& Y2){
3179  for (int X=0; X<int(XDim); X++){
3180  TVal Val=At(X, Y1); At(X, Y1)=At(X, Y2); At(X, Y2)=Val;}
3181 }
3182 
3183 template <class TVal>
3185  if (this!=&Vec){
3186  ::Swap(XDim, Vec.XDim);
3187  ::Swap(YDim, Vec.YDim);
3188  ValV.Swap(Vec.ValV);
3189  }
3190 }
3191 
3192 template <class TVal>
3194  for (int X=0; X<XDim-1; X++){SwapX(X, X+Rnd.GetUniDevInt(XDim-X));}
3195 }
3196 
3197 template <class TVal>
3199  for (int Y=0; Y<YDim-1; Y++){SwapY(Y, Y+Rnd.GetUniDevInt(YDim-Y));}
3200 }
3201 
3202 template <class TVal>
3203 void TVVec<TVal>::GetMxValXY(int& X, int& Y) const {
3204  int MxValN=ValV.GetMxValN();
3205  Y=MxValN%YDim;
3206  X=MxValN/YDim;
3207 }
3208 
3209 template <class TVal>
3211  int CopyXDim=TInt::GetMn(GetXDim(), VVec.GetXDim());
3212  int CopyYDim=TInt::GetMn(GetYDim(), VVec.GetYDim());
3213  for (int X=0; X<CopyXDim; X++){
3214  for (int Y=0; Y<CopyYDim; Y++){
3215  At(X, Y)=VVec.At(X, Y);
3216  }
3217  }
3218 }
3219 
3220 template <class TVal>
3222  TVVec<TVal> NewVVec(XDim+1, YDim);
3223  NewVVec.CopyFrom(*this);
3224  *this=NewVVec;
3225 }
3226 
3227 template <class TVal>
3229  TVVec<TVal> NewVVec(XDim, YDim+1);
3230  NewVVec.CopyFrom(*this);
3231  *this=NewVVec;
3232 }
3233 
3234 template <class TVal>
3235 void TVVec<TVal>::DelX(const int& X){
3236  TVVec<TVal> NewVVec(XDim-1, YDim);
3237  for (int Y=0; Y<YDim; Y++){
3238  for (int LX=0; LX<X; LX++){
3239  NewVVec.At(LX, Y)=At(LX, Y);}
3240  for (int RX=X+1; RX<XDim; RX++){
3241  NewVVec.At(RX-1, Y)=At(RX, Y);}
3242  }
3243  *this=NewVVec;
3244 }
3245 
3246 template <class TVal>
3247 void TVVec<TVal>::DelY(const int& Y){
3248  TVVec<TVal> NewVVec(XDim, YDim-1);
3249  for (int X=0; X<XDim; X++){
3250  for (int LY=0; LY<Y; LY++){
3251  NewVVec.At(X, LY)=At(X, LY);}
3252  for (int RY=Y+1; RY<YDim; RY++){
3253  NewVVec.At(X, RY-1)=At(X, RY);}
3254  }
3255  *this=NewVVec;
3256 }
3257 
3258 template <class TVal>
3259 void TVVec<TVal>::GetRow(const int& RowN, TVec<TVal>& Vec) const {
3260  Vec.Gen(GetCols(), 0);
3261  for (int col = 0; col < GetCols(); col++) {
3262  Vec.Add(At(RowN, col));
3263  }
3264 }
3265 
3266 template <class TVal>
3267 void TVVec<TVal>::GetCol(const int& ColN, TVec<TVal>& Vec) const {
3268  Vec.Gen(GetRows(), 0);
3269  for (int row = 0; row < GetRows(); row++) {
3270  Vec.Add(At(row, ColN));
3271  }
3272 }
3273 
3275 // Common-2D-Vector-Types
3283 
3285 // 3D-Vector
3286 template <class TVal>
3287 class TVVVec{
3288 private:
3291 public:
3292  TVVVec(): XDim(), YDim(), ZDim(), ValV(){}
3293  TVVVec(const TVVVec& Vec):
3294  XDim(Vec.XDim), YDim(Vec.YDim), ZDim(Vec.ZDim), ValV(Vec.ValV){}
3295  TVVVec(const int& _XDim, const int& _YDim, const int& _ZDim):
3296  XDim(), YDim(), ZDim(), ValV(){Gen(_XDim, _YDim, _ZDim);}
3297  explicit TVVVec(TSIn& SIn):
3298  XDim(SIn), YDim(SIn), ZDim(SIn), ValV(SIn){}
3299  void Save(TSOut& SOut) const {
3300  XDim.Save(SOut); YDim.Save(SOut); ZDim.Save(SOut); ValV.Save(SOut);}
3301 
3303  XDim=Vec.XDim; YDim=Vec.YDim; ZDim=Vec.ZDim; ValV=Vec.ValV;
3304  return *this;
3305  }
3306  bool operator==(const TVVVec& Vec) const {
3307  return (XDim==Vec.XDim)&&(YDim==Vec.YDim)&&(ZDim==Vec.ZDim)&&
3308  (ValV==Vec.ValV);}
3309 
3310  bool Empty() const {return ValV.Len()==0;}
3311  void Clr(){XDim=0; YDim=0; ZDim=0; ValV.Clr();}
3312  void Gen(const int& _XDim, const int& _YDim, const int& _ZDim){
3313  Assert((_XDim>=0)&&(_YDim>=0)&&(_ZDim>=0));
3314  XDim=_XDim; YDim=_YDim; ZDim=_ZDim; ValV.Gen(XDim*YDim*ZDim);}
3315  TVal& At(const int& X, const int& Y, const int& Z){
3316  Assert((0<=X)&&(X<int(XDim))&&(0<=Y)&&(Y<int(YDim))&&(0<=Z)&&(Z<int(ZDim)));
3317  return ValV[X*YDim*ZDim+Y*ZDim+Z];}
3318  const TVal& At(const int& X, const int& Y, const int& Z) const {
3319  Assert((0<=X)&&(X<int(XDim))&&(0<=Y)&&(Y<int(YDim))&&(0<=Z)&&(Z<int(ZDim)));
3320  return ValV[X*YDim*ZDim+Y*ZDim+Z];}
3321  TVal& operator()(const int& X, const int& Y, const int& Z){
3322  return At(X, Y, Z);}
3323  const TVal& operator()(const int& X, const int& Y, const int& Z) const {
3324  return At(X, Y, Z);}
3325  int GetXDim() const {return XDim;}
3326  int GetYDim() const {return YDim;}
3327  int GetZDim() const {return ZDim;}
3328 };
3329 
3331 // Common-3D-Vector-Types
3334 
3336 // Tree
3337 template <class TVal>
3338 class TTree{
3339 private:
3340  TVec<TTriple<TInt, TIntV, TVal> > NodeV; // (ParentNodeId, ChildNodeIdV, NodeVal)
3341 public:
3342  TTree(): NodeV(){}
3343  TTree(const TTree& Tree): NodeV(Tree.NodeV){}
3344  explicit TTree(TSIn& SIn): NodeV(SIn){}
3345  void Save(TSOut& SOut) const {NodeV.Save(SOut);}
3346  void LoadXml(const PXmlTok& XmlTok, const TStr& Nm="");
3347  void SaveXml(TSOut& SOut, const TStr& Nm) const;
3348 
3349  TTree& operator=(const TTree& Tree){if (this!=&Tree){NodeV=Tree.NodeV;} return *this;}
3350  bool operator==(const TTree& Tree) const {return NodeV==Tree.NodeV;}
3351  bool operator<(const TTree& Tree) const {return false;}
3352 
3353  int GetPrimHashCd() const {return NodeV.GetPrimHashCd();}
3354  int GetSecHashCd() const {return NodeV.GetSecHashCd();}
3355 
3356  int GetMemUsed() const {return NodeV.GetMemUsed();}
3357 
3358  void Clr(){NodeV.Clr();}
3359 
3360  int AddNode(const int& ParentNodeId, const TVal& NodeVal=TVal()){
3361  IAssert(((ParentNodeId==-1)&&(NodeV.Len()==0))||(NodeV.Len()>0));
3362  if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.Add(NodeV.Len());}
3363  return NodeV.Add(TTriple<TInt, TIntV, TVal>(ParentNodeId, TIntV(), NodeVal));}
3364  int AddRoot(const TVal& NodeVal=TVal()){
3365  return AddNode(-1, NodeVal);}
3366 
3367  int GetNodes() const {return NodeV.Len();}
3368  void GetNodeIdV(TIntV& NodeIdV, const int& NodeId=0);
3369  int GetParentNodeId(const int& NodeId) const {return NodeV[NodeId].Val1;}
3370  int GetChildren(const int& NodeId) const {return NodeV[NodeId].Val2.Len();}
3371  int GetChildNodeId(const int& NodeId, const int& ChildN) const {return NodeV[NodeId].Val2[ChildN];}
3372  TVal& GetNodeVal(const int& NodeId){return NodeV[NodeId].Val3;}
3373 
3374  void GenRandomTree(const int& Nodes, TRnd& Rnd);
3375 
3376  void DelNode(const int& NodeId);
3377  void CopyTree(const int& SrcNodeId, TTree& DstTree, const int& DstParentNodeId=-1);
3378 
3379  void WrTree(const int& NodeId=0, const int& Lev=0);
3380 };
3381 
3382 template <class TVal>
3383 void TTree<TVal>::GetNodeIdV(TIntV& NodeIdV, const int& NodeId){
3384  if (NodeId==0){NodeIdV.Clr(); if (GetNodes()==0){return;}}
3385  else if (GetParentNodeId(NodeId)==-1){return;}
3386  NodeIdV.Add(NodeId);
3387  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
3388  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
3389  if (ChildNodeId!=-1){
3390  GetNodeIdV(NodeIdV, ChildNodeId);
3391  }
3392  }
3393 }
3394 
3395 template <class TVal>
3396 void TTree<TVal>::GenRandomTree(const int& Nodes, TRnd& Rnd){
3397  Clr();
3398  if (Nodes>0){
3399  AddRoot(TVal());
3400  for (int NodeN=1; NodeN<Nodes; NodeN++){
3401  int ParentNodeId=Rnd.GetUniDevInt(0, GetNodes()-1);
3402  AddNode(ParentNodeId, TVal());
3403  }
3404  }
3405 }
3406 
3407 template <class TVal>
3408 void TTree<TVal>::DelNode(const int& NodeId){
3409  if (NodeId==0){
3410  Clr();
3411  } else {
3412  TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
3413  int ChildNodeIdN=ChildNodeIdV.SearchForw(NodeId);
3414  ChildNodeIdV[ChildNodeIdN]=-1;
3415  }
3416 }
3417 
3418 template <class TVal>
3419 void TTree<TVal>::CopyTree(const int& SrcNodeId, TTree& DstTree, const int& DstParentNodeId){
3420  int DstNodeId=DstTree.AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
3421  for (int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
3422  int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
3423  if (ChildNodeId!=-1){
3424  CopyTree(ChildNodeId, DstTree, DstNodeId);
3425  }
3426  }
3427 }
3428 
3429 template <class TVal>
3430 void TTree<TVal>::WrTree(const int& NodeId, const int& Lev){
3431  for (int LevN=0; LevN<Lev; LevN++){printf("| ");}
3432  printf("%d (%d)\n", NodeId, GetChildren(NodeId));
3433  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
3434  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
3435  if (ChildNodeId!=-1){
3436  WrTree(ChildNodeId, Lev+1);
3437  }
3438  }
3439 }
3440 
3442 // Common-Tree-Types
3448 
3450 // Stack
3451 template <class TVal>
3452 class TSStack{
3453 private:
3455 public:
3456  TSStack(): ValV(){}
3457  TSStack(const int& MxVals): ValV(MxVals, 0){}
3458  TSStack(const TSStack& Stack): ValV(Stack.ValV){}
3459  explicit TSStack(TSIn& SIn): ValV(SIn){}
3460  void Save(TSOut& SOut) const {ValV.Save(SOut);}
3461 
3462  TSStack& operator=(const TSStack& Stack){
3463  if (this!=&Stack){ValV=Stack.ValV;} return *this;}
3464  bool operator==(const TSStack& Stack) const {return this==&Stack;}
3465  const TVal& operator[](const int& ValN) const {return ValV[ValV.Len()-ValN-1];}
3466  TVal& operator[](const int& ValN) {return ValV[ValV.Len()-ValN-1];}
3467 
3468  bool Empty(){return ValV.Len()==0;}
3469  void Clr(const bool& DoDel=false) {ValV.Clr(DoDel);}
3470  bool IsIn(const TVal& Val) const {return ValV.IsIn(Val);}
3471  int Len(){return ValV.Len();}
3472  TVal& Top(){Assert(0<ValV.Len()); return ValV.Last();}
3473  const TVal& Top() const {Assert(0<ValV.Len()); return ValV.Last();}
3474  void Push(){ValV.Add();}
3475  void Push(const TVal& Val){ValV.Add(Val);}
3476  void Pop(){Assert(0<ValV.Len()); ValV.DelLast();}
3477 };
3478 
3480 // Common-Stack-Types
3483 
3485 // Queue
3486 template <class TVal>
3487 class TQQueue{
3488 private:
3492 public:
3493  TQQueue(const int& _MxLast=64, const int& _MxLen=-1):
3494  MxLast(_MxLast), MxLen(_MxLen), First(0), Last(0), ValV(){
3495  Assert(int(MxLast)>0); Assert((MxLen==-1)||(int(MxLen)>0));}
3496  TQQueue(const TQQueue& Queue):
3497  MxLast(Queue.MxLast), MxLen(Queue.MxLen),
3498  First(Queue.First), Last(Queue.Last), ValV(Queue.ValV){}
3499  explicit TQQueue(TSIn& SIn):
3500  MxLast(SIn), MxLen(SIn), First(SIn), Last(SIn), ValV(SIn){}
3501  void Save(TSOut& SOut) const {
3502  MxLast.Save(SOut); MxLen.Save(SOut);
3503  First.Save(SOut); Last.Save(SOut); ValV.Save(SOut);}
3504 
3505  TQQueue& operator=(const TQQueue& Queue){
3506  if (this!=&Queue){MxLast=Queue.MxLast; MxLen=Queue.MxLen;
3507  First=Queue.First; Last=Queue.Last; ValV=Queue.ValV;}
3508  return *this;}
3509  const TVal& operator[](const int& ValN) const {Assert((0<=ValN)&&(ValN<Len()));
3510  return ValV[Last+ValN];}
3511 
3512  void Clr(const bool& DoDel=true){ValV.Clr(DoDel); First=Last=0;}
3513  void Gen(const int& _MxLast=64, const int& _MxLen=-1){
3514  MxLast=_MxLast; MxLen=_MxLen; First=0; Last=0; ValV.Clr();}
3515  void GetSubValV(const int& _BValN, const int& _EValN, TVec<TVal>& SubValV) const {
3516  int BValN=TInt::GetMx(0, _BValN);
3517  int EValN=TInt::GetMn(Len()-1, _EValN);
3518  SubValV.Gen(EValN-BValN+1);
3519  for (int ValN=BValN; ValN<=EValN; ValN++){
3520  SubValV[ValN-BValN]=ValV[Last+ValN];}
3521  }
3522 
3523  bool Empty() const {return First==Last;}
3524  int Len() const {return First-Last;}
3525  const TVal& Top() const {
3526  Assert(First!=Last); return ValV[Last];}
3527  void Pop(){
3528  IAssert(First!=Last); Last++;
3529  if (First==Last){ValV.Clr(); First=Last=0;}}
3530  void Push(const TVal& Val){
3531  if (Last>MxLast){ValV.Del(0, Last-1); First-=Last; Last=0;}
3532  if ((MxLen!=-1)&&(MxLen==Len())){Pop();}
3533  First++; ValV.Add(Val);}
3534 
3535  void Shuffle(TRnd& Rnd){
3536  TVec<TVal> ValV(Len(), 0); while (!Empty()){ValV.Add(Top()); Pop();}
3537  ValV.Shuffle(Rnd); Clr();
3538  for (int ValN=0; ValN<ValV.Len(); ValN++){Push(ValV[ValN]);}}
3539 };
3540 
3542 // Common-Queue-Types
3551 
3553 // List-Node
3554 template <class TVal>
3555 class TLstNd{
3556 public:
3559  TVal Val;
3560 public:
3561  TLstNd(): PrevNd(NULL), NextNd(NULL), Val(){}
3562  TLstNd(const TLstNd&);
3563  TLstNd(TLstNd* _PrevNd, TLstNd* _NextNd, const TVal& _Val):
3564  PrevNd(_PrevNd), NextNd(_NextNd), Val(_Val){}
3565 
3566  TLstNd& operator=(const TLstNd&);
3567 
3568  bool IsPrev() const {return (PrevNd != NULL); }
3569  bool IsNext() const {return (NextNd != NULL); }
3570  TLstNd* Prev() const {Assert(this!=NULL); return PrevNd;}
3571  TLstNd* Next() const {Assert(this!=NULL); return NextNd;}
3572  TVal& GetVal(){Assert(this!=NULL); return Val;}
3573  const TVal& GetVal() const {Assert(this!=NULL); return Val;}
3574 };
3575 
3577 // List
3578 template <class TVal>
3579 class TLst{
3580 public:
3582 private:
3583  int Nds;
3586 public:
3587  TLst(): Nds(0), FirstNd(NULL), LastNd(NULL){}
3588  TLst(const TLst&);
3589  ~TLst(){Clr();}
3590  explicit TLst(TSIn& SIn);
3591  void Save(TSOut& SOut) const;
3592 
3593  TLst& operator=(const TLst&);
3594 
3595  void Clr(){
3596  PLstNd Nd=FirstNd;
3597  while (Nd!=NULL){PLstNd NextNd=Nd->NextNd; delete Nd; Nd=NextNd;}
3598  Nds=0; FirstNd=NULL; LastNd=NULL;}
3599 
3600  bool Empty() const {return Nds==0;}
3601  int Len() const {return Nds;}
3602  PLstNd First() const {return FirstNd;}
3603  PLstNd Last() const {return LastNd;}
3604  TVal& FirstVal() const {return FirstNd->GetVal();}
3605  TVal& LastVal() const {return LastNd->GetVal();}
3606 
3607  PLstNd AddFront(const TVal& Val);
3608  PLstNd AddBack(const TVal& Val);
3609  PLstNd AddFrontSorted(const TVal& Val, const bool& Asc=true);
3610  PLstNd AddBackSorted(const TVal& Val, const bool& Asc=true);
3611  void PutFront(const PLstNd& Nd);
3612  void PutBack(const PLstNd& Nd);
3613  PLstNd Ins(const PLstNd& Nd, const TVal& Val);
3614  void Del(const TVal& Val);
3615  void Del(const PLstNd& Nd);
3616  void DelFirst() { PLstNd DelNd = FirstNd; Del(DelNd); }
3617  void DelLast() { PLstNd DelNd = LastNd; Del(DelNd); }
3618 
3619  PLstNd SearchForw(const TVal& Val);
3620  PLstNd SearchBack(const TVal& Val);
3621 
3622  friend class TLstNd<TVal>;
3623 };
3624 
3625 template <class TVal>
3627  Nds(0), FirstNd(NULL), LastNd(NULL){
3628  int CheckNds=0; SIn.Load(CheckNds);
3629  for (int NdN=0; NdN<CheckNds; NdN++){AddBack(TVal(SIn));}
3630  Assert(Nds==CheckNds);
3631 }
3632 
3633 template <class TVal>
3634 void TLst<TVal>::Save(TSOut& SOut) const {
3635  SOut.Save(Nds);
3636  PLstNd Nd=FirstNd; int CheckNds=0;
3637  while (Nd!=NULL){
3638  Nd->Val.Save(SOut); Nd=Nd->NextNd; CheckNds++;}
3639  IAssert(Nds==CheckNds);
3640 }
3641 
3642 template <class TVal>
3644  PLstNd Nd=new TLstNd<TVal>(NULL, FirstNd, Val);
3645  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
3646  else {FirstNd=Nd; LastNd=Nd;}
3647  Nds++; return Nd;
3648 }
3649 
3650 template <class TVal>
3652  PLstNd Nd=new TLstNd<TVal>(LastNd, NULL, Val);
3653  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
3654  else {FirstNd=Nd; LastNd=Nd;}
3655  Nds++; return Nd;
3656 }
3657 
3658 template <class TVal>
3659 TLstNd<TVal>* TLst<TVal>::AddFrontSorted(const TVal& Val, const bool& Asc){
3660  PLstNd Nd=First();
3661  if (Nd==NULL){
3662  return Ins(Nd, Val);
3663  } else {
3664  while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
3665  Nd=Nd->Next();}
3666  if (Nd==NULL){return Ins(Nd->Last(), Val);}
3667  else {return Ins(Nd->Prev(), Val);}
3668  }
3669 }
3670 
3671 template <class TVal>
3672 TLstNd<TVal>* TLst<TVal>::AddBackSorted(const TVal& Val, const bool& Asc){
3673  PLstNd Nd=Last();
3674  while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->Val)))){
3675  Nd=Nd->Prev();}
3676  return Ins(Nd, Val);
3677 }
3678 
3679 template <class TVal>
3681  Assert(Nd!=NULL);
3682  // unchain
3683  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
3684  else {Nd->PrevNd->NextNd=Nd->NextNd;}
3685  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
3686  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
3687  // add to front
3688  Nd->PrevNd=NULL; Nd->NextNd=FirstNd;
3689  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
3690  else {FirstNd=Nd; LastNd=Nd;}
3691 }
3692 
3693 template <class TVal>
3694 void TLst<TVal>::PutBack(const PLstNd& Nd){
3695  Assert(Nd!=NULL);
3696  // unchain
3697  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
3698  else {Nd->PrevNd->NextNd=Nd->NextNd;}
3699  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
3700  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
3701  // add to back
3702  Nd->PrevNd=LastNd; Nd->NextNd=NULL;
3703  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
3704  else {FirstNd=Nd; LastNd=Nd;}
3705 }
3706 
3707 template <class TVal>
3708 TLstNd<TVal>* TLst<TVal>::Ins(const PLstNd& Nd, const TVal& Val){
3709  if (Nd==NULL){return AddFront(Val);}
3710  else if (Nd->NextNd==NULL){return AddBack(Val);}
3711  else {
3712  PLstNd NewNd=new TLstNd<TVal>(Nd, Nd->NextNd, Val);
3713  Nd->NextNd=NewNd; NewNd->NextNd->PrevNd=Nd;
3714  Nds++; return Nd;
3715  }
3716 }
3717 
3718 template <class TVal>
3719 void TLst<TVal>::Del(const TVal& Val){
3720  PLstNd Nd=SearchForw(Val);
3721  if (Nd!=NULL){Del(Nd);}
3722 }
3723 
3724 template <class TVal>
3725 void TLst<TVal>::Del(const PLstNd& Nd){
3726  Assert(Nd!=NULL);
3727  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
3728  else {Nd->PrevNd->NextNd=Nd->NextNd;}
3729  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
3730  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
3731  Nds--; delete Nd;
3732 }
3733 
3734 template <class TVal>
3736  PLstNd Nd=First();
3737  while (Nd!=NULL){
3738  if (Nd->GetVal()==Val){return Nd;}
3739  Nd=Nd->Next();
3740  }
3741  return NULL;
3742 }
3743 
3744 template <class TVal>
3746  PLstNd Nd=Last();
3747  while (Nd!=NULL){
3748  if (Nd->GetVal()==Val){return Nd;}
3749  Nd=Nd->Prev();
3750  }
3751  return NULL;
3752 }
3753 
3755 // Common-List-Types
3768 
3770 // Record-File
3771 template <class THd, class TRec>
3772 class TFRec{
3773 private:
3775 public:
3776  TFRec(const TStr& FNm, const TFAccess& FAccess, const bool& CreateIfNo):
3777  FRnd(PFRnd(new TFRnd(FNm, FAccess, CreateIfNo, sizeof(THd), sizeof(TRec)))){}
3778  TFRec(const TFRec&);
3779 
3780  TFRec& operator=(const TFRec&);
3781 
3782  void SetRecN(const int& RecN){FRnd->SetRecN(RecN);}
3783  int GetRecN(){return FRnd->GetRecN();}
3784  int GetRecs(){return FRnd->GetRecs();}
3785 
3786  void GetHd(THd& Hd){FRnd->GetHd(&Hd);}
3787  void PutHd(const THd& Hd){FRnd->PutHd(&Hd);}
3788  void GetRec(TRec& Rec, const int& RecN=-1){FRnd->GetRec(&Rec, RecN);}
3789  void PutRec(const TRec& Rec, const int& RecN=-1){FRnd->PutRec(&Rec, RecN);}
3790 };
3791 
3793 // Function
3794 template <class TFuncPt>
3795 class TFunc{
3796 private:
3797  TFuncPt FuncPt;
3798 public:
3799  TFunc(): FuncPt(NULL){}
3800  TFunc(const TFunc& Func): FuncPt(Func.FuncPt){}
3801  TFunc(const TFuncPt& _FuncPt): FuncPt(_FuncPt){}
3803  void Save(TSOut&) const {Fail;}
3804 
3805  TFunc& operator=(const TFunc& Func){
3806  if (this!=&Func){FuncPt=Func.FuncPt;} return *this;}
3807  bool operator==(const TFunc& Func) const {
3808  return FuncPt==Func.FuncPt;}
3809  bool operator<(const TFunc&) const {
3810  Fail; return false;}
3811  TFuncPt operator()() const {return FuncPt;}
3812 };
Definition: ds.h:336
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:1068
void PushHeap(const TVal &Val, const TCmp &Cmp)
Definition: ds.h:1613
~TVec()
Definition: ds.h:448
void Save(TSOut &SOut) const
Definition: ds.h:2953
bool operator==(const TTree &Tree) const
Definition: ds.h:3350
Definition: bd.h:440
#define IAssert(Cond)
Definition: bd.h:262
TQuad< TStr, TStr, TStr, TStr > TStrQu
Definition: ds.h:252
TVec< TFltIntKd > TFltIntKdV
Definition: ds.h:2517
TFuncPt FuncPt
Definition: ds.h:3797
TVec< TVal > V
Definition: ds.h:3057
int AddMerged(const TVal &Val)
Definition: ds.h:2003
bool operator==(const TVVec &Vec) const
Definition: ds.h:3119
int MxVals
Definition: ds.h:1485
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:2614
const TVal & GetVal() const
Definition: ds.h:3573
TVal & LastLast()
Definition: ds.h:1555
TQQueue< TAscFltV > TAscFltVQ
Definition: ds.h:3549
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:3075
::TSize GetVecs() const
Definition: ds.h:2843
void MakeHeap()
Definition: ds.h:1608
TTriple(const TTriple &Triple)
Definition: ds.h:136
TPair(const TPair &Pair)
Definition: ds.h:38
void Reserve(const int &_MxVals)
Definition: ds.h:1536
TVec< TUInt64IntPr > TUInt64IntPrV
Definition: ds.h:2510
::TSize Vals
Definition: ds.h:2823
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1115
TTree< TStrIntStrVTr > TStrIntStrVTrTree
Definition: ds.h:3447
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
Definition: ds.h:552
TStr GetStr() const
Definition: ds.h:62
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7)
Definition: ds.h:1778
TPair< TUCh, TStr > TUChStrPr
Definition: ds.h:80
TVec< TSFlt > TSFltV
Definition: ds.h:2476
TVec< TUInt > TUIntV
Definition: ds.h:2472
TTriple(TSIn &SIn)
Definition: ds.h:140
bool operator()(const TTriple< TVal1, TVal2, TVal3 > &T1, const TTriple< TVal1, TVal2, TVal3 > &T2) const
Definition: ds.h:205
bool Empty()
Definition: ds.h:3468
TTriple< TStr, TStr, TInt > TStrStrIntTr
Definition: ds.h:183
TPair(const TVal1 &_Val1, const TVal2 &_Val2)
Definition: ds.h:39
TVal & operator()(const int &X, const int &Y)
Definition: ds.h:3139
static TIter PartitionCmp(TIter BI, TIter EI, const TVal Pivot, const TCmp &Cmp)
Definition: ds.h:1668
TVVec< TCh > TChVV
Definition: ds.h:3277
TSizeTy Reserved() const
Returns the size of allocated storage capacity.
Definition: ds.h:537
TVec< TIntIntVIntTr > TIntIntVIntTrV
Definition: ds.h:2508
TStr GetStr() const
Definition: dt.h:1104
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TPair< TUInt, TUInt > TUIntUIntPr
Definition: ds.h:91
static TVec< TVal > 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)
Definition: ds.h:1780
TVec< TFltIntIntTr > TFltIntIntTrV
Definition: ds.h:2523
TVec< TIntIntFltTr > TIntIntFltTrV
Definition: ds.h:2498
void Save(TSOut &) const
Definition: ds.h:3803
void Shuffle(TRnd &Rnd)
Definition: ds.h:2190
TPair< TFlt, TInt > TFltIntPr
Definition: ds.h:97
PVec< TStr > TStrVP
Definition: ds.h:3094
int GetPrimHashCd() const
Returns primary hash code of the vector. Used by THash.
Definition: ds.h:930
TTriple< TInt, TStr, TInt > TIntStrIntTr
Definition: ds.h:168
void PutX(const int &X, const TVal &Val)
Definition: ds.h:3146
bool operator<(const TFunc &) const
Definition: ds.h:3809
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:99
bool operator==(const TQuad &Quad) const
Definition: ds.h:237
PLstNd Ins(const PLstNd &Nd, const TVal &Val)
Definition: ds.h:3708
TPair()
Definition: ds.h:37
bool operator()(const TPair< TVal1, TVal2 > &P1, const TPair< TVal1, TVal2 > &P2) const
Definition: ds.h:121
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:1256
TVec< TAscFltIntKd > TAscFltIntKdV
Definition: ds.h:2526
TInt Last
Definition: ds.h:3490
TTree()
Definition: ds.h:3342
Definition: ds.h:3053
TTuple & operator=(const TTuple &Tup)
Definition: ds.h:276
int64 GetUniDevInt64(const int64 &Range=0)
Definition: dt.cpp:51
void Reserve(const int &_MxVals, const int &_Vals)
Definition: ds.h:1537
void Save(TSOut &SOut) const
Definition: ds.h:3114
static int GetInRng(const int &Val, const int &Mn, const int &Mx)
Definition: dt.h:1101
bool operator==(const TVVVec &Vec) const
Definition: ds.h:3306
void Diff(const TVec< TVal > &ValV)
Definition: ds.h:2270
TVec< TAscFlt > TAscFltV
Definition: ds.h:2477
TQQueue & operator=(const TQQueue &Queue)
Definition: ds.h:3505
static void SwapI(TIter LVal, TIter RVal)
Definition: ds.h:1588
Definition: ds.h:262
TLstNd< TFlt > * PFltLN
Definition: ds.h:3761
TTriple< TStr, TInt, TStrV > TStrIntStrVTr
Definition: ds.h:184
bool Empty() const
Definition: ds.h:3523
TPair< TStr, TStr > TStrPr
Definition: ds.h:107
TVVec< TVal > & operator=(const TVVec< TVal > &Vec)
Definition: ds.h:3117
TPair< TStr, TFlt > TStrFltPr
Definition: ds.h:106
TVal & At(const int &X, const int &Y)
Definition: ds.h:3136
PLstNd SearchBack(const TVal &Val)
Definition: ds.h:3745
Definition: dt.h:11
TSStack(const TSStack &Stack)
Definition: ds.h:3458
uint64 Reserved() const
Returns the total capacity of the pool.
Definition: ds.h:2588
TPair< TUInt64, TFlt > TUInt64FltPr
Definition: ds.h:95
void DelNode(const int &NodeId)
Definition: ds.h:3408
static PVecPool New(const TSize &ExpectVals=0, const TSize &GrowBy=1000000, const bool &FastCopy=false)
Definition: ds.h:2574
TFunc(TSIn &)
Definition: ds.h:3802
TInt YDim
Definition: ds.h:3102
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:95
Definition: ds.h:129
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1094
int GetYDim() const
Definition: ds.h:3326
TTuple(TSIn &SIn)
Definition: ds.h:269
TVec< TStrPr > TStrPrV
Definition: ds.h:2527
void Save(TSOut &SOut) const
Definition: ds.h:3071
TVec< TStrFltKd > TStrFltKdV
Definition: ds.h:2531
TVec< TVal > ValV
Definition: ds.h:3290
int AddV(const TValV &ValV)
Adds vector ValV to the pool and returns its id.
Definition: ds.h:2747
bool IsSorted(const bool &Asc=true) const
Definition: ds.h:2178
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:3360
TVVVec(TSIn &SIn)
Definition: ds.h:3297
const TVal & LastLast() const
Definition: ds.h:1552
TKeyDat< TFlt, TBool > TFltBoolKd
Definition: ds.h:381
TTree< TStr > TStrTree
Definition: ds.h:3445
TVec< TIntIntStrTr > TIntIntStrTrV
Definition: ds.h:2497
void Push(const TVal &Val)
Definition: ds.h:3475
TVal & FirstVal() const
Definition: ds.h:3604
void Save(TSOut &SOut) const
Definition: dt.h:1057
bool operator()(const TKeyDat< TVal1, TVal2 > &P1, const TKeyDat< TVal1, TVal2 > &P2) const
Definition: ds.h:405
bool operator==(const TSStack &Stack) const
Definition: ds.h:3464
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
Definition: ds.h:782
bool operator<(const TVec< TVal, TSizeTy > &Vec) const
Lexicographically compares two vectors.
Definition: ds.h:912
void GetHd(THd &Hd)
Definition: ds.h:3786
TVecPool & operator=(const TVecPool &Pool)
Definition: ds.h:2966
#define forever
Definition: bd.h:6
void Reserve(const ::TSize &MxVals)
Definition: ds.h:2846
TVal * ValT
Definition: ds.h:1487
int Nds
Definition: ds.h:3583
TKeyDat(const TKey &_Key)
Definition: ds.h:343
unsigned int uint
Definition: bd.h:11
TVec< TIntStrKd > TIntStrKdV
Definition: ds.h:2505
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:3369
void Save(TSOut &) const
Definition: ds.h:12
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:3371
TFunc(const TFuncPt &_FuncPt)
Definition: ds.h:3801
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1089
TVal & Top()
Definition: ds.h:3472
TVVVec(const int &_XDim, const int &_YDim, const int &_ZDim)
Definition: ds.h:3295
int SearchVForw(const TVec< TVal > &ValV, const int &BValN=0) const
Definition: ds.h:2443
static const int Mx
Definition: dt.h:1046
#define Fail
Definition: bd.h:238
int GetSecHashCd() const
Definition: ds.h:1896
void QSort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Quick sorts the values between positions MnLValN...MxLValN.
Definition: ds.h:1205
int GetPrimHashCd() const
Definition: ds.h:1888
PLstNd AddBackSorted(const TVal &Val, const bool &Asc=true)
Definition: ds.h:3672
void Load(TSIn &SIn)
Definition: ds.h:3113
::TSize GetVals() const
Definition: ds.h:2842
const TVal1 & GetVal1() const
Definition: ds.h:60
TVal * ValBf
Definition: ds.h:2559
uint64 GetMemUsed() const
Returns the total memory footprint (in bytes) of the pool.
Definition: ds.h:2596
bool IsSortedCmp(const TCmp &Cmp) const
Checks whether the vector is sorted according to the comparator Cmp.
Definition: ds.h:716
TKeyDat< TUInt64, TFlt > TUInt64FltKd
Definition: ds.h:379
void SetEmptyVal(const TVal &_EmptyVal)
Definition: ds.h:2848
PVec< TAscFlt > TAscFltVP
Definition: ds.h:3092
TVal & Last()
Definition: ds.h:1550
int Vals
Definition: ds.h:1486
void MoveFrom(TVec< TVal > &Vec)
Definition: ds.h:1952
TVal2 Val2
Definition: ds.h:216
void Minus(const TVec< TVal > &ValV)
Definition: ds.h:2277
TFunc(const TFunc &Func)
Definition: ds.h:3800
TVal & LastVal() const
Definition: ds.h:3605
TVec< TVal > TValV
Definition: ds.h:2819
int Len() const
Definition: ds.h:3601
void CopyFrom(const TVVec< TVal > &VVec)
Definition: ds.h:3210
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TInt, TFlt > TIntFltKd
Definition: ds.h:371
TVec< TIntIntIntVTr > TIntIntIntVTrV
Definition: ds.h:2509
TVec< TFltTr > TFltTrV
Definition: ds.h:2484
static void BSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Definition: ds.h:1680
void PutRec(const void *Rec, const int &RecN=-1)
Definition: fl.h:536
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6)
Definition: ds.h:1776
TLstNd * Prev() const
Definition: ds.h:3570
int GetSecHashCd() const
Returns secondary hash code of the vector. Used by THash.
Definition: ds.h:942
void ISort(const int &MnLValN, const int &MxRValN, const bool &Asc)
Definition: ds.h:2101
TVVec(const int &_XDim, const int &_YDim)
Definition: ds.h:3108
void GetSwitchedKdV(const TVec< TKeyDat< TKey, TDat >, int > &SrcKdV, TVec< TKeyDat< TDat, TKey >, int > &DstKdV)
Definition: ds.h:360
void Diff(const TVec< TVal, TSizeTy > &ValV)
Subtracts ValV from this vector.
Definition: ds.h:1324
void Save(TSOut &SOut) const
Definition: ds.h:3634
void GenExt(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
Definition: ds.h:497
TTriple< TInt, TInt, TFlt > TIntIntFltTr
Definition: ds.h:170
Definition: ds.h:3579
TVec< TIntKd > TIntKdV
Definition: ds.h:2485
void GetVal(TVal1 &_Val1, TVal2 &_Val2) const
Definition: ds.h:59
TKeyDat< TInt, TFltPr > TIntFltPrKd
Definition: ds.h:373
void Reverse()
Definition: ds.h:2196
TVec< TFltStrPr > TFltStrPrV
Definition: ds.h:2494
TKeyDat< TUInt64, TStr > TUInt64StrKd
Definition: ds.h:380
TTree(TSIn &SIn)
Definition: ds.h:3344
TInt ZDim
Definition: ds.h:3289
TVec< TIntFltPrKd > TIntFltPrKdV
Definition: ds.h:2491
TLstNd * NextNd
Definition: ds.h:3558
TVec< TStrTr > TStrTrV
Definition: ds.h:2533
TTriple(const TVal1 &_Val1, const TVal2 &_Val2, const TVal3 &_Val3)
Definition: ds.h:138
TRec * operator->() const
Definition: ds.h:20
TKeyDat< TFlt, TStr > TFltStrKd
Definition: ds.h:387
TVal & operator()(const int &X, const int &Y, const int &Z)
Definition: ds.h:3321
void Save(TSOut &SOut) const
Definition: ds.h:141
bool IsVId(const int &VId) const
Definition: ds.h:2844
TVal3 Val3
Definition: ds.h:217
void Save(TSOut &SOut) const
Definition: ds.h:3501
void PutRec(const TRec &Rec, const int &RecN=-1)
Definition: ds.h:3789
int AddV(const TValV &ValV)
Definition: ds.h:2986
TVec< TFltPr > TFltPrV
Definition: ds.h:2483
void SetEmptyVal(const TVal &_EmptyVal)
Sets the empty value.
Definition: ds.h:2594
TVec< TStrQu > TStrQuV
Definition: ds.h:2534
Vector Pool.
Definition: ds.h:2550
void Save(TSOut &SOut) const
Definition: ds.h:2712
TCRef CRef
Definition: ds.h:3055
TVec< TStrAscFltKd > TStrAscFltKdV
Definition: ds.h:2532
TDat Dat
Definition: ds.h:339
TKeyDat< TStr, TInt > TStrIntKd
Definition: ds.h:392
void SetRecN(const int &RecN)
Definition: ds.h:3782
int SearchForw(const TVal &Val, const int &BValN=0) const
Definition: ds.h:2429
TTriple< TInt, TFlt, TInt > TIntFltIntTr
Definition: ds.h:171
bool PrevPerm()
Definition: ds.h:2235
int GetXDim() const
Definition: ds.h:3127
int GetMemUsed() const
Definition: ds.h:1518
TVec< TIntIntPrPr > TIntIntPrPrV
Definition: ds.h:2542
Definition: ds.h:3555
TPair< TStrV, TInt > TStrVIntPr
Definition: ds.h:109
int GetSecHashCd() const
Definition: ds.h:291
TVec< ::TSize > IdToOffV
Definition: ds.h:2826
TQQueue< TIntPr > TIntPrQ
Definition: ds.h:3546
const TVal2 & GetVal2() const
Definition: ds.h:61
TVal1 Val1
Definition: ds.h:131
void Load(TSIn &SIn)
Definition: ds.h:271
TSizeTy Add(const TVal &Val, const TSizeTy &ResizeLen)
Adds element Val at the end of the vector. #TVec::Add2.
Definition: ds.h:569
bool IsIn(const TVal &Val) const
Definition: ds.h:1751
PLstNd LastNd
Definition: ds.h:3585
TVec< TVal > ValV
Definition: ds.h:3491
void Clr(const bool &DoDel=false)
Definition: ds.h:3469
bool operator==(const TKeyDat &KeyDat) const
Definition: ds.h:352
int LastValN() const
Definition: ds.h:1551
int GetSecHashCd() const
Definition: ds.h:245
void Swap(const TSizeTy &ValN1, const TSizeTy &ValN2)
Swaps elements at positions ValN1 and ValN2.
Definition: ds.h:618
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
TVec< TStrStrVPr > TStrStrVPrV
Definition: ds.h:2538
TTriple< TStr, TInt, TInt > TStrIntIntTr
Definition: ds.h:181
void CompactPool(const TVal &DelVal)
Deletes all elements of value DelVal from all vectors.
Definition: ds.h:2767
void Merge()
Definition: ds.h:2202
TVal & At(const int &X, const int &Y, const int &Z)
Definition: ds.h:3315
TSStack()
Definition: ds.h:3456
TPair< TUInt, TInt > TUIntIntPr
Definition: ds.h:92
void Load(TSIn &SIn)
Definition: ds.h:877
PLstNd AddFront(const TVal &Val)
Definition: ds.h:3643
TQQueue(TSIn &SIn)
Definition: ds.h:3499
void AdjustHeap(const int &First, int HoleIdx, const int &Len, TVal Val, const TCmp &Cmp)
Definition: ds.h:1626
bool IsInBin(const TVal &Val) const
Definition: ds.h:1754
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4)
Definition: ds.h:1772
void Resize(const TSize &_MxVals)
Definition: ds.h:2648
static TRnd Rnd
Definition: dt.h:1050
int FindMx() const
Definition: ds.h:310
void SaveXml(TSOut &SOut, const TStr &Nm) const
TVec(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
Definition: ds.h:446
TPair< TInt, TVec< TInt, int > > TIntIntVPr
Definition: ds.h:86
::TSize GrowBy
Definition: ds.h:2823
TVal & LastLast()
Returns a reference to the one before last element of the vector.
Definition: ds.h:547
TRec * operator()() const
Definition: ds.h:24
TSizeTy GetMemUsed() const
Returns the memory footprint (the number of bytes) of the vector.
Definition: ds.h:474
TVal & operator[](const int &ValN)
Definition: ds.h:3466
void GetSubValV(const int &BValN, const int &EValN, TVec< TVal > &ValV) const
Definition: ds.h:2026
void PutFront(const PLstNd &Nd)
Definition: ds.h:3680
Definition: fl.h:275
TVec< TIntTr > TIntTrV
Definition: ds.h:2481
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:1061
TVec(TVal *_ValT, const int &_Vals)
Definition: ds.h:1499
TVal1 Val1
Definition: ds.h:215
TLst & operator=(const TLst &)
bool operator<(const TKeyDat &KeyDat) const
Definition: ds.h:353
static PVecPool Load(const TStr &FNm)
Definition: ds.h:2837
TPt< TVecPool< TVal, TSizeTy > > PVecPool
Definition: ds.h:2552
void GetCol(const int &ColN, TVec< TVal > &Vec) const
Definition: ds.h:3267
bool operator()(const TTriple< TVal1, TVal2, TVal3 > &T1, const TTriple< TVal1, TVal2, TVal3 > &T2) const
Definition: ds.h:193
TPair< TInt, TUInt64 > TIntUInt64Pr
Definition: ds.h:84
void GetNodeIdV(TIntV &NodeIdV, const int &NodeId=0)
Definition: ds.h:3383
TSize GetVals() const
Returns the total number of values stored in the vector pool.
Definition: ds.h:2584
void PutAll(const TVal &Val)
Definition: ds.h:2881
TVec< TStrKd > TStrKdV
Definition: ds.h:2537
TInt XDim
Definition: ds.h:3102
TVecPool & operator=(const TVecPool &Pool)
Definition: ds.h:2725
TSize GrowBy
Definition: ds.h:2557
TKeyDat< TFlt, TIntBoolPr > TFltIntBoolPrKd
Definition: ds.h:389
const TVal & GetEmptyVal() const
Definition: ds.h:2847
bool operator==(const TAPt &Pt) const
Definition: ds.h:16
void Gen(const int &_Vals)
Definition: ds.h:1524
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1027
void DelLast()
Definition: ds.h:3617
TPair< TAscFlt, TInt > TAscFltIntPr
Definition: ds.h:101
TInt First
Definition: ds.h:3490
TKeyDat< TInt, TStr > TIntStrKd
Definition: ds.h:375
TVec(TSIn &SIn)
Definition: ds.h:1502
int GetSecHashCd() const
Definition: ds.h:156
void Union(const TVec< TVal > &ValV)
Definition: ds.h:2263
void PutXY(const int &X, const int &Y, const TVal &Val)
Definition: ds.h:3144
int AddEmptyV(const int &ValVLen)
Adds a vector of length ValVLen to the pool and returns its id.
Definition: ds.h:2758
TQuad< TInt, TInt, TInt, TInt > TIntQu
Definition: ds.h:253
void Clr(bool DoDel=true)
Definition: ds.h:2876
TSStack(TSIn &SIn)
Definition: ds.h:3459
bool Empty() const
Definition: ds.h:3600
TPair< TInt, TBool > TIntBoolPr
Definition: ds.h:81
TVal & operator[](const int &ValN)
Definition: ds.h:274
TVVec(TSIn &SIn)
Definition: ds.h:3112
Definition: fl.h:58
void Save(TSOut &SOut) const
Definition: ds.h:885
const TVal & Top() const
Definition: ds.h:3473
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:530
int GetRecs()
Definition: ds.h:3784
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:87
void Save(TSOut &SOut) const
Definition: ds.h:228
TPair< TInt, TStrV > TIntStrVPr
Definition: ds.h:89
void Sort(const bool &Asc=true)
Definition: ds.h:2173
bool DelIfIn(const TVal &Val)
Definition: ds.h:2066
void Reverse(TSizeTy LValN, TSizeTy RValN)
Reverses the order of elements between LValN...RValN.
Definition: ds.h:666
TTriple< TFlt, TFlt, TStr > TFltFltStrTr
Definition: ds.h:178
void PutV(const int &VId, const TValV &ValV)
Sets the values of vector VId with those in ValV.
Definition: ds.h:2618
void DelAll(const TVal &Val)
Removes all occurrences of element Val.
Definition: ds.h:1123
void Intrs(const TVec< TVal, TSizeTy > &ValV)
Result is the intersection of this vector with ValV.
Definition: ds.h:1310
TVec< TIntUInt64Pr > TIntUInt64PrV
Definition: ds.h:2488
int GetRecN()
Definition: ds.h:3783
TKeyDat< TStr, TFlt > TStrFltKd
Definition: ds.h:393
const TVal & operator[](const int &ValN) const
Definition: ds.h:3465
void Clr()
Definition: ds.h:3311
TLstNd & operator=(const TLstNd &)
int GetNodes() const
Definition: ds.h:3367
TPair< TInt, TFlt > TIntFltPr
Definition: ds.h:87
uint GetVLen(const int &VId) const
Definition: ds.h:2854
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1011
TVal Val
Definition: ds.h:3559
void DelAll(const TVal &Val)
Definition: ds.h:2074
void PutAll(const TVal &Val)
Definition: ds.h:2082
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3)
Definition: ds.h:1770
TVec< TIntFltPr > TIntFltPrV
Definition: ds.h:2490
void GetVal(TVal1 &_Val1, TVal2 &_Val2, TVal3 &_Val3, TVal4 &_Val4) const
Definition: ds.h:247
void Shuffle(TRnd &Rnd)
Definition: ds.h:3535
int Len() const
Definition: ds.h:3080
TVec< TFltIntPrKd > TFltIntPrKdV
Definition: ds.h:2519
void Clr()
Definition: ds.h:3123
TSStack(const int &MxVals)
Definition: ds.h:3457
int FindMn() const
Definition: ds.h:322
TTree & operator=(const TTree &Tree)
Definition: ds.h:3349
TQQueue< TInt > TIntQ
Definition: ds.h:3543
TSizeTy Add(TVal &Val)
Definition: ds.h:566
void Pop()
Definition: ds.h:3527
TVec< TStrFltPr > TStrFltPrV
Definition: ds.h:2529
TQuad< TStr, TStr, TInt, TInt > TStrStrIntIntQu
Definition: ds.h:251
int GetMemUsed() const
Definition: ds.h:54
TKeyDat()
Definition: ds.h:341
int GetPrimHashCd() const
Definition: ds.h:244
TVec< TVal, TSizeTy > TValV
Definition: ds.h:2553
TVal2 Val2
Definition: ds.h:132
TVal EmptyVal
Definition: ds.h:2558
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:1165
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:595
TTriple< TFlt, TFlt, TInt > TFltFltIntTr
Definition: ds.h:177
void Gen(const int &_MxLast=64, const int &_MxLen=-1)
Definition: ds.h:3513
TVec< TStrFltFltTr > TStrFltFltTrV
Definition: ds.h:2535
TAPt(TSIn &)
Definition: ds.h:11
void Save(TSOut &SOut) const
Definition: ds.h:3299
TKeyDat< TAscFlt, TInt > TAscFltIntKd
Definition: ds.h:390
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:953
PLstNd FirstNd
Definition: ds.h:3584
TAPt()
Definition: ds.h:8
bool IsAsc
Definition: ds.h:202
::TSize MxVals
Definition: ds.h:2823
void PutHd(const void *Hd)
Definition: fl.h:532
TVec< TUInt64IntKd > TUInt64IntKdV
Definition: ds.h:2513
Definition: bd.h:368
TPair< TFlt, TStrPr > TFltStrPrPr
Definition: ds.h:112
bool operator==(const TFunc &Func) const
Definition: ds.h:3807
TVec< TIntPrFltKd > TIntPrFltKdV
Definition: ds.h:2504
TTriple< TCh, TCh, TCh > TChTr
Definition: ds.h:163
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:2608
TVec< TAscFltStrPr > TAscFltStrPrV
Definition: ds.h:2495
void Del(const int &ValN)
Definition: ds.h:2045
TVec< TStrVIntPr > TStrVIntPrV
Definition: ds.h:2539
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1087
TTree< TStrIntPr > TStrIntPrTree
Definition: ds.h:3446
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1218
bool operator==(const TTuple &Tup) const
Definition: ds.h:278
bool NextPerm()
Generates next permutation of the elements in the vector.
Definition: ds.h:1267
void SortCmp(const TCmp &Cmp)
Definition: ds.h:1717
TVVec(const TVVec &Vec)
Definition: ds.h:3106
void MakeHeap(const TCmp &Cmp)
Definition: ds.h:1612
TVec< TIntPr > TIntPrV
Definition: ds.h:2480
TVec< TVal, TSizeTy > & operator=(const TVec< TVal, TSizeTy > &Vec)
Assigns new contents to the vector, replacing its current content.
Definition: ds.h:892
TVec< TUIntIntKd > TUIntIntKdV
Definition: ds.h:2502
Definition: ds.h:3100
TAPt(TRec *_Addr)
Definition: ds.h:10
TPt< TVecPool< TVal > > PVecPool
Definition: ds.h:2818
TPt< TFltVP > PFltV
Definition: ds.h:3091
~TLst()
Definition: ds.h:3589
int AddVMerged(const TVec< TVal > &ValV)
Definition: ds.h:2011
int GetSecHashCd() const
Definition: ds.h:3354
int SearchBack(const TVal &Val) const
Definition: ds.h:2436
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
Definition: ds.h:1130
TVec< TStrStrIntTr > TStrStrIntTrV
Definition: ds.h:2536
TFRec(const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)
Definition: ds.h:3776
int AddSorted(const TVal &Val, const bool &Asc=true, const int &_MxVals=-1)
Definition: ds.h:1977
unsigned long long uint64
Definition: bd.h:38
void GetHd(void *Hd)
Definition: fl.h:530
TLst< TFlt > TFltL
Definition: ds.h:3760
TVal & operator[](const int &ValN) const
Definition: ds.h:3077
const TVal & LastLast() const
Returns a reference to the one before last element of the vector.
Definition: ds.h:545
TVec< TFltFltStrTr > TFltFltStrTrV
Definition: ds.h:2524
TIter EndI() const
Definition: ds.h:1560
bool operator==(const TPair &Pair) const
Definition: ds.h:49
TPair< TInt, TIntPr > TIntIntPrPr
Definition: ds.h:85
TInt MxLen
Definition: ds.h:3489
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:255
static PVecPool Load(TSIn &SIn)
Definition: ds.h:2836
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:2606
void Swap(const int &ValN1, const int &ValN2)
Definition: ds.h:1586
TLstNd()
Definition: ds.h:3561
bool IsInBin(const TVal &Val) const
Checks whether element Val is a member of the vector.
Definition: ds.h:790
TInt XDim
Definition: ds.h:3289
bool IsExt() const
Returns true if the vector was created using the GenExt().
Definition: ds.h:504
void CopyTree(const int &SrcNodeId, TTree &DstTree, const int &DstParentNodeId=-1)
Definition: ds.h:3419
TVec< TUInt64FltKd > TUInt64FltKdV
Definition: ds.h:2514
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
Definition: ds.h:792
bool Empty() const
Definition: ds.h:3122
TQuad< TInt, TInt, TFlt, TFlt > TIntIntFltFltQu
Definition: ds.h:257
bool IsExt() const
Definition: ds.h:1535
TPair< TBool, TCh > TBoolChPr
Definition: ds.h:76
TVec< TFltUInt64Kd > TFltUInt64KdV
Definition: ds.h:2518
#define TSizeMx
Definition: bd.h:59
TVec< TVal > & operator=(const TVec< TVal > &Vec)
Definition: ds.h:1853
void Clr(bool DoDel=true)
Clears the contents of the pool.
Definition: ds.h:2637
TCmpTripleByVal2(const bool &AscSort=true)
Definition: ds.h:192
TVVec< TFlt > TFltVV
Definition: ds.h:3280
int GetSecHashCd() const
Definition: ds.h:356
TCmpTripleByVal3(const bool &AscSort=true)
Definition: ds.h:204
bool IsNext() const
Definition: ds.h:3569
int AddV(const TVec< TVal > &ValV)
Definition: ds.h:1970
TVVVec< TFlt > TFltVVV
Definition: ds.h:3333
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:672
void Resize(const ::TSize &_MxVals)
Definition: ds.h:2888
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3)
Returns a vector on elements Val1...Val3.
Definition: ds.h:808
void Save(TSOut &SOut) const
Definition: ds.h:346
int UnionLen(const TVec< TVal > &ValV) const
Returns the size of the union with vector ValV. Method assumes both vectors are sorted in ascending o...
Definition: ds.h:2376
void Load(TSIn &SIn)
Definition: dt.h:1056
size_t TSize
Definition: bd.h:58
void Reverse(int First, int Last)
Definition: ds.h:1600
#define Assert(Cond)
Definition: bd.h:251
TTree< TFlt > TFltTree
Definition: ds.h:3444
TSStack< TInt > TIntS
Definition: ds.h:3481
void Gen(const int &_MxVals, const int &_Vals)
Definition: ds.h:1528
TInt YDim
Definition: ds.h:3289
TVal * TIter
Definition: ds.h:1483
int GetPrimHashCd() const
Definition: ds.h:3353
TVal & Last()
Returns a reference to the last element of the vector.
Definition: ds.h:541
TVec< TUInt64StrKd > TUInt64StrKdV
Definition: ds.h:2515
TSizeTy SearchVForw(const TVec< TVal, TSizeTy > &ValV, const TSizeTy &BValN=0) const
Returns the starting position of vector ValV.
Definition: ds.h:1454
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:693
PVec< TVal > & operator=(const PVec< TVal > &Vec)
Definition: ds.h:3073
void SwapY(const int &Y1, const int &Y2)
Definition: ds.h:3178
const TVal & TopHeap() const
Definition: ds.h:1610
bool IsAsc
Definition: ds.h:118
const TVal & GetEmptyVal() const
Returns the reference to an empty value.
Definition: ds.h:2592
void Save(TSOut &SOut) const
Definition: ds.h:3460
TPair< TUInt64, TUInt64 > TUInt64Pr
Definition: ds.h:94
int IntrsLen(const TVec< TVal > &ValV) const
Returns the size of the intersection (number of common elements) with vector ValV. Method assumes both vectors are sorted in ascending order!
Definition: ds.h:2362
TVecPool< TInt > TIntVecPool
Definition: ds.h:3045
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2)
Definition: ds.h:1768
TVal4 Val4
Definition: ds.h:218
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:814
void PutAll(const TVal &Val)
Sets the values of all elements in the pool to Val.
Definition: ds.h:2642
int Len() const
Definition: ds.h:3524
Compares the triple by the second value.
Definition: ds.h:188
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:539
TQQueue< TFlt > TFltQ
Definition: ds.h:3544
TPt< TAscFltVP > PAscFltV
Definition: ds.h:3093
static int GetHashCd(const int hc1, const int hc2)
Definition: bd.h:590
static PVecPool Load(TSIn &SIn)
Definition: ds.h:2576
void Clr()
Definition: ds.h:3595
TLst< TStr > TStrL
Definition: ds.h:3766
TSizeTy MxVals
Vector capacity. Capacity is the size of allocated storage. If MxVals==-1, then ValT is not owned by ...
Definition: ds.h:424
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:71
Definition: ds.h:4
TVec< TCh > TChV
Definition: ds.h:2470
TTriple< TInt, TInt, TVec< TInt, int > > TIntIntIntVTr
Definition: ds.h:174
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
bool operator<(const TTuple &Tup) const
Definition: ds.h:281
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
TQuad< TFlt, TFlt, TFlt, TFlt > TFltQu
Definition: ds.h:254
TRec * Addr
Definition: ds.h:6
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:175
const TVal & operator()(const int &X, const int &Y, const int &Z) const
Definition: ds.h:3323
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:103
TQQueue(const TQQueue &Queue)
Definition: ds.h:3496
::TSize Reserved() const
Definition: ds.h:2845
TPair< TInt, TStr > TIntStrPr
Definition: ds.h:88
TVec< TStrIntKd > TStrIntKdV
Definition: ds.h:2530
int GetMxValN() const
Definition: ds.h:2456
TVVec()
Definition: ds.h:3105
void AddXDim()
Definition: ds.h:3221
void Gen(const int &_XDim, const int &_YDim)
Definition: ds.h:3124
const TVal & operator[](const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:466
int Len()
Definition: ds.h:3471
void GetMxValXY(int &X, int &Y) const
Definition: ds.h:3203
Definition: fl.h:491
TAPt & operator=(TRec *_Addr)
Definition: ds.h:15
TTriple< TUInt64, TUInt64, TUInt64 > TUInt64Tr
Definition: ds.h:167
void BSort(const int &MnLValN, const int &MxRValN, const bool &Asc)
Definition: ds.h:2087
#define FailR(Reason)
Definition: bd.h:240
PVec< TFlt > TFltVP
Definition: ds.h:3090
TLstNd< TVal > * PLstNd
Definition: ds.h:3581
TSizeTy IntrsLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the intersection of vectors this and ValV.
Definition: ds.h:1378
TFRec & operator=(const TFRec &)
TVal GetVal(const int &ValN) const
Definition: ds.h:3081
TVVec(const TVec< TVal > &_ValV, const int &_XDim, const int &_YDim)
Definition: ds.h:3110
TVVec< TBool > TBoolVV
Definition: ds.h:3276
const TVal & Top() const
Definition: ds.h:3525
TPair< TInt, TCh > TIntChPr
Definition: ds.h:82
TPair< TIntPr, TInt > TIntPrIntPr
Definition: ds.h:90
int AddUnique(const TVal &Val)
Definition: ds.h:2018
const TVal & operator()(const int &X, const int &Y) const
Definition: ds.h:3141
void PutHd(const THd &Hd)
Definition: ds.h:3787
Definition: ds.h:3487
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
Compares the triple by the third value.
Definition: ds.h:200
TVec(const int &_MxVals, const int &_Vals)
Definition: ds.h:1496
void GetRow(const int &RowN, TVec< TVal > &Vec) const
Definition: ds.h:3259
Definition: ds.h:3452
Definition: fl.h:128
TVec< TAscFltIntPr > TAscFltIntPrV
Definition: ds.h:2525
TVec< TFltUInt64Pr > TFltUInt64PrV
Definition: ds.h:2493
TPair< TBool, TFlt > TBoolFltPr
Definition: ds.h:77
TVVVec(const TVVVec &Vec)
Definition: ds.h:3293
int GetRecs()
Definition: fl.cpp:830
void DelY(const int &Y)
Definition: ds.h:3247
int SearchBin(const TVal &Val) const
Definition: ds.h:2407
PLstNd AddFrontSorted(const TVal &Val, const bool &Asc=true)
Definition: ds.h:3659
TVal & GetNodeVal(const int &NodeId)
Definition: ds.h:3372
TKeyDat< TUInt, TInt > TUIntIntKd
Definition: ds.h:376
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1418
TTriple()
Definition: ds.h:135
TVal & GetAddDat(const TVal &Val)
Returns reference to the first occurrence of element Val.
Definition: ds.h:796
void SetVal(const TSizeTy &ValN, const TVal &Val)
Sets the value of element at position ValN to Val.
Definition: ds.h:599
int GetRecN()
Definition: fl.cpp:823
TFunc()
Definition: ds.h:3799
int Add(const TVal &Val, const int &ResizeLen)
Definition: ds.h:1567
void Save(const bool &Bool)
Definition: fl.h:173
static TPt< PVec< TVal > > Load(TSIn &SIn)
Definition: ds.h:3070
TPair< TStr, TStrV > TStrStrVPr
Definition: ds.h:108
TPair< TAscFlt, TAscFlt > TAscFltPr
Definition: ds.h:102
TVec< TIntStrIntIntQu > TIntStrIntIntQuV
Definition: ds.h:2541
static TIter GetPivotValNCmp(const TIter &BI, const TIter &EI, const TCmp &Cmp)
Definition: ds.h:1648
TVec< TVal > ValV
Definition: ds.h:3103
#define max(a, b)
Definition: bd.h:350
TLstNd< TAscFltIntKd > * PAscFltIntKdLN
Definition: ds.h:3765
TPair< TUCh, TUInt64 > TUChUInt64Pr
Definition: ds.h:79
~TVecPool()
Definition: ds.h:2573
TTriple< TInt, TFlt, TFlt > TIntFltFltTr
Definition: ds.h:172
Definition: dt.h:1041
TQuad()
Definition: ds.h:220
TVal * TIter
Random access iterator to TVal.
Definition: ds.h:422
TVVec< TInt > TIntVV
Definition: ds.h:3278
PLstNd Last() const
Definition: ds.h:3603
int GetPrimHashCd() const
Definition: ds.h:155
TFuncPt operator()() const
Definition: ds.h:3811
TVec< TVal > & operator+(const TVal &Val)
Definition: ds.h:1509
static TPt< PVec< TVal > > New(const int &MxVals, const int &Vals)
Definition: ds.h:3064
TVec< TFltIntIntIntQu > TFltIntIntIntQuV
Definition: ds.h:2540
TVec< TUChIntPr > TUChIntPrV
Definition: ds.h:2486
void Gen(const int &_XDim, const int &_YDim, const int &_ZDim)
Definition: ds.h:3312
TVec< TStrIntPr > TStrIntPrV
Definition: ds.h:2528
const TVal & operator[](const int &ValN) const
Definition: ds.h:3509
void ShuffleAll(TRnd &Rnd=TInt::Rnd)
Definition: ds.h:3036
TVec< TChA > TChAV
Definition: ds.h:2479
TPair< TAscFlt, TStr > TAscFltStrPr
Definition: ds.h:104
TLstNd< TStr > * PStrLN
Definition: ds.h:3767
const TVal & At(const int &X, const int &Y, const int &Z) const
Definition: ds.h:3318
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:811
TVVec< TStr > TStrVV
Definition: ds.h:3281
TTriple< TInt, TVec< TInt, int >, TInt > TIntIntVIntTr
Definition: ds.h:173
TVec< TIntStrVPr > TIntStrVPrV
Definition: ds.h:2507
TQQueue< TIntStrPr > TIntStrPrQ
Definition: ds.h:3547
bool PrevPerm()
Generates previous permutation of the elements in the vector.
Definition: ds.h:1289
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:564
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:75
int Add(const TVal &Val)
Definition: ds.h:1565
Definition: ds.h:3287
TVal & GetVal(const TSizeTy &ValN)
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:597
void DelLast()
Definition: ds.h:1581
int GetSecHashCd() const
Definition: ds.h:57
void MakeHeap(const int &First, const int &Len, const TCmp &Cmp)
Definition: ds.h:1639
void ISort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Insertion sorts the values between positions MnLValN...MxLValN.
Definition: ds.h:1148
int Reserved() const
Definition: ds.h:1548
TKeyDat(const TKey &_Key, const TDat &_Dat)
Definition: ds.h:344
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
Definition: ds.h:1086
int GetPrimHashCd() const
Definition: ds.h:355
TVec< TStr > TStrV
Definition: ds.h:2478
void Save(TSOut &SOut) const
Definition: ds.h:3345
void Push()
Definition: ds.h:3474
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:817
TKeyDat< TFlt, TIntPr > TFltIntPrKd
Definition: ds.h:384
void Ins(const int &ValN, const TVal &Val)
Definition: ds.h:2037
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:686
static int GetRnd(const int &Range=0)
Definition: dt.h:1082
void Reserve(const TSize &MxVals)
Reserves enough capacity for the pool to store MxVals elements.
Definition: ds.h:2590
void DelFirst()
Definition: ds.h:3616
TLstNd< TIntKd > * PIntKdLN
Definition: ds.h:3759
TQuad(const TQuad &Quad)
Definition: ds.h:222
TKeyDat & operator=(const TKeyDat &KeyDat)
Definition: ds.h:350
Definition: ds.h:32
TKeyDat< TUInt64, TInt > TUInt64IntKd
Definition: ds.h:378
void GetRec(void *Rec, const int &RecN=-1)
Definition: fl.h:534
TVec< TFltBoolKd > TFltBoolKdV
Definition: ds.h:2516
TSizeTy LastValN() const
Returns the position of the last element.
Definition: ds.h:543
TVec< TUInt64StrPr > TUInt64StrPrV
Definition: ds.h:2512
PLstNd AddBack(const TVal &Val)
Definition: ds.h:3651
bool Empty() const
Definition: ds.h:3079
void ShuffleY(TRnd &Rnd)
Definition: ds.h:3198
bool Empty() const
Definition: ds.h:1546
TVec< TIntStrPrPr > TIntStrPrPrV
Definition: ds.h:2506
void PutV(const int &VId, const TValV &ValV)
Definition: ds.h:2863
static PVecPool New(const ::TSize &ExpectVals=0, const ::TSize &GrowBy=1000000, const bool &FastCopy=false)
Definition: ds.h:2834
TKeyDat< TIntPr, TFlt > TIntPrFltKd
Definition: ds.h:372
void AddYDim()
Definition: ds.h:3228
TKeyDat< TStr, TBool > TStrBoolKd
Definition: ds.h:391
TStr GetStr() const
Definition: ds.h:296
TVec(const TSizeTy &_Vals)
Constructs a vector (an array) of length _Vals.
Definition: ds.h:435
bool Empty() const
Definition: ds.h:26
TKey Key
Definition: ds.h:338
TPt< TStrVP > PStrV
Definition: ds.h:3095
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:3443
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:820
void Load(TSIn &SIn)
Definition: ds.h:43
void GenExt(TVal *_ValT, const int &_Vals)
Definition: ds.h:1532
TVec< TUInt64 > TUInt64V
Definition: ds.h:2474
TVec< TFlt > TFltV
Definition: ds.h:2475
bool IsIn(const TVal &Val, int &ValN) const
Definition: ds.h:1752
bool Empty() const
Definition: ds.h:3310
TVal & GetAddDat(const TVal &Val)
Definition: ds.h:1759
int AddRoot(const TVal &NodeVal=TVal())
Definition: ds.h:3364
PFRnd FRnd
Definition: ds.h:3774
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
static TVec< TVal > GetV(const TVal &Val1)
Definition: ds.h:1766
TVal GetXY(const int &X, const int &Y) const
Definition: ds.h:3150
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:470
TSizeTy UnionLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the union of vectors this and ValV.
Definition: ds.h:1392
void Del(const TVal &Val)
Definition: ds.h:3719
TVVec< TSFlt > TSFltVV
Definition: ds.h:3279
const TVal & operator[](const int &ValN) const
Definition: ds.h:1512
TLst()
Definition: ds.h:3587
TVec< TIntQu > TIntQuV
Definition: ds.h:2482
void Union(const TVec< TVal, TSizeTy > &ValV)
Result is the union of this vector with ValV.
Definition: ds.h:1317
void Pop()
Definition: ds.h:3476
TLstNd(TLstNd *_PrevNd, TLstNd *_NextNd, const TVal &_Val)
Definition: ds.h:3563
TKeyDat< TUInt, TUInt > TUIntKd
Definition: ds.h:377
TVec< TUChUInt64Pr > TUChUInt64PrV
Definition: ds.h:2487
TIter GetI(const int &ValN) const
Definition: ds.h:1561
void Trunc(const int &_Vals=-1)
Definition: ds.h:1914
Definition: dt.h:412
Definition: ds.h:213
void PutBack(const PLstNd &Nd)
Definition: ds.h:3694
void Resize(const int &_MxVals=-1)
Definition: ds.h:1789
void QSort(const int &MnLValN, const int &MxRValN, const bool &Asc)
Definition: ds.h:2159
TSizeTy Partition(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Partitions the values between positions MnLValN...MxLValN.
Definition: ds.h:1186
TSStack< TBoolChPr > TBoolChS
Definition: ds.h:3482
static TVec< TVal > 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)
Definition: ds.h:1782
TTriple< TStr, TStr, TStr > TStrTr
Definition: ds.h:180
TKeyDat(const TKeyDat &KeyDat)
Definition: ds.h:342
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Definition: ds.h:550
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TQuad & operator=(const TQuad &Quad)
Definition: ds.h:233
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:1223
void Pack()
The vector reduces its capacity (frees memory) to match its size.
Definition: ds.h:987
void PushHeap(const int &First, int HoleIdx, const int &Top, TVal Val, const TCmp &Cmp)
Definition: ds.h:1618
TCRef CRef
Definition: ds.h:2555
bool IsPrev() const
Definition: ds.h:3568
bool operator<(const TAPt &Pt) const
Definition: ds.h:18
TQQueue(const int &_MxLast=64, const int &_MxLen=-1)
Definition: ds.h:3493
TVec< TFltStrPrPr > TFltStrPrPrV
Definition: ds.h:2522
TAPt & operator=(const TAPt &Pt)
Definition: ds.h:14
int Add(const TVal &Val)
Definition: ds.h:3083
TVec< TVal, TSizeTy > & operator+(const TVal &Val)
Appends value Val to the vector.
Definition: ds.h:458
int GetVecs() const
Returns the total number of vectors stored in the vector pool.
Definition: ds.h:2582
TPair< TInt, TStrPr > TIntStrPrPr
Definition: ds.h:111
bool operator<(const TVec< TVal > &Vec) const
Definition: ds.h:1873
int Len() const
Definition: ds.h:273
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:705
int Partition(const int &MnLValN, const int &MxRValN, const bool &Asc)
Definition: ds.h:2139
void DelX(const int &X)
Definition: ds.h:3235
TCmpPairByVal2(const bool &AscSort=true)
Definition: ds.h:120
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
Definition: ds.h:1235
void Save(TSOut &SOut) const
Definition: ds.h:1846
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
Definition: ds.h:1440
int GetXDim() const
Definition: ds.h:3325
int GetPivotValN(const int &LValN, const int &RValN) const
Definition: ds.h:2119
static PVecPool Load(const TStr &FNm)
Definition: ds.h:2577
TVec(const int &_Vals)
Definition: ds.h:1493
TPair< TStr, TInt > TStrIntPr
Definition: ds.h:105
TQQueue< TStr > TStrQ
Definition: ds.h:3545
void ShuffleAll(TRnd &Rnd=TInt::Rnd)
Shuffles the order of all elements in the pool.
Definition: ds.h:2796
TBool FastCopy
Definition: ds.h:2556
TKeyDat< TFlt, TUInt > TFltUIntKd
Definition: ds.h:385
TTuple(const TVal &InitVal)
Definition: ds.h:267
TVecPool(const ::TSize &ExpectVals=0, const ::TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
Definition: ds.h:2915
TKeyDat< TInt, TInt > TIntKd
Definition: ds.h:369
bool IsIn(const TVal &Val, TSizeTy &ValN) const
Checks whether element Val is a member of the vector.
Definition: ds.h:786
TTriple< TCh, TInt, TInt > TChIntIntTr
Definition: ds.h:164
void GetV(const int &VId, TValV &ValV) const
Definition: ds.h:2860
TVal * ValBf
Definition: ds.h:2825
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
TVec< uint64, int > IdToOffV
Definition: ds.h:2560
const TVal & Last() const
Definition: ds.h:1549
TSStack & operator=(const TSStack &Stack)
Definition: ds.h:3462
TVecPool(const TSize &ExpectVals=0, const TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
Vector pool constructor.
Definition: ds.h:2676
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2)
Returns a vector on elements Val1, Val2.
Definition: ds.h:805
TVal1 Val1
Definition: ds.h:34
bool NextPerm()
Definition: ds.h:2213
TVec< TInt > TIntV
Definition: ds.h:2473
TVal2 Val2
Definition: ds.h:35
TKeyDat< TInt, TSFlt > TIntSFltKd
Definition: ds.h:374
TAPt(const TAPt &Pt)
Definition: ds.h:9
TVal ValV[NVals]
Definition: ds.h:264
int GetYDim() const
Definition: ds.h:3128
Definition: bd.h:196
TKeyDat(TSIn &SIn)
Definition: ds.h:345
void Push(const TVal &Val)
Definition: ds.h:3530
void Sort(const bool &Asc=true)
Definition: ds.h:302
TCmpKeyDatByDat(const bool &AscSort=true)
Definition: ds.h:404
void Reverse()
Reverses the order of the elements in the vector.
Definition: ds.h:1250
bool operator<(const TPair &Pair) const
Definition: ds.h:51
#define AssertR(Cond, Reason)
Definition: bd.h:258
void SwapX(const int &X1, const int &X2)
Definition: ds.h:3172
TQuad< TInt, TStr, TInt, TInt > TIntStrIntIntQu
Definition: ds.h:256
void GenRandomTree(const int &Nodes, TRnd &Rnd)
Definition: ds.h:3396
int GetZDim() const
Definition: ds.h:3327
void Swap(TVVec< TVal > &Vec)
Definition: ds.h:3184
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:1053
void Clr(const bool &DoDel=true, const int &NoDelLim=-1)
Definition: ds.h:1904
int GetChildren(const int &NodeId) const
Definition: ds.h:3370
TInt MxLast
Definition: ds.h:3489
void ShuffleX(TRnd &Rnd)
Definition: ds.h:3193
TVec()
Definition: ds.h:432
TTriple< TInt, TInt, TInt > TIntTr
Definition: ds.h:166
TSizeTy AddBackSorted(const TVal &Val, const bool &Asc)
Adds element Val to a sorted vector.
Definition: ds.h:1042
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TVal & GetVal(const int &ValN)
Definition: ds.h:1576
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
TVal & GetVal()
Definition: ds.h:3572
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:818
TVal & operator[](const int &ValN)
Definition: ds.h:1515
Definition: ds.h:3795
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
TSizeTy Count(const TVal &Val) const
Counts the number of occurrences of Val in the vector.
Definition: ds.h:1410
bool operator==(const TVec< TVal, TSizeTy > &Vec) const
Checks that the two vectors have the same contents.
Definition: ds.h:903
void PushHeap(const TVal &Val)
Definition: ds.h:1609
int AddBackSorted(const TVal &Val, const bool &Asc)
Definition: ds.h:1992
TQQueue< TFltV > TFltVQ
Definition: ds.h:3548
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
Definition: ds.h:506
void MoveFrom(TVec< TVal, TSizeTy > &Vec)
Takes over the data and the capacity from Vec.
Definition: ds.h:1002
bool operator==(const TTriple &Triple) const
Definition: ds.h:149
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:3758
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:439
TVec< TIntFltIntTr > TIntFltIntTrV
Definition: ds.h:2499
TIter BegI() const
Definition: ds.h:1559
static TPt< PVec< TVal > > New()
Definition: ds.h:3061
void Load(TSIn &SIn)
Definition: ds.h:1837
Definition: ds.h:3772
TTuple()
Definition: ds.h:266
void Clr(const bool &DoDel=true)
Definition: ds.h:3512
TLst< TFltIntKd > TFltIntKdL
Definition: ds.h:3762
TFunc & operator=(const TFunc &Func)
Definition: ds.h:3805
TVVec< TIntPr > TIntPrVV
Definition: ds.h:3282
void Resize(const TSizeTy &_MxVals=-1)
Resizes the vector so that it can store at least _MxVals.
Definition: ds.h:831
int GetMemUsed() const
Definition: ds.h:3356
static TVec< TVal, TSizeTy > GetV(const TVal &Val1)
Returns a vector on element Val1.
Definition: ds.h:802
TRec & operator*() const
Definition: ds.h:21
TVec< TUInt64FltPr > TUInt64FltPrV
Definition: ds.h:2511
TVec< TBool > TBoolV
Definition: ds.h:2465
TVVVec< TVal > & operator=(const TVVVec< TVal > &Vec)
Definition: ds.h:3302
static TPt< PVec< TVal > > New(const TVec< TVal > &V)
Definition: ds.h:3067
TKeyDat< TFlt, TInt > TFltIntKd
Definition: ds.h:382
void SortCmp(const TCmp &Cmp)
Sorts the elements of the vector using the comparator Cmp.
Definition: ds.h:713
TPair< TFlt, TUInt64 > TFltUInt64Pr
Definition: ds.h:98
TVal PopHeap(const TCmp &Cmp)
Definition: ds.h:1614
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:239
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:490
Definition: ds.h:3338
void GetVal(TVal1 &_Val1, TVal2 &_Val2, TVal3 &_Val3) const
Definition: ds.h:159
void BSort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Bubble sorts the values between positions MnLValN...MxLValN.
Definition: ds.h:1135
TKeyDat< TInt, TUInt64 > TIntUInt64Kd
Definition: ds.h:370
TSizeTy Vals
Vector length. Length is the number of elements stored in the vector.
Definition: ds.h:425
TVec(TSIn &SIn)
Definition: ds.h:449
TVec< TVal > & Get1DVec()
Definition: ds.h:3131
TVec< TFltIntPr > TFltIntPrV
Definition: ds.h:2492
bool IsVId(const int &VId) const
Tests whether vector of id VId is in the pool.
Definition: ds.h:2586
void Clr()
Definition: ds.h:3358
int Len() const
Definition: ds.h:1547
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TTuple(const TTuple &Tup)
Definition: ds.h:268
void Pack()
Definition: ds.h:1937
TSizeTy GetMemSize() const
Returns the memory size (the number of bytes) of a binary representation.
Definition: ds.h:477
TPt< TIntVecPool > PIntVecPool
Definition: ds.h:3048
void CompactPool(const TVal &DelVal)
Definition: ds.h:3007
TLstNd< TInt > * PIntLN
Definition: ds.h:3757
TVVVec< TInt > TIntVVV
Definition: ds.h:3332
Definition: dt.h:881
TVec< TFltKd > TFltKdV
Definition: ds.h:2520
void DelLast()
Removes the last element of the vector.
Definition: ds.h:609
bool IsAsc
Definition: ds.h:402
TTree(const TTree &Tree)
Definition: ds.h:3343
PLstNd SearchForw(const TVal &Val)
Definition: ds.h:3735
TTriple< TInt, TInt, TStr > TIntIntStrTr
Definition: ds.h:169
void Trunc(const TSizeTy &_Vals=-1)
Truncates the vector's length and capacity to _Vals elements.
Definition: ds.h:964
static void SwapI(TIter LVal, TIter RVal)
Swaps the elements that iterators LVal and RVal point to.
Definition: ds.h:620
bool IsAsc
Definition: ds.h:190
TVec< TIntFltKd > TIntFltKdV
Definition: ds.h:2503
TPair & operator=(const TPair &Pair)
Definition: ds.h:47
TKeyDat< TStr, TAscFlt > TStrAscFltKd
Definition: ds.h:394
TVec< TQQueue< TInt > > TIntQV
Definition: ds.h:3550
int GetCols() const
Definition: ds.h:3130
TBool FastCopy
Definition: ds.h:2822
bool operator<(const TTree &Tree) const
Definition: ds.h:3351
void Intrs(const TVec< TVal > &ValV)
Definition: ds.h:2256
TFAccess
Definition: fl.h:347
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
Definition: ds.h:554
int GetRows() const
Definition: ds.h:3129
TVal * GetValVPt(const int &VId) const
Definition: ds.h:2857
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:826
TPair< TUCh, TInt > TUChIntPr
Definition: ds.h:78
TLstNd * PrevNd
Definition: ds.h:3557
TVal PopHeap()
Definition: ds.h:1611
TLst< TAscFltIntKd > TAscFltIntKdL
Definition: ds.h:3764
TPair< TUInt64, TInt > TUInt64IntPr
Definition: ds.h:93
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:3133
TSize Vals
Definition: ds.h:2557
TSize MxVals
Definition: ds.h:2557
void GetRec(TRec &Rec, const int &RecN=-1)
Definition: ds.h:3788
TQuad(TSIn &SIn)
Definition: ds.h:226
void PutY(const int &Y, const TVal &Val)
Definition: ds.h:3148
int GetPrimHashCd() const
Definition: ds.h:288
TVec< TIntStrIntTr > TIntStrIntTrV
Definition: ds.h:2500
TStr GetXOutOfBoundsErrMsg(const int &ValN) const
Definition: ds.h:1821
void PutAll(const TVal &Val)
Definition: ds.h:3145
TLstNd< TFltIntKd > * PFltIntKdLN
Definition: ds.h:3763
void GetSubValV(const int &_BValN, const int &_EValN, TVec< TVal > &SubValV) const
Definition: ds.h:3515
TStr GetXOutOfBoundsErrMsg(const TSizeTy &ValN) const
Constructs the out of bounds error message.
Definition: ds.h:861
TSizeTy SearchBack(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1447
TKeyDat< TFlt, TUInt64 > TFltUInt64Kd
Definition: ds.h:383
::TSize GetMemUsed() const
Definition: ds.h:2849
bool operator==(const TVec< TVal > &Vec) const
Definition: ds.h:1864
TVal * ValT
Definition: ds.h:426
TLst< TInt > TIntL
Definition: ds.h:3756
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:508
TTriple< TFlt, TInt, TInt > TFltIntIntTr
Definition: ds.h:176
TQuad(const TVal1 &_Val1, const TVal2 &_Val2, const TVal3 &_Val3, const TVal4 &_Val4)
Definition: ds.h:224
bool operator!=(const TAPt &Pt) const
Definition: ds.h:17
int Add()
Definition: ds.h:1563
bool IsIn(const TVal &Val) const
Definition: ds.h:3470
TVec< TIntStrPr > TIntStrPrV
Definition: ds.h:2496
TVal3 Val3
Definition: ds.h:133
PLstNd First() const
Definition: ds.h:3602
Compares the pair by the second value.
Definition: ds.h:116
TVec< TIntUInt64Kd > TIntUInt64KdV
Definition: ds.h:2489
TVVVec()
Definition: ds.h:3292
TVal & GetDat(const TVal &Val) const
Definition: ds.h:1756
void Save(TSOut &SOut) const
Definition: ds.h:270
TSizeTy GetMxValN() const
Returns the position of the largest element in the vector.
Definition: ds.h:1467
TVec< TUCh > TUChV
Definition: ds.h:2471
static void QSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Definition: ds.h:1699
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568
TKeyDat< TStr, TStr > TStrKd
Definition: ds.h:395
TTriple & operator=(const TTriple &Triple)
Definition: ds.h:146
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:420
TTriple< TUCh, TInt, TInt > TUChIntIntTr
Definition: ds.h:165
int AddEmptyV(const int &ValVLen)
Definition: ds.h:2997
TVec< TFltStrKd > TFltStrKdV
Definition: ds.h:2521
int GetMemUsed() const
Definition: ds.h:157
TPair< TUInt64, TStr > TUInt64StrPr
Definition: ds.h:96
void WrTree(const int &NodeId=0, const int &Lev=0)
Definition: ds.h:3430
TTriple< TStr, TFlt, TFlt > TStrFltFltTr
Definition: ds.h:182
TTriple< TChA, TChA, TChA > TChATr
Definition: ds.h:179
bool IsSortedCmp(const TCmp &Cmp) const
Definition: ds.h:1725
static void ISortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Definition: ds.h:1688
TVec< TVal > ValV
Definition: ds.h:3454
TSizeTy AddV(const TVec< TVal, TSizeTy > &ValV)
Adds the elements of the vector ValV to the to end of the vector.
Definition: ds.h:1020
void GetSubValV(const TSizeTy &BValN, const TSizeTy &EValN, TVec< TVal, TSizeTy > &ValV) const
Returns a vector on elements at positions BValN...EValN.
Definition: ds.h:1076
bool operator<(const TTriple &Triple) const
Definition: ds.h:151
TLstNd * Next() const
Definition: ds.h:3571
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:699
int Count(const TVal &Val) const
Definition: ds.h:2399
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5)
Definition: ds.h:1774
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:823