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