31 template <
class TVal1,
class TVal2>
39 TPair(
const TVal1& _Val1,
const TVal2& _Val2):
Val1(_Val1),
Val2(_Val2){}
63 return TStr(
"Pair(")+
Val1.GetStr()+
", "+
Val2.GetStr()+
")";}
66 template <
class TVal1,
class TVal2,
class TSizeTy>
68 const TSizeTy Prs = SrcPrV.Len();
70 for (TSizeTy PrN=0; PrN<Prs; PrN++){
115 template <
class TVal1,
class TVal2>
128 template <
class TVal1,
class TVal2,
class TVal3>
138 TTriple(
const TVal1& _Val1,
const TVal2& _Val2,
const TVal3& _Val3):
159 void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3)
const {
192 template <
class TVal1,
class TVal2,
class TVal3>
204 template <
class TVal1,
class TVal2,
class TVal3>
217 template <
class TVal1,
class TVal2,
class TVal3,
class TVal4>
229 TQuad(
const TVal1& _Val1,
const TVal2& _Val2,
const TVal3& _Val3,
const TVal4& _Val4):
252 void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3, TVal4& _Val4)
const {
270 template<
class TVal,
int NVals>
276 TTuple(
const TVal& InitVal) {
for (
int i=0; i<
Len(); i++)
ValV[i]=InitVal; }
282 int Len()
const {
return NVals; }
286 for (
int i=0; i<
Len(); i++)
ValV[i]=Tup[i]; }
return *
this; }
288 if (
Len()!=Tup.
Len()) {
return false; }
if (&Tup==
this) {
return true; }
289 for (
int i=0; i<
Len(); i++)
if(
ValV[i]!=Tup[i]){
return false;}
return true; }
291 if (
Len() == Tup.
Len()) {
for (
int i=0; i<
Len(); i++) {
292 if(
ValV[i]<Tup[i]){
return true;}
else if(
ValV[i]>Tup[i]){
return false;} }
return false; }
293 else {
return Len() < Tup.
Len(); } }
294 void Sort(
const bool& Asc=
true);
306 for (
int i=0; i<
Len(); i++) { ValsStr+=
" "+
ValV[i].GetStr(); }
310 template<
class TVal,
int NVals>
313 for (
int i=0; i<NVals; i++) { V.
Add(ValV[i]); }
315 for (
int i=0; i<NVals; i++) { ValV[i] = V[i]; }
318 template<
class TVal,
int NVals>
320 TVal MxVal = ValV[0];
322 for (
int i = 1; i < NVals; i++) {
324 MxVal=ValV[i]; ValN=i;
330 template<
class TVal,
int NVals>
332 TVal MnVal = ValV[0];
334 for (
int i = 1; i < NVals; i++) {
336 MnVal=ValV[i]; ValN=i;
344 template <
class TKey,
class TDat>
360 if (
this!=&KeyDat){
Key=KeyDat.
Key;
Dat=KeyDat.
Dat;}
return *
this;}
368 template <
class TKey,
class TDat>
370 const int Kds=SrcKdV.Len();
372 for (
int KdN=0; KdN<Kds; KdN++){
408 template <
class TVal1,
class TVal2>
428 template <
class TVal,
class TSizeTy =
int>
436 void Resize(
const TSizeTy& _MxVals=-1);
444 explicit TVec(
const TSizeTy& _Vals){
446 if (_Vals==0){
ValT=NULL;}
else {
ValT=
new TVal[_Vals];}}
448 TVec(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
450 if (_MxVals==0){
ValT=NULL;}
else {
ValT=
new TVal[_MxVals];}}
455 explicit TVec(TVal *_ValT,
const TSizeTy& _Vals):
473 bool operator<(const TVec<TVal, TSizeTy>& Vec)
const;
484 return TSizeTy(2*
sizeof(TSizeTy)+
sizeof(TVal*)+
MxVals*
sizeof(TVal));}
487 return TSizeTy(2*
sizeof(TVal)+
sizeof(TSizeTy)*
Vals);}
499 void Gen(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
IAssert((0<=_Vals)&&(_Vals<=_MxVals));
501 if (_MxVals==0){
ValT=NULL;}
else {
ValT=
new TVal[_MxVals];}}
506 void GenExt(TVal *_ValT,
const TSizeTy& _Vals){
522 void Clr(
const bool& DoDel=
true,
const TSizeTy& NoDelLim=-1);
526 void Trunc(
const TSizeTy& _Vals=-1);
574 TSizeTy
Add(){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
580 TSizeTy
Add(
const TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
582 TSizeTy
Add(TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
585 TSizeTy
Add(
const TVal& Val,
const TSizeTy& ResizeLen){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
588 TSizeTy
AddMP(
const TVal& Val){
const int Idx = __sync_fetch_and_add(&
Vals, 1);
590 ValT[Idx]=Val;
return Idx;}
594 TSizeTy
MoveLastMP(
const TVal& Val,
int Inc){
const int Idx = __sync_fetch_and_add(&
Vals, Inc);
602 TSizeTy
AddSorted(
const TVal& Val,
const bool& Asc=
true,
const TSizeTy& _MxVals=-1);
629 void Ins(
const TSizeTy& ValN,
const TVal& Val);
631 void Del(
const TSizeTy& ValN);
633 void Del(
const TSizeTy& MnValN,
const TSizeTy& MxValN);
639 void DelAll(
const TVal& Val);
641 void PutAll(
const TVal& Val);
644 void Swap(
const TSizeTy& ValN1,
const TSizeTy& ValN2){
const TVal Val=
ValT[ValN1];
ValT[ValN1]=
ValT[ValN2];
ValT[ValN2]=Val;}
646 static void SwapI(
TIter LVal,
TIter RVal){
const TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
661 TSizeTy
GetPivotValN(
const TSizeTy& LValN,
const TSizeTy& RValN)
const;
665 void BSort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
669 void ISort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
674 TSizeTy
Partition(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
679 void QSort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
684 void Sort(
const bool& Asc=
true);
686 bool IsSorted(
const bool& Asc=
true)
const;
692 void Reverse(TSizeTy LValN, TSizeTy RValN){
Assert(LValN>=0 && RValN<
Len());
while (LValN < RValN){
Swap(LValN++, RValN--);} }
697 template <
class TCmp>
699 TSizeTy SubVals=TSizeTy(EI-BI);
if (SubVals >
TInt::Mx-1) { SubVals =
TInt::Mx-1; }
701 const TVal& Val1 = *(BI+ValN1);
const TVal& Val2 = *(BI+ValN2);
const TVal& Val3 = *(BI+ValN3);
702 if (
Cmp(Val1, Val2)) {
703 if (
Cmp(Val2, Val3))
return BI+ValN2;
704 else if (
Cmp(Val3, Val1))
return BI+ValN1;
705 else return BI+ValN3;
707 if (
Cmp(Val1, Val3))
return BI+ValN1;
708 else if (
Cmp(Val3, Val2))
return BI+ValN2;
709 else return BI+ValN3; } }
711 template <
class TCmp>
714 while (
Cmp(*BI, Pivot)){++BI;} --EI;
715 while (
Cmp(Pivot, *EI)){--EI;}
716 if (!(BI<EI)){
return BI;}
SwapI(BI, EI); ++BI; } }
718 template <
class TCmp>
720 for (
TIter i = BI; i != EI; ++i) {
721 for (
TIter j = EI-1; j != i; --j) {
722 if (
Cmp(*j, *(j-1))) {
SwapI(j, j-1); } } } }
724 template <
class TCmp>
727 for (
TIter i = BI, j; i != EI; ++i) { TVal Tmp=*i; j=i;
728 while (j > BI &&
Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; } *j=Tmp; } } }
730 template <
class TCmp>
733 if (EI - BI < 20) {
ISortCmp(BI, EI, Cmp); }
738 template <
class TCmp>
741 template <
class TCmp>
745 if (
Cmp(*(i+1), *i)){
return false;} }
return true; }
768 TSizeTy
Count(
const TVal& Val)
const;
773 TSizeTy
SearchBin(
const TVal& Val)
const;
777 TSizeTy
SearchBin(
const TVal& Val, TSizeTy& InsValN)
const;
781 TSizeTy
SearchBinLeft(
const TVal& Val, TSizeTy& InsValN)
const;
786 TSizeTy
SearchForw(
const TVal& Val,
const TSizeTy& BValN=0)
const;
801 bool IsIn(
const TVal& Val, TSizeTy& ValN)
const { ValN=
SearchForw(Val);
return ValN!=-1;}
811 TVal&
GetAddDat(
const TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
832 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6){
835 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){
838 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){
841 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){
845 template <
class TVal,
class TSizeTy>
847 IAssertR(MxVals!=-1,
TStr::Fmt(
"Can not increase the capacity of the vector. %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
GetTypeNm(*this).
CStr()).CStr());
848 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());
850 if (Vals==0){MxVals=16;}
else {MxVals*=2;}
852 if (_MxVals<=MxVals){
return;}
else {MxVals=_MxVals;}
859 ValT=
new TVal[MxVals];
861 catch (std::exception Ex){
862 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.]",
865 TVal* NewValT = NULL;
867 NewValT=
new TVal[MxVals];
869 catch (std::exception Ex){
870 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.]",
873 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
874 delete[] ValT; ValT=NewValT;
878 template <
class TVal,
class TSizeTy>
887 template <
class TVal,
class TSizeTy>
890 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
891 for (TSizeTy ValN=0; ValN<Vec.
Vals; ValN++){ValT[ValN]=Vec.
ValT[ValN];}
894 template <
class TVal,
class TSizeTy>
896 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
897 SIn.
Load(MxVals); SIn.
Load(Vals); MxVals=Vals;
898 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
899 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=TVal(SIn);}
902 template <
class TVal,
class TSizeTy>
904 if (MxVals!=-1){SOut.
Save(MxVals);}
else {SOut.
Save(Vals);}
906 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
909 template <
class TVal,
class TSizeTy>
912 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
913 MxVals=Vals=Vec.
Vals;
914 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
915 for (TSizeTy ValN=0; ValN<Vec.
Vals; ValN++){ValT[ValN]=Vec.
ValT[ValN];}
920 template <
class TVal,
class TSizeTy>
922 if (
this==&Vec){
return true;}
923 if (Len()!=Vec.
Len()){
return false;}
924 for (TSizeTy ValN=0; ValN<Vals; ValN++){
925 if (ValT[ValN]!=Vec.
ValT[ValN]){
return false;}}
929 template <
class TVal,
class TSizeTy>
931 if (
this==&Vec){
return false;}
932 if (Len()==Vec.
Len()){
933 for (TSizeTy ValN=0; ValN<Vals; ValN++){
934 if (ValT[ValN]<Vec.
ValT[ValN]){
return true;}
935 else if (ValT[ValN]>Vec.
ValT[ValN]){
return false;}
940 return Len()<Vec.
Len();
947 template <
class TVal,
class TSizeTy>
950 for (TSizeTy i=0; i<Vals; i++){
959 template <
class TVal,
class TSizeTy>
962 for (TSizeTy i=0; i<Vals; i++){
970 template <
class TVal,
class TSizeTy>
972 if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){
973 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
974 MxVals=Vals=0; ValT=NULL;
976 IAssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
981 template <
class TVal,
class TSizeTy>
983 IAssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
984 IAssert((_Vals==-1)||(_Vals>=0));
985 if ((_Vals!=-1)&&(_Vals>=Vals)){
988 if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){
989 if (ValT!=NULL){
delete[] ValT;}
990 MxVals=Vals=0; ValT=NULL;
993 if (MxVals==Vals){
return;}
else {MxVals=Vals;}
997 TVal* NewValT=
new TVal[MxVals];
999 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1000 delete[] ValT; ValT=NewValT;
1004 template <
class TVal,
class TSizeTy>
1006 IAssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1008 if (ValT!=NULL){
delete[] ValT;} ValT=NULL;
1012 TVal* NewValT=
new TVal[MxVals];
1014 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1015 delete[] ValT; ValT=NewValT;
1019 template <
class TVal,
class TSizeTy>
1022 if (ValT!=NULL && MxVals!=-1){
delete[] ValT;}
1028 template <
class TVal,
class TSizeTy>
1031 if (ValT!=NULL && MxVals!=-1 && MxVals < Sz){
1035 if (Sz == 0) { Vals = 0;
return; }
1036 ValT[0] = Vec.
ValT[Offset];
1038 for (TSizeTy ValN=1; ValN<Sz; ValN++){
1039 if (ValT[Vals-1] != Vec.
ValT[Offset+ValN]) {
1040 ValT[Vals++] = Vec.
ValT[Offset+ValN];
1046 template <
class TVal,
class TSizeTy>
1055 template <
class TVal,
class TSizeTy>
1057 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1058 for (TSizeTy ValN=0; ValN<ValV.
Vals; ValN++){Add(ValV[ValN]);}
1062 template <
class TVal,
class TSizeTy>
1064 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1065 TSizeTy ValN=Add(Val);
1067 while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){
1068 Swap(ValN, ValN-1); ValN--;}
1070 while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){
1071 Swap(ValN, ValN-1); ValN--;}
1073 if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);}
1077 template <
class TVal,
class TSizeTy>
1079 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1081 TSizeTy ValN=Vals-2;
1082 while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
1083 ValT[ValN+1]=ValT[ValN]; ValN--;}
1088 template <
class TVal,
class TSizeTy>
1090 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1091 TSizeTy ValN=SearchBin(Val);
1092 if (ValN==-1){
return AddSorted(Val);}
1093 else {GetVal(ValN)=Val;
return -1;}
1096 template <
class TVal,
class TSizeTy>
1098 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1099 for (TSizeTy ValN=0; ValN<ValV.
Vals; ValN++){AddMerged(ValV[ValN]);}
1103 template <
class TVal,
class TSizeTy>
1105 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1106 TSizeTy ValN=SearchForw(Val);
1107 if (ValN==-1){
return Add(Val);}
1108 else {GetVal(ValN)=Val;
return -1;}
1111 template <
class TVal,
class TSizeTy>
1115 const TSizeTy SubVals=
TInt::GetMx(0, EValN-BValN+1);
1116 SubValV.
Gen(SubVals, 0);
1117 for (TSizeTy ValN=BValN; ValN<=EValN; ValN++){
1118 SubValV.
Add(GetVal(ValN));}
1121 template <
class TVal,
class TSizeTy>
1123 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1124 Add();
Assert((0<=ValN)&&(ValN<Vals));
1125 for (TSizeTy MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
1129 template <
class TVal,
class TSizeTy>
1131 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1132 Assert((0<=ValN)&&(ValN<Vals));
1133 for (TSizeTy MValN=ValN+1; MValN<Vals; MValN++){
1134 ValT[MValN-1]=ValT[MValN];}
1135 ValT[--Vals]=TVal();
1138 template <
class TVal,
class TSizeTy>
1140 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1141 Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
1143 for (TSizeTy ValN=MxValN+1; ValN<Vals; ValN++){
1144 ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
1145 for (TSizeTy ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
1147 Vals-=MxValN-MnValN+1;
1150 template <
class TVal,
class TSizeTy>
1152 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1153 TSizeTy ValN=SearchForw(Val);
1154 if (ValN!=-1){Del(ValN);
return true;}
1155 else {
return false;}
1158 template <
class TVal,
class TSizeTy>
1160 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1162 while ((ValN=SearchForw(Val))!=-1){Del(ValN);}
1165 template <
class TVal,
class TSizeTy>
1167 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
1170 template <
class TVal,
class TSizeTy>
1172 for (TSizeTy ValN1=MnLValN; ValN1<=MxRValN; ValN1++){
1173 for (TSizeTy ValN2=MxRValN; ValN2>ValN1; ValN2--){
1175 if (ValT[ValN2]<ValT[ValN2-1]){
Swap(ValN2, ValN2-1);}
1177 if (ValT[ValN2]>ValT[ValN2-1]){
Swap(ValN2, ValN2-1);}
1183 template <
class TVal,
class TSizeTy>
1185 if (MnLValN<MxRValN){
1186 for (TSizeTy ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){
1187 TVal Val=ValT[ValN1]; TSizeTy ValN2=ValN1;
1189 while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){
1190 ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1192 while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){
1193 ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1200 template <
class TVal,
class TSizeTy>
1202 TSizeTy SubVals=RValN-LValN+1;
1207 const TVal& Val1=ValT[ValN1];
1208 const TVal& Val2=ValT[ValN2];
1209 const TVal& Val3=ValT[ValN3];
1211 if (Val2<Val3){
return ValN2;}
1212 else if (Val3<Val1){
return ValN1;}
1213 else {
return ValN3;}
1215 if (Val1<Val3){
return ValN1;}
1216 else if (Val3<Val2){
return ValN2;}
1217 else {
return ValN3;}
1221 template <
class TVal,
class TSizeTy>
1223 TSizeTy PivotValN=GetPivotValN(MnLValN, MxRValN);
1224 Swap(PivotValN, MnLValN);
1225 TVal PivotVal=ValT[MnLValN];
1226 TSizeTy LValN=MnLValN-1; TSizeTy RValN=MxRValN+1;
1229 do {RValN--;}
while (ValT[RValN]>PivotVal);
1230 do {LValN++;}
while (ValT[LValN]<PivotVal);
1232 do {RValN--;}
while (ValT[RValN]<PivotVal);
1233 do {LValN++;}
while (ValT[LValN]>PivotVal);
1235 if (LValN<RValN){
Swap(LValN, RValN);}
1236 else {
return RValN;}
1240 template <
class TVal,
class TSizeTy>
1242 if (MnLValN<MxRValN){
1243 if (MxRValN-MnLValN<20){
1244 ISort(MnLValN, MxRValN, Asc);
1246 TSizeTy SplitValN=Partition(MnLValN, MxRValN, Asc);
1247 QSort(MnLValN, SplitValN, Asc);
1248 QSort(SplitValN+1, MxRValN, Asc);
1253 template <
class TVal,
class TSizeTy>
1255 QSort(0, Len()-1, Asc);
1258 template <
class TVal,
class TSizeTy>
1261 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1262 if (ValT[ValN]>ValT[ValN+1]){
return false;}}
1264 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1265 if (ValT[ValN]<ValT[ValN+1]){
return false;}}
1270 template <
class TVal,
class TSizeTy>
1273 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1274 const int Range = int(Vals-ValN);
1278 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1279 const TSizeTy Range = Vals-ValN;
1285 template <
class TVal,
class TSizeTy>
1287 for (TSizeTy ValN=0; ValN<Vals/2; ValN++){
1288 Swap(ValN, Vals-ValN-1);}
1291 template <
class TVal,
class TSizeTy>
1293 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1296 for (TSizeTy ValN=0; ValN<SortedVec.
Len(); ValN++){
1297 if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){
1298 Add(SortedVec[ValN]);}
1302 template <
class TVal,
class TSizeTy>
1305 TSizeTy First = 0, Last = Len(), Next = Len()-1;
1306 if (Last < 2)
return false;
1309 TSizeTy Next1 = Next;
1310 if (GetVal(--Next) < GetVal(Next1)) {
1312 for (; GetVal(Next) >= GetVal(--Mid); ) { }
1314 Reverse(Next1, Last-1);
1317 if (Next == First) {
1324 template <
class TVal,
class TSizeTy>
1326 TSizeTy First = 0, Last = Len(), Next = Len()-1;
1327 if (Last < 2)
return false;
1330 TSizeTy Next1 = Next;
1331 if (GetVal(--Next) >= GetVal(Next1)) {
1333 for (; GetVal(Next) < GetVal(--Mid); ) { }
1335 Reverse(Next1, Last);
1338 if (Next == First) {
1345 template <
class TVal,
class TSizeTy>
1348 Intrs(ValV, IntrsVec);
1352 template <
class TVal,
class TSizeTy>
1355 Union(ValV, UnionVec);
1359 template <
class TVal,
class TSizeTy>
1362 Diff(ValV, DiffVec);
1366 template <
class TVal,
class TSizeTy>
1369 TSizeTy ValN1=0, ValN2=0;
1370 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1371 const TVal& Val1=GetVal(ValN1);
1372 while ((ValN2<ValV.
Len())&&(Val1>ValV.
GetVal(ValN2))){
1374 if ((ValN2<ValV.
Len())&&(Val1==ValV.
GetVal(ValN2))){
1375 DstValV.
Add(Val1); ValN2++;}
1380 template <
class TVal,
class TSizeTy>
1383 TSizeTy ValN1=0, ValN2=0;
1384 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1385 const TVal& Val1=GetVal(ValN1);
1386 const TVal& Val2=ValV.
GetVal(ValN2);
1387 if (Val1<Val2){DstValV.
Add(Val1); ValN1++;}
1388 else if (Val1>Val2){DstValV.
Add(Val2); ValN2++;}
1389 else {DstValV.
Add(Val1); ValN1++; ValN2++;}
1391 for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1392 DstValV.
Add(GetVal(RestValN1));}
1393 for (TSizeTy RestValN2=ValN2; RestValN2<ValV.
Len(); RestValN2++){
1397 template <
class TVal,
class TSizeTy>
1400 TSizeTy ValN1=0, ValN2=0;
1401 while (ValN1<Len() && ValN2<ValV.
Len()) {
1402 const TVal& Val1 = GetVal(ValN1);
1403 while (ValN2<ValV.
Len() && Val1>ValV.
GetVal(ValN2)) ValN2++;
1404 if (ValN2<ValV.
Len()) {
1405 if (Val1!=ValV.
GetVal(ValN2)) { DstValV.
Add(Val1); }
1409 for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1410 DstValV.
Add(GetVal(RestValN1));}
1413 template <
class TVal,
class TSizeTy>
1415 TSizeTy Cnt=0, ValN1=0, ValN2=0;
1416 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1417 const TVal& Val1=GetVal(ValN1);
1418 while ((ValN2<ValV.
Len())&&(Val1>ValV.
GetVal(ValN2))){
1420 if ((ValN2<ValV.
Len())&&(Val1==ValV.
GetVal(ValN2))){
1427 template <
class TVal,
class TSizeTy>
1429 TSizeTy Cnt = 0, ValN1 = 0, ValN2 = 0;
1430 while ((ValN1 < Len()) && (ValN2 < ValV.
Len())) {
1431 const TVal& Val1 = GetVal(ValN1);
1432 const TVal& Val2 = ValV.
GetVal(ValN2);
1435 }
else if (Val1 > Val2) {
1438 Cnt++; ValN1++; ValN2++;
1441 Cnt += (Len() - ValN1) + (ValV.
Len() - ValN2);
1445 template <
class TVal,
class TSizeTy>
1448 for (TSizeTy i = 0; i < Len(); i++){
1449 if (Val == ValT[i]){Count++;}}
1453 template <
class TVal,
class TSizeTy>
1455 TSizeTy LValN=0, RValN=Len()-1;
1456 while (RValN>=LValN){
1457 TSizeTy ValN=(LValN+RValN)/2;
1458 if (Val==ValT[ValN]){
return ValN;}
1459 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
1464 template <
class TVal,
class TSizeTy>
1466 TSizeTy LValN=0, RValN=Len()-1;
1467 while (RValN>=LValN){
1468 TSizeTy ValN=(LValN+RValN)/2;
1469 if (Val==ValT[ValN]){InsValN=ValN;
return ValN;}
1470 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
1472 InsValN=LValN;
return -1;
1475 template <
class TVal,
class TSizeTy>
1477 TSizeTy LValN=0, RValN=Len()-1;
1478 while (RValN>=LValN){
1479 TSizeTy ValN=(LValN+RValN)/2;
1480 if (Val==ValT[ValN]){InsValN=ValN;
return ValN;}
1481 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
1483 InsValN=RValN;
return -1;
1486 template <
class TVal,
class TSizeTy>
1488 for (TSizeTy ValN=BValN; ValN<Vals; ValN++){
1489 if (Val==ValT[ValN]){
return ValN;}}
1493 template <
class TVal,
class TSizeTy>
1495 for (TSizeTy ValN=Vals-1; ValN>=0; ValN--){
1496 if (Val==ValT[ValN]){
return ValN;}}
1500 template <
class TVal,
class TSizeTy>
1502 TSizeTy ValVLen=ValV.
Len();
1503 for (TSizeTy ValN=BValN; ValN<Vals-ValVLen+1; ValN++){
1505 for (TSizeTy SubValN=0; SubValN<ValVLen; SubValN++){
1506 if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=
false;
break;}
1508 if (Found){
return ValN;}
1513 template <
class TVal,
class TSizeTy>
1515 if (Vals==0){
return -1;}
1517 for (TSizeTy ValN=1; ValN<Vals; ValN++){
1518 if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
1606 template <
class TVal,
class TSizeTy=
int>
1627 TVecPool(
const TSize& ExpectVals=0,
const TSize& _GrowBy=1000000,
const bool& _FastCopy=
false,
const TVal& _EmptyVal=TVal());
1680 for (::
TSize ValN=0; ValN <
::TSize(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1704 template <
class TVal,
class TSizeTy>
1706 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
1707 if (ValBf == NULL) {
1708 try { ValBf =
new TVal [MxVals]; }
1709 catch (std::exception Ex) {
1710 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()); }
1712 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1715 TVal* NewValBf = NULL;
1716 try { NewValBf =
new TVal [MxVals]; }
1717 catch (std::exception Ex) {
1718 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()); }
1721 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
1723 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1724 if (EmptyVal != TVal()) {
1725 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1732 template <
class TVal,
class TSizeTy>
1738 template <
class TVal,
class TSizeTy>
1742 catch (std::exception Ex) {
1751 template <
class TVal,
class TSizeTy>
1753 uint64 _GrowBy, _MxVals, _Vals;
1759 for (
TSize ValN = 0; ValN <
Vals; ValN++) {
ValBf[ValN] = TVal(SIn); }
1762 for (
int ValN = 0; ValN <
Vals; ValN++) {
1768 template <
class TVal,
class TSizeTy>
1770 SOut.
Save(FastCopy);
1771 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1772 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
1773 SOut.
Save(EmptyVal);
1774 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1775 { SOut.
Save(IdToOffV.Len()); SOut.
Save(IdToOffV.Len());
1776 for (
int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
1777 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
1781 template <
class TVal,
class TSizeTy>
1791 ValBf =
new TVal [MxVals]; }
1792 catch (std::exception Ex) {
1793 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()); }
1796 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
1798 for (
TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
1803 template <
class TVal,
class TSizeTy>
1806 if (ValVLen == 0) {
return 0; }
1807 if (MxVals < Vals+ValVLen) { Resize(Vals+
MAX(ValVLen, GrowBy)); }
1808 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
1809 else {
for (
TSize ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1810 Vals+=ValVLen; IdToOffV.
Add(Vals);
1811 return IdToOffV.Len()-1;
1814 template <
class TVal,
class TSizeTy>
1816 if (ValVLen==0){
return 0;}
1817 if (MxVals < Vals+ValVLen){Resize(Vals+
MAX(
TSize(ValVLen), GrowBy)); }
1818 Vals+=ValVLen; IdToOffV.Add(Vals);
1819 return IdToOffV.Len()-1;
1823 template <
class TVal,
class TSizeTy>
1827 for (
int vid = 1; vid < IdToOffV.Len(); vid++) {
1829 const uint Len = GetVLen(vid);
1830 TVal* ValV = GetValVPt(vid);
1831 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
1832 if (Len == 0) {
continue; }
1834 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
1837 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
1838 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
1842 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
1845 IdToOffV.Last() -= TotalDel;
1846 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
1852 template <
class TVal,
class TSizeTy>
1854 for (::
TSize n = Vals-1; n > 0; n--) {
1856 const TVal Tmp = ValBf[n];
1857 ValBf[n] = ValBf[k];
1869 namespace TGLib_OLD {
1872 template<
class TVal>
1912 if (VId==0){
return 0;}
1925 for (
uint ValN=0; ValN <
uint(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1944 template <
class TVal>
1946 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
1947 if (ValBf == NULL) {
1948 try { ValBf =
new TVal [MxVals]; }
1949 catch (std::exception Ex) {
1950 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()); }
1952 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1955 TVal* NewValBf = NULL;
1956 try { NewValBf =
new TVal [MxVals]; }
1957 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()); }
1960 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
1962 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1963 if (EmptyVal != TVal()) {
1964 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1971 template <
class TVal>
1973 GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
1978 template <
class TVal>
1980 FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy),
1981 MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
1983 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVecPool::TVecPool: %s, MxVals: %d", Ex.what(),
MxVals).CStr()); }
1991 template <
class TVal>
1994 uint64 _GrowBy, _MxVals, _Vals;
2000 for (
TSize ValN = 0; ValN <
Vals; ValN++) {
ValBf[ValN] = TVal(SIn); }
2003 for (
int ValN = 0; ValN <
Vals; ValN++) {
2009 template <
class TVal>
2011 SOut.
Save(FastCopy);
2012 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2013 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
2014 SOut.
Save(EmptyVal);
2015 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2016 { SOut.
Save(IdToOffV.Len()); SOut.
Save(IdToOffV.Len());
2017 for (
int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
2018 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
2022 template <
class TVal>
2031 try { ValBf =
new TVal [MxVals]; }
2032 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVec::operator= : %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
2035 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
2037 for (
uint64 ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
2042 template<
class TVal>
2045 if (ValVLen == 0) {
return 0; }
2046 if (MxVals < Vals+ValVLen) { Resize(Vals+
MAX(ValVLen, GrowBy)); }
2047 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
2048 else {
for (
uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2049 Vals+=ValVLen; IdToOffV.
Add(Vals);
2050 return IdToOffV.Len()-1;
2053 template<
class TVal>
2055 if (ValVLen==0){
return 0;}
2056 if (MxVals < Vals+ValVLen){Resize(Vals+
MAX(
TSize(ValVLen), GrowBy)); }
2057 Vals+=ValVLen; IdToOffV.Add(Vals);
2058 return IdToOffV.Len()-1;
2063 template<
class TVal>
2067 for (
int vid = 1; vid < IdToOffV.Len(); vid++) {
2069 const uint Len = GetVLen(vid);
2070 TVal* ValV = GetValVPt(vid);
2071 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
2072 if (Len == 0) {
continue; }
2074 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
2077 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
2078 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
2082 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
2085 IdToOffV.Last() -= TotalDel;
2086 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
2092 template<
class TVal>
2094 for (::
TSize n = Vals-1; n > 0; n--) {
2096 const TVal Tmp = ValBf[n];
2097 ValBf[n] = ValBf[k];
2109 template <
class TVal>
2131 if (
this!=&Vec){
V=Vec.
V;}
return *
this;}
2133 bool operator<(const PVec<TVal>& Vec)
const {
return V<Vec.V;}
2138 TVal
GetVal(
const int& ValN)
const {
return V[ValN];}
2156 template <
class TVal>
2165 TVVec(
const int& _XDim,
const int& _YDim):
2181 void Gen(
const int& _XDim,
const int& _YDim){
2182 Assert((_XDim>=0)&&(_YDim>=0));
2190 const TVal&
At(
const int& X,
const int& Y)
const {
2193 TVal&
At(
const int& X,
const int& Y){
2201 void PutXY(
const int& X,
const int& Y,
const TVal& Val){
At(X, Y)=Val;}
2203 void PutX(
const int& X,
const TVal& Val){
2204 for (
int Y=0; Y<int(
YDim); Y++){
At(X, Y)=Val;}}
2205 void PutY(
const int& Y,
const TVal& Val){
2206 for (
int X=0; X<int(
XDim); X++){
At(X, Y)=Val;}}
2207 TVal
GetXY(
const int& X,
const int& Y)
const {
2213 void SwapX(
const int& X1,
const int& X2);
2214 void SwapY(
const int& Y1,
const int& Y2);
2224 void DelX(
const int& X);
2225 void DelY(
const int& Y);
2228 template <
class TVal>
2230 for (
int Y=0; Y<int(YDim); Y++){
2231 TVal Val=At(X1, Y); At(X1, Y)=At(X2, Y); At(X2, Y)=Val;}
2234 template <
class TVal>
2236 for (
int X=0; X<int(XDim); X++){
2237 TVal Val=At(X, Y1); At(X, Y1)=At(X, Y2); At(X, Y2)=Val;}
2240 template <
class TVal>
2245 ValV.Swap(Vec.
ValV);
2249 template <
class TVal>
2251 for (
int X=0; X<XDim-1; X++){SwapX(X, X+Rnd.
GetUniDevInt(XDim-X));}
2254 template <
class TVal>
2256 for (
int Y=0; Y<YDim-1; Y++){SwapY(Y, Y+Rnd.
GetUniDevInt(YDim-Y));}
2259 template <
class TVal>
2261 int MxValN=ValV.GetMxValN();
2266 template <
class TVal>
2270 for (
int X=0; X<CopyXDim; X++){
2271 for (
int Y=0; Y<CopyYDim; Y++){
2272 At(X, Y)=VVec.
At(X, Y);
2277 template <
class TVal>
2284 template <
class TVal>
2291 template <
class TVal>
2294 for (
int Y=0; Y<YDim; Y++){
2295 for (
int LX=0; LX<X; LX++){
2296 NewVVec.
At(LX, Y)=At(LX, Y);}
2297 for (
int RX=X+1; RX<XDim; RX++){
2298 NewVVec.
At(RX-1, Y)=At(RX, Y);}
2303 template <
class TVal>
2306 for (
int X=0; X<XDim; X++){
2307 for (
int LY=0; LY<Y; LY++){
2308 NewVVec.
At(X, LY)=At(X, LY);}
2309 for (
int RY=Y+1; RY<YDim; RY++){
2310 NewVVec.
At(X, RY-1)=At(X, RY);}
2315 template <
class TVal>
2317 Vec.
Gen(GetCols(), 0);
2318 for (
int col = 0; col < GetCols(); col++) {
2319 Vec.
Add(At(RowN, col));
2323 template <
class TVal>
2325 Vec.
Gen(GetRows(), 0);
2326 for (
int row = 0; row < GetRows(); row++) {
2327 Vec.
Add(At(row, ColN));
2343 template <
class TVal>
2352 TVVVec(
const int& _XDim,
const int& _YDim,
const int& _ZDim):
2369 void Gen(
const int& _XDim,
const int& _YDim,
const int& _ZDim){
2370 Assert((_XDim>=0)&&(_YDim>=0)&&(_ZDim>=0));
2372 TVal&
At(
const int& X,
const int& Y,
const int& Z){
2375 const TVal&
At(
const int& X,
const int& Y,
const int& Z)
const {
2379 return At(X, Y, Z);}
2380 const TVal&
operator()(
const int& X,
const int& Y,
const int& Z)
const {
2381 return At(X, Y, Z);}
2394 template <
class TVal>
2417 int AddNode(
const int& ParentNodeId,
const TVal& NodeVal=TVal()){
2419 if (ParentNodeId!=-1){
NodeV[ParentNodeId].Val2.Add(
NodeV.Len());}
2433 void DelNode(
const int& NodeId);
2434 void CopyTree(
const int& SrcNodeId,
TTree& DstTree,
const int& DstParentNodeId=-1);
2436 void WrTree(
const int& NodeId=0,
const int& Lev=0);
2439 template <
class TVal>
2441 if (NodeId==0){NodeIdV.
Clr();
if (GetNodes()==0){
return;}}
2442 else if (GetParentNodeId(NodeId)==-1){
return;}
2443 NodeIdV.
Add(NodeId);
2444 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2445 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2446 if (ChildNodeId!=-1){
2447 GetNodeIdV(NodeIdV, ChildNodeId);
2452 template <
class TVal>
2457 for (
int NodeN=1; NodeN<Nodes; NodeN++){
2459 AddNode(ParentNodeId, TVal());
2464 template <
class TVal>
2469 TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2470 int ChildNodeIdN=ChildNodeIdV.
SearchForw(NodeId);
2471 ChildNodeIdV[ChildNodeIdN]=-1;
2475 template <
class TVal>
2477 int DstNodeId=DstTree.
AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
2478 for (
int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
2479 int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
2480 if (ChildNodeId!=-1){
2481 CopyTree(ChildNodeId, DstTree, DstNodeId);
2486 template <
class TVal>
2488 for (
int LevN=0; LevN<Lev; LevN++){printf(
"| ");}
2489 printf(
"%d (%d)\n", NodeId, GetChildren(NodeId));
2490 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2491 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2492 if (ChildNodeId!=-1){
2493 WrTree(ChildNodeId, Lev+1);
2508 template <
class TVal>
2520 if (
this!=&Stack){
ValV=Stack.
ValV;}
return *
this;}
2543 template <
class TVal>
2550 TQQueue(
const int& _MxLast=64,
const int& _MxLen=-1):
2570 void Gen(
const int& _MxLast=64,
const int& _MxLen=-1){
2575 SubValV.
Gen(EValN-BValN+1);
2576 for (
int ValN=BValN; ValN<=EValN; ValN++){
2577 SubValV[ValN-BValN]=
ValV[
Last+ValN];}
2595 for (
int ValN=0; ValN<ValV.
Len(); ValN++){
Push(ValV[ValN]);}}
2611 template <
class TVal>
2635 template <
class TVal>
2654 while (Nd!=NULL){
PLstNd NextNd=Nd->
NextNd;
delete Nd; Nd=NextNd;}
2671 void Del(
const TVal& Val);
2682 template <
class TVal>
2684 Nds(0), FirstNd(NULL), LastNd(NULL){
2685 int CheckNds=0; SIn.
Load(CheckNds);
2686 for (
int NdN=0; NdN<CheckNds; NdN++){
AddBack(TVal(SIn));}
2690 template <
class TVal>
2693 PLstNd Nd=FirstNd;
int CheckNds=0;
2695 Nd->
Val.Save(SOut); Nd=Nd->
NextNd; CheckNds++;}
2699 template <
class TVal>
2702 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
2703 else {FirstNd=Nd; LastNd=Nd;}
2707 template <
class TVal>
2710 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
2711 else {FirstNd=Nd; LastNd=Nd;}
2715 template <
class TVal>
2719 return Ins(Nd, Val);
2721 while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
2723 if (Nd==NULL){
return Ins(Nd->Last(),
Val);}
2724 else {
return Ins(Nd->
Prev(),
Val);}
2728 template <
class TVal>
2731 while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->
Val)))){
2733 return Ins(Nd, Val);
2736 template <
class TVal>
2746 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
2747 else {FirstNd=Nd; LastNd=Nd;}
2750 template <
class TVal>
2760 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
2761 else {FirstNd=Nd; LastNd=Nd;}
2764 template <
class TVal>
2766 if (Nd==NULL){
return AddFront(Val);}
2767 else if (Nd->
NextNd==NULL){
return AddBack(Val);}
2775 template <
class TVal>
2777 PLstNd Nd=SearchForw(Val);
2778 if (Nd!=NULL){Del(Nd);}
2781 template <
class TVal>
2791 template <
class TVal>
2801 template <
class TVal>
2828 template <
class THd,
class TRec>
2834 FRnd(
PFRnd(new
TFRnd(FNm, FAccess, CreateIfNo, sizeof(THd), sizeof(TRec)))){}
2851 template <
class TFuncPt>
2867 Fail;
return false;}
TSizeTy AddUnique(const TVal &Val)
Adds element Val to a vector only if the element Val is not already in the vector.
void Save(TSOut &SOut) const
bool operator==(const TTree &Tree) const
TQuad< TStr, TStr, TStr, TStr > TStrQu
TVec< TFltIntKd > TFltIntKdV
bool operator==(const TVVec &Vec) const
void SaveXml(TSOut &SOut, const TStr &Nm) const
void GetV(const int &VId, TValV &ValV) const
Returns ValV which is a reference (not a copy) to vector with id VId.
const TVal & GetVal() const
TQQueue< TAscFltV > TAscFltVQ
TPair< TInt, TInt > TIntPr
TStr GetTypeNm(const Type &Var)
bool operator==(const PVec< TVal > &Vec) const
TTriple(const TTriple &Triple)
TVec< TUInt64IntPr > TUInt64IntPrV
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
TTree< TStrIntStrVTr > TStrIntStrVTrTree
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
TPair< TUCh, TStr > TUChStrPr
bool operator()(const TTriple< TVal1, TVal2, TVal3 > &T1, const TTriple< TVal1, TVal2, TVal3 > &T2) const
TTriple< TStr, TStr, TInt > TStrStrIntTr
TPair(const TVal1 &_Val1, const TVal2 &_Val2)
TVal & operator()(const int &X, const int &Y)
TSizeTy Reserved() const
Returns the size of allocated storage capacity.
TVec< TIntIntVIntTr > TIntIntVIntTrV
#define IAssertR(Cond, Reason)
TPair< TUInt, TUInt > TUIntUIntPr
TVec< TFltIntIntTr > TFltIntIntTrV
TVec< TIntIntFltTr > TIntIntFltTrV
TPair< TFlt, TInt > TFltIntPr
int GetPrimHashCd() const
Returns primary hash code of the vector. Used by THash.
TTriple< TInt, TStr, TInt > TIntStrIntTr
void PutX(const int &X, const TVal &Val)
bool operator<(const TFunc &) const
void SaveXml(TSOut &SOut, const TStr &Nm) const
bool operator==(const TQuad &Quad) const
PLstNd Ins(const PLstNd &Nd, const TVal &Val)
bool operator()(const TPair< TVal1, TVal2 > &P1, const TPair< TVal1, TVal2 > &P2) const
void Save(TSOut &SOut) const
void Merge()
Sorts the vector and only keeps a single element of each value.
TVec< TAscFltIntKd > TAscFltIntKdV
TTuple & operator=(const TTuple &Tup)
int64 GetUniDevInt64(const int64 &Range=0)
void Save(TSOut &SOut) const
static int GetInRng(const int &Val, const int &Mn, const int &Mx)
bool operator==(const TVVVec &Vec) const
TQQueue & operator=(const TQQueue &Queue)
TTriple< TStr, TInt, TStrV > TStrIntStrVTr
TPair< TStr, TStr > TStrPr
TVVec< TVal > & operator=(const TVVec< TVal > &Vec)
TPair< TStr, TFlt > TStrFltPr
TVal & At(const int &X, const int &Y)
PLstNd SearchBack(const TVal &Val)
TSStack(const TSStack &Stack)
uint64 Reserved() const
Returns the total capacity of the pool.
TPair< TUInt64, TFlt > TUInt64FltPr
void DelNode(const int &NodeId)
static PVecPool New(const TSize &ExpectVals=0, const TSize &GrowBy=1000000, const bool &FastCopy=false)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
void Save(TSOut &SOut) const
TVec< TStrFltKd > TStrFltKdV
int AddV(const TValV &ValV)
Adds vector ValV to the pool and returns its id.
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
TKeyDat< TFlt, TBool > TFltBoolKd
TVec< TIntIntStrTr > TIntIntStrTrV
void Push(const TVal &Val)
void Save(TSOut &SOut) const
bool operator()(const TKeyDat< TVal1, TVal2 > &P1, const TKeyDat< TVal1, TVal2 > &P2) const
bool operator==(const TSStack &Stack) const
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
bool operator<(const TVec< TVal, TSizeTy > &Vec) const
Lexicographically compares two vectors.
TVecPool & operator=(const TVecPool &Pool)
void Reserve(const ::TSize &MxVals)
TKeyDat(const TKey &_Key)
TVec< TIntStrKd > TIntStrKdV
int GetParentNodeId(const int &NodeId) const
int GetChildNodeId(const int &NodeId, const int &ChildN) const
TFunc(const TFuncPt &_FuncPt)
static int GetMx(const int &Int1, const int &Int2)
TVVVec(const int &_XDim, const int &_YDim, const int &_ZDim)
void QSort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Quick sorts the values between positions MnLValN...MxLValN.
PLstNd AddBackSorted(const TVal &Val, const bool &Asc=true)
const TVal1 & GetVal1() const
uint64 GetMemUsed() const
Returns the total memory footprint (in bytes) of the pool.
bool IsSortedCmp(const TCmp &Cmp) const
Checks whether the vector is sorted according to the comparator Cmp.
TKeyDat< TUInt64, TFlt > TUInt64FltKd
void SetEmptyVal(const TVal &_EmptyVal)
PVec< TAscFlt > TAscFltVP
void CopyFrom(const TVVec< TVal > &VVec)
TSizeTy Len() const
Returns the number of elements in the vector.
TKeyDat< TInt, TFlt > TIntFltKd
TVec< TIntIntIntVTr > TIntIntIntVTrV
void PutRec(const void *Rec, const int &RecN=-1)
int GetSecHashCd() const
Returns secondary hash code of the vector. Used by THash.
TVVec(const int &_XDim, const int &_YDim)
void GetSwitchedKdV(const TVec< TKeyDat< TKey, TDat >, int > &SrcKdV, TVec< TKeyDat< TDat, TKey >, int > &DstKdV)
void Diff(const TVec< TVal, TSizeTy > &ValV)
Subtracts ValV from this vector. Assumes the vectors are sorted!
const TVal3 & GetVal3() const
void Save(TSOut &SOut) const
void GenExt(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
TTriple< TInt, TInt, TFlt > TIntIntFltTr
void GetVal(TVal1 &_Val1, TVal2 &_Val2) const
TKeyDat< TInt, TFltPr > TIntFltPrKd
TVec< TFltStrPr > TFltStrPrV
TKeyDat< TUInt64, TStr > TUInt64StrKd
TVec< TIntFltPrKd > TIntFltPrKdV
TTriple(const TVal1 &_Val1, const TVal2 &_Val2, const TVal3 &_Val3)
TRec * operator->() const
TKeyDat< TFlt, TStr > TFltStrKd
TVal & operator()(const int &X, const int &Y, const int &Z)
void Save(TSOut &SOut) const
bool IsVId(const int &VId) const
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...
void Save(TSOut &SOut) const
void PutRec(const TRec &Rec, const int &RecN=-1)
TVal & GetRndVal(TRnd &Rnd=TInt::Rnd)
Returns a reference to a random element in the vector.
int AddV(const TValV &ValV)
void SetEmptyVal(const TVal &_EmptyVal)
Sets the empty value.
void Save(TSOut &SOut) const
TVec< TStrAscFltKd > TStrAscFltKdV
TKeyDat< TStr, TInt > TStrIntKd
void SetRecN(const int &RecN)
TTriple< TInt, TFlt, TInt > TIntFltIntTr
TVec< TIntIntPrPr > TIntIntPrPrV
TPair< TStrV, TInt > TStrVIntPr
TQQueue< TIntPr > TIntPrQ
const TVal2 & GetVal2() const
TSizeTy Add(const TVal &Val, const TSizeTy &ResizeLen)
Adds element Val at the end of the vector. #TVec::Add2.
TSizeTy SearchBinLeft(const TVal &Val, TSizeTy &InsValN) const
Returns the position of an element with value Val.
void Clr(const bool &DoDel=false)
bool operator==(const TKeyDat &KeyDat) const
void Swap(const TSizeTy &ValN1, const TSizeTy &ValN2)
Swaps elements at positions ValN1 and ValN2.
TKeyDat< TFlt, TFlt > TFltKd
TVec< TStrStrVPr > TStrStrVPrV
TTriple< TStr, TInt, TInt > TStrIntIntTr
void CompactPool(const TVal &DelVal)
Deletes all elements of value DelVal from all vectors.
TVal & At(const int &X, const int &Y, const int &Z)
TPair< TUInt, TInt > TUIntIntPr
PLstNd AddFront(const TVal &Val)
void CopyUniqueFrom(TVec< TVal, TSizeTy > &Vec, TInt Offset, TInt Sz)
Copy Sz values from Vec starting at Offset.
void Resize(const TSize &_MxVals)
TVec(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
TPair< TInt, TVec< TInt, int > > TIntIntVPr
TVal & LastLast()
Returns a reference to the one before last element of the vector.
TRec * operator()() const
TSizeTy GetMemUsed() const
Returns the memory footprint (the number of bytes) of the vector.
TVal & operator[](const int &ValN)
void PutFront(const PLstNd &Nd)
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...
TLst & operator=(const TLst &)
bool operator<(const TKeyDat &KeyDat) const
void Reduce(const TSizeTy &_Vals=-1)
Reduces the vector's length to _Vals elements, which must be less than the current length...
static PVecPool Load(const TStr &FNm)
TPt< TVecPool< TVal, TSizeTy > > PVecPool
void GetCol(const int &ColN, TVec< TVal > &Vec) const
bool operator()(const TTriple< TVal1, TVal2, TVal3 > &T1, const TTriple< TVal1, TVal2, TVal3 > &T2) const
TPair< TInt, TUInt64 > TIntUInt64Pr
void GetNodeIdV(TIntV &NodeIdV, const int &NodeId=0)
TSize GetVals() const
Returns the total number of values stored in the vector pool.
void PutAll(const TVal &Val)
TVecPool & operator=(const TVecPool &Pool)
TKeyDat< TFlt, TIntBoolPr > TFltIntBoolPrKd
const TVal & GetEmptyVal() const
bool operator==(const TAPt &Pt) const
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
TPair< TAscFlt, TInt > TAscFltIntPr
TKeyDat< TInt, TStr > TIntStrKd
void PutXY(const int &X, const int &Y, const TVal &Val)
int AddEmptyV(const int &ValVLen)
Adds a vector of length ValVLen to the pool and returns its id.
TQuad< TInt, TInt, TInt, TInt > TIntQu
void Clr(bool DoDel=true)
TPair< TInt, TBool > TIntBoolPr
TVal & operator[](const int &ValN)
void Save(TSOut &SOut) const
bool Empty() const
Tests whether the vector is empty.
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
void Save(TSOut &SOut) const
TPair< TInt, TStrV > TIntStrVPr
void Reverse(TSizeTy LValN, TSizeTy RValN)
Reverses the order of elements between LValN...RValN.
TTriple< TFlt, TFlt, TStr > TFltFltStrTr
void PutV(const int &VId, const TValV &ValV)
Sets the values of vector VId with those in ValV.
void DelAll(const TVal &Val)
Removes all occurrences of element Val.
void Intrs(const TVec< TVal, TSizeTy > &ValV)
Sets this vector to its intersection with ValV. Assumes the vectors are sorted!
TVec< TIntUInt64Pr > TIntUInt64PrV
TKeyDat< TStr, TFlt > TStrFltKd
const TVal & operator[](const int &ValN) const
TLstNd & operator=(const TLstNd &)
TPair< TInt, TFlt > TIntFltPr
uint GetVLen(const int &VId) const
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
TVec< TIntFltPr > TIntFltPrV
void GetVal(TVal1 &_Val1, TVal2 &_Val2, TVal3 &_Val3, TVal4 &_Val4) const
const TVal & GetRndVal(TRnd &Rnd=TInt::Rnd) const
Returns a reference to a random element in the vector.
TVec< TFltIntPrKd > TFltIntPrKdV
TSStack(const int &MxVals)
TTree & operator=(const TTree &Tree)
TVec< TStrFltPr > TStrFltPrV
TQuad< TStr, TStr, TInt, TInt > TStrStrIntIntQu
int GetPrimHashCd() const
TVec< TVal, TSizeTy > TValV
TSizeTy MoveLastMP(const TVal &Val, int Inc)
Reserves space after the current last element in a thread safe manner, returning the old vector size...
TSizeTy GetPivotValN(const TSizeTy &LValN, const TSizeTy &RValN) const
Picks three random elements at positions LValN...RValN and returns the middle one.
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
TTriple< TFlt, TFlt, TInt > TFltFltIntTr
void Gen(const int &_MxLast=64, const int &_MxLen=-1)
TVec< TStrFltFltTr > TStrFltFltTrV
void Save(TSOut &SOut) const
TKeyDat< TAscFlt, TInt > TAscFltIntKd
void SaveXml(TSOut &SOut, const TStr &Nm) const
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
void PutHd(const void *Hd)
TVec< TUInt64IntKd > TUInt64IntKdV
TPair< TFlt, TStrPr > TFltStrPrPr
bool operator==(const TFunc &Func) const
TVec< TIntPrFltKd > TIntPrFltKdV
TTriple< TCh, TCh, TCh > TChTr
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
TVec< TAscFltStrPr > TAscFltStrPrV
TVec< TStrVIntPr > TStrVIntPrV
static int GetMn(const int &Int1, const int &Int2)
TTree< TStrIntPr > TStrIntPrTree
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
bool operator==(const TTuple &Tup) const
bool NextPerm()
Generates next permutation of the elements in the vector.
TVec< TVal, TSizeTy > & operator=(const TVec< TVal, TSizeTy > &Vec)
Assigns new contents to the vector, replacing its current content.
TVec< TUIntIntKd > TUIntIntKdV
TPt< TVecPool< TVal > > PVecPool
const TVal1 & GetVal1() const
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
TVec< TStrStrIntTr > TStrStrIntTrV
TFRec(const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)
unsigned long long uint64
TVal & operator[](const int &ValN) const
const TVal & LastLast() const
Returns a reference to the one before last element of the vector.
TVec< TFltFltStrTr > TFltFltStrTrV
bool operator==(const TPair &Pair) const
TPair< TInt, TIntPr > TIntIntPrPr
void SaveXml(TSOut &SOut, const TStr &Nm) const
TQuad< TFlt, TInt, TInt, TInt > TFltIntIntIntQu
static PVecPool Load(TSIn &SIn)
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
bool IsInBin(const TVal &Val) const
Checks whether element Val is a member of the vector.
bool IsExt() const
Returns true if the vector was created using the GenExt().
void CopyTree(const int &SrcNodeId, TTree &DstTree, const int &DstParentNodeId=-1)
TVec< TUInt64FltKd > TUInt64FltKdV
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
TQuad< TInt, TInt, TFlt, TFlt > TIntIntFltFltQu
TPair< TBool, TCh > TBoolChPr
TVec< TFltUInt64Kd > TFltUInt64KdV
void Clr(bool DoDel=true)
Clears the contents of the pool.
TCmpTripleByVal2(const bool &AscSort=true)
TCmpTripleByVal3(const bool &AscSort=true)
const TVal2 & GetVal2() const
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...
void Resize(const ::TSize &_MxVals)
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3)
Returns a vector on elements Val1...Val3.
void Save(TSOut &SOut) const
int GetPrimHashCd() const
TVal & Last()
Returns a reference to the last element of the vector.
TVec< TUInt64StrKd > TUInt64StrKdV
TSizeTy SearchVForw(const TVec< TVal, TSizeTy > &ValV, const TSizeTy &BValN=0) const
Returns the starting position of vector ValV.
static void BSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Bubble sorts the values between positions BI...EI under the comparator Cmp.
PVec< TVal > & operator=(const PVec< TVal > &Vec)
void SwapY(const int &Y1, const int &Y2)
const TVal & GetEmptyVal() const
Returns the reference to an empty value.
const TVal2 & GetVal2() const
TTriple< TInt, TStr, TStr > TIntStrStrTr
void Save(TSOut &SOut) const
TPair< TUInt64, TUInt64 > TUInt64Pr
TVecPool< TInt > TIntVecPool
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.
void PutAll(const TVal &Val)
Sets the values of all elements in the pool to Val.
Compares the triple by the second value.
const TVal & Last() const
Returns a reference to the last element of the vector.
TPt< TAscFltVP > PAscFltV
static int GetHashCd(const int hc1, const int hc2)
static PVecPool Load(TSIn &SIn)
TSizeTy MxVals
Vector capacity. Capacity is the size of allocated storage. If MxVals==-1, then ValT is not owned by ...
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
TTriple< TInt, TInt, TVec< TInt, int > > TIntIntIntVTr
bool operator<(const TTuple &Tup) const
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
TQuad< TFlt, TFlt, TFlt, TFlt > TFltQu
TTriple< TFlt, TFlt, TFlt > TFltTr
const TVal & operator()(const int &X, const int &Y, const int &Z) const
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
TQQueue(const TQQueue &Queue)
TPair< TInt, TStr > TIntStrPr
TVec< TStrIntKd > TStrIntKdV
void Gen(const int &_XDim, const int &_YDim)
const TVal & operator[](const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
void GetMxValXY(int &X, int &Y) const
TAPt & operator=(TRec *_Addr)
TTriple< TUInt64, TUInt64, TUInt64 > TUInt64Tr
TSizeTy IntrsLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the intersection of vectors this and ValV. Assumes the vectors are sorted! ...
TFRec & operator=(const TFRec &)
TVal GetVal(const int &ValN) const
TVVec(const TVec< TVal > &_ValV, const int &_XDim, const int &_YDim)
TPair< TInt, TCh > TIntChPr
TPair< TIntPr, TInt > TIntPrIntPr
const TVal & operator()(const int &X, const int &Y) const
void PutHd(const THd &Hd)
TPair< TFlt, TFlt > TFltPr
Compares the triple by the third value.
void GetRow(const int &RowN, TVec< TVal > &Vec) const
TVec< TAscFltIntPr > TAscFltIntPrV
TVec< TFltUInt64Pr > TFltUInt64PrV
TPair< TBool, TFlt > TBoolFltPr
TVVVec(const TVVVec &Vec)
PLstNd AddFrontSorted(const TVal &Val, const bool &Asc=true)
TVal & GetNodeVal(const int &NodeId)
TKeyDat< TUInt, TInt > TUIntIntKd
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
TVal & GetAddDat(const TVal &Val)
Returns reference to the first occurrence of element Val.
void SetVal(const TSizeTy &ValN, const TVal &Val)
Sets the value of element at position ValN to Val.
void Save(const bool &Bool)
static TPt< PVec< TVal > > Load(TSIn &SIn)
TPair< TStr, TStrV > TStrStrVPr
TPair< TAscFlt, TAscFlt > TAscFltPr
TVec< TIntStrIntIntQu > TIntStrIntIntQuV
TLstNd< TAscFltIntKd > * PAscFltIntKdLN
TPair< TUCh, TUInt64 > TUChUInt64Pr
TTriple< TInt, TFlt, TFlt > TIntFltFltTr
TVal * TIter
Random access iterator to TVal.
int GetPrimHashCd() const
TFuncPt operator()() const
static TPt< PVec< TVal > > New(const int &MxVals, const int &Vals)
TVec< TFltIntIntIntQu > TFltIntIntIntQuV
TVec< TUChIntPr > TUChIntPrV
void Gen(const int &_XDim, const int &_YDim, const int &_ZDim)
TVec< TStrIntPr > TStrIntPrV
const TVal & operator[](const int &ValN) const
void ShuffleAll(TRnd &Rnd=TInt::Rnd)
TPair< TAscFlt, TStr > TAscFltStrPr
const TVal & At(const int &X, const int &Y, const int &Z) const
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4)
Returns a vector on elements Val1...Val4.
TTriple< TInt, TVec< TInt, int >, TInt > TIntIntVIntTr
TVec< TIntStrVPr > TIntStrVPrV
TQQueue< TIntStrPr > TIntStrPrQ
bool PrevPerm()
Generates previous permutation of the elements in the vector.
TSizeTy Add(const TVal &Val)
Adds a new element at the end of the vector, after its current last element.
void SaveXml(TSOut &SOut, const TStr &Nm) const
TVal & GetVal(const TSizeTy &ValN)
Returns a reference to the element at position ValN in the vector.
void ISort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Insertion sorts the values between positions MnLValN...MxLValN.
TKeyDat(const TKey &_Key, const TDat &_Dat)
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
int GetPrimHashCd() const
void Save(TSOut &SOut) const
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.
TKeyDat< TFlt, TIntPr > TFltIntPrKd
static TIter PartitionCmp(TIter BI, TIter EI, const TVal Pivot, const TCmp &Cmp)
Partitions the values between positions BI...EI under the comparator Cmp.
static int GetRnd(const int &Range=0)
void Reserve(const TSize &MxVals)
Reserves enough capacity for the pool to store MxVals elements.
TLstNd< TIntKd > * PIntKdLN
TKeyDat & operator=(const TKeyDat &KeyDat)
TKeyDat< TUInt64, TInt > TUInt64IntKd
void GetRec(void *Rec, const int &RecN=-1)
TVec< TFltBoolKd > TFltBoolKdV
TSizeTy LastValN() const
Returns the position of the last element.
TVec< TUInt64StrPr > TUInt64StrPrV
PLstNd AddBack(const TVal &Val)
TVec< TIntStrPrPr > TIntStrPrPrV
void PutV(const int &VId, const TValV &ValV)
static PVecPool New(const ::TSize &ExpectVals=0, const ::TSize &GrowBy=1000000, const bool &FastCopy=false)
TKeyDat< TIntPr, TFlt > TIntPrFltKd
TKeyDat< TStr, TBool > TStrBoolKd
TVec(const TSizeTy &_Vals)
Constructs a vector (an array) of length _Vals.
void GetSwitchedPrV(const TVec< TPair< TVal1, TVal2 >, TSizeTy > &SrcPrV, TVec< TPair< TVal2, TVal1 >, TSizeTy > &DstPrV)
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.
int AddRoot(const TVal &NodeVal=TVal())
TVec< TTriple< TInt, TIntV, TVal > > NodeV
TVal GetXY(const int &X, const int &Y) const
int GetPrimHashCd() const
TVal & operator[](const TSizeTy &ValN)
Returns a reference to the element at position ValN in the vector.
TSizeTy UnionLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the union of vectors this and ValV. Assumes the vectors are sorted! ...
void Del(const TVal &Val)
void Union(const TVec< TVal, TSizeTy > &ValV)
Sets this vector to its union with ValV. Assumes the vectors are sorted!
TLstNd(TLstNd *_PrevNd, TLstNd *_NextNd, const TVal &_Val)
TKeyDat< TUInt, TUInt > TUIntKd
TVec< TUChUInt64Pr > TUChUInt64PrV
const TVal1 & GetVal1() const
void PutBack(const PLstNd &Nd)
TSizeTy Partition(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Partitions the values between positions MnLValN...MxLValN.
TSStack< TBoolChPr > TBoolChS
TTriple< TStr, TStr, TStr > TStrTr
TKeyDat(const TKeyDat &KeyDat)
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
static TStr Fmt(const char *FmtStr,...)
TQuad & operator=(const TQuad &Quad)
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
void Pack()
Reduces vector capacity (frees memory) to match its size.
bool operator<(const TAPt &Pt) const
TQQueue(const int &_MxLast=64, const int &_MxLen=-1)
TVec< TFltStrPrPr > TFltStrPrPrV
TAPt & operator=(const TAPt &Pt)
TVec< TVal, TSizeTy > & operator+(const TVal &Val)
Appends value Val to the vector.
int GetVecs() const
Returns the total number of vectors stored in the vector pool.
TPair< TInt, TStrPr > TIntStrPrPr
static void QSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Quick sorts the values between positions BI...EI under the comparator Cmp.
TCmpPairByVal2(const bool &AscSort=true)
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
static PVecPool Load(const TStr &FNm)
TPair< TStr, TInt > TStrIntPr
void ShuffleAll(TRnd &Rnd=TInt::Rnd)
Shuffles the order of all elements in the pool.
TKeyDat< TFlt, TUInt > TFltUIntKd
TTuple(const TVal &InitVal)
TVecPool(const ::TSize &ExpectVals=0, const ::TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
TKeyDat< TInt, TInt > TIntKd
bool IsIn(const TVal &Val, TSizeTy &ValN) const
Checks whether element Val is a member of the vector.
TTriple< TCh, TInt, TInt > TChIntIntTr
void GetV(const int &VId, TValV &ValV) const
TVec< uint64, int > IdToOffV
TSStack & operator=(const TSStack &Stack)
TVecPool(const TSize &ExpectVals=0, const TSize &_GrowBy=1000000, const bool &_FastCopy=false, const TVal &_EmptyVal=TVal())
Vector pool constructor.
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2)
Returns a vector on elements Val1, Val2.
TKeyDat< TInt, TSFlt > TIntSFltKd
void Push(const TVal &Val)
void Sort(const bool &Asc=true)
TCmpKeyDatByDat(const bool &AscSort=true)
void Reverse()
Reverses the order of the elements in the vector.
bool operator<(const TPair &Pair) const
#define AssertR(Cond, Reason)
void SwapX(const int &X1, const int &X2)
TQuad< TInt, TStr, TInt, TInt > TIntStrIntIntQu
void GenRandomTree(const int &Nodes, TRnd &Rnd)
void Swap(TVVec< TVal > &Vec)
TSizeTy AddMerged(const TVal &Val)
Adds element Val to a sorted vector only if the element Val is not already in the vector...
int GetChildren(const int &NodeId) const
TTriple< TInt, TInt, TInt > TIntTr
TSizeTy AddBackSorted(const TVal &Val, const bool &Asc)
Adds element Val to a sorted vector.
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
TRec & operator[](const int &RecN) const
TPair< TFlt, TStr > TFltStrPr
void SetRecN(const int &RecN)
int GetUniDevInt(const int &Range=0)
TSizeTy Count(const TVal &Val) const
Counts the number of occurrences of Val in the vector.
bool operator==(const TVec< TVal, TSizeTy > &Vec) const
Checks that the two vectors have the same contents.
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
void MoveFrom(TVec< TVal, TSizeTy > &Vec)
Takes over the data and the capacity from Vec.
bool operator==(const TTriple &Triple) const
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
void SaveXml(TSOut &SOut, const TStr &Nm) const
TVec(const TSizeTy &_MxVals, const TSizeTy &_Vals)
Constructs a vector (an array) of length _Vals, while reserving enough memory to store _MxVals elemen...
TVec< TIntFltIntTr > TIntFltIntTrV
static TPt< PVec< TVal > > New()
void Clr(const bool &DoDel=true)
TLst< TFltIntKd > TFltIntKdL
TFunc & operator=(const TFunc &Func)
void Resize(const TSizeTy &_MxVals=-1)
Resizes the vector so that it can store at least _MxVals.
static TVec< TVal, TSizeTy > GetV(const TVal &Val1)
Returns a vector on element Val1.
TVec< TUInt64FltPr > TUInt64FltPrV
TVVVec< TVal > & operator=(const TVVVec< TVal > &Vec)
static TPt< PVec< TVal > > New(const TVec< TVal > &V)
TKeyDat< TFlt, TInt > TFltIntKd
void SortCmp(const TCmp &Cmp)
Sorts the elements of the vector using the comparator Cmp.
TPair< TFlt, TUInt64 > TFltUInt64Pr
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
bool operator<(const TQuad &Quad) const
void Gen(const TSizeTy &_MxVals, const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements, while reserving enough memory for _MxVals elements...
void GetVal(TVal1 &_Val1, TVal2 &_Val2, TVal3 &_Val3) const
void BSort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Bubble sorts the values between positions MnLValN...MxLValN.
TKeyDat< TInt, TUInt64 > TIntUInt64Kd
TSizeTy Vals
Vector length. Length is the number of elements stored in the vector.
TVec< TVal > & Get1DVec()
TVec< TFltIntPr > TFltIntPrV
bool IsVId(const int &VId) const
Tests whether vector of id VId is in the pool.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
TTuple(const TTuple &Tup)
TSizeTy GetMemSize() const
Returns the memory size (the number of bytes) of a binary representation.
TPt< TIntVecPool > PIntVecPool
void CompactPool(const TVal &DelVal)
void DelLast()
Removes the last element of the vector.
PLstNd SearchForw(const TVal &Val)
TTriple< TInt, TInt, TStr > TIntIntStrTr
void Trunc(const TSizeTy &_Vals=-1)
Truncates the vector's length and capacity to _Vals elements.
static void SwapI(TIter LVal, TIter RVal)
Swaps the elements that iterators LVal and RVal point to.
TVec< TIntFltKd > TIntFltKdV
TPair & operator=(const TPair &Pair)
TKeyDat< TStr, TAscFlt > TStrAscFltKd
TVec< TQQueue< TInt > > TIntQV
bool operator<(const TTree &Tree) const
TVec< TIntStrStrTr > TIntStrStrTrV
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
TVal * GetValVPt(const int &VId) const
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.
TPair< TUCh, TInt > TUChIntPr
TLst< TAscFltIntKd > TAscFltIntKdL
TPair< TUInt64, TInt > TUInt64IntPr
const TVal & At(const int &X, const int &Y) const
void GetRec(TRec &Rec, const int &RecN=-1)
void PutY(const int &Y, const TVal &Val)
int GetPrimHashCd() const
TVec< TIntStrIntTr > TIntStrIntTrV
void PutAll(const TVal &Val)
TLstNd< TFltIntKd > * PFltIntKdLN
void GetSubValV(const int &_BValN, const int &_EValN, TVec< TVal > &SubValV) const
TStr GetXOutOfBoundsErrMsg(const TSizeTy &ValN) const
Constructs the out of bounds error message.
TSizeTy SearchBack(const TVal &Val) const
Returns the position of an element with value Val.
TKeyDat< TFlt, TUInt64 > TFltUInt64Kd
::TSize GetMemUsed() const
void Reserve(const TSizeTy &_MxVals, const TSizeTy &_Vals)
Reserves enough memory for the vector to store _MxVals elements and sets its length to _Vals...
TTriple< TFlt, TInt, TInt > TFltIntIntTr
TQuad(const TVal1 &_Val1, const TVal2 &_Val2, const TVal3 &_Val3, const TVal4 &_Val4)
bool operator!=(const TAPt &Pt) const
bool IsIn(const TVal &Val) const
TVec< TIntStrPr > TIntStrPrV
Compares the pair by the second value.
TVec< TIntUInt64Kd > TIntUInt64KdV
void Save(TSOut &SOut) const
TSizeTy GetMxValN() const
Returns the position of the largest element in the vector.
void Swap(TRec &Rec1, TRec &Rec2)
TKeyDat< TStr, TStr > TStrKd
TTriple & operator=(const TTriple &Triple)
Vector is a sequence TVal objects representing an array that can change in size.
const TVal4 & GetVal4() const
TTriple< TUCh, TInt, TInt > TUChIntIntTr
int AddEmptyV(const int &ValVLen)
TVec< TFltStrKd > TFltStrKdV
const TVal3 & GetVal3() const
TPair< TUInt64, TStr > TUInt64StrPr
void WrTree(const int &NodeId=0, const int &Lev=0)
TTriple< TStr, TFlt, TFlt > TStrFltFltTr
TTriple< TChA, TChA, TChA > TChATr
TSizeTy AddV(const TVec< TVal, TSizeTy > &ValV)
Adds the elements of the vector ValV to the to end of the vector.
void GetSubValV(const TSizeTy &BValN, const TSizeTy &EValN, TVec< TVal, TSizeTy > &ValV) const
Fills ValV with elements at positions BValN...EValN.
bool operator<(const TTriple &Triple) const
static void ISortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Insertion sorts the values between positions BI...EI under the comparator Cmp.
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.