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 {
187 template <
class TVal1,
class TVal2,
class TVal3>
199 template <
class TVal1,
class TVal2,
class TVal3>
212 template <
class TVal1,
class TVal2,
class TVal3,
class TVal4>
224 TQuad(
const TVal1& _Val1,
const TVal2& _Val2,
const TVal3& _Val3,
const TVal4& _Val4):
247 void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3, TVal4& _Val4)
const {
261 template<
class TVal,
int NVals>
267 TTuple(
const TVal& InitVal) {
for (
int i=0; i<
Len(); i++)
ValV[i]=InitVal; }
273 int Len()
const {
return NVals; }
277 for (
int i=0; i<
Len(); i++)
ValV[i]=Tup[i]; }
return *
this; }
279 if (
Len()!=Tup.
Len()) {
return false; }
if (&Tup==
this) {
return true; }
280 for (
int i=0; i<
Len(); i++)
if(
ValV[i]!=Tup[i]){
return false;}
return true; }
282 if (
Len() == Tup.
Len()) {
for (
int i=0; i<
Len(); i++) {
283 if(
ValV[i]<Tup[i]){
return true;}
else if(
ValV[i]>Tup[i]){
return false;} }
return false; }
284 else {
return Len() < Tup.
Len(); } }
285 void Sort(
const bool& Asc=
true);
297 for (
int i=0; i<
Len(); i++) { ValsStr+=
" "+
ValV[i].GetStr(); }
301 template<
class TVal,
int NVals>
304 for (
int i=0; i<NVals; i++) { V.
Add(ValV[i]); }
306 for (
int i=0; i<NVals; i++) { ValV[i] = V[i]; }
309 template<
class TVal,
int NVals>
311 TVal MxVal = ValV[0];
313 for (
int i = 1; i < NVals; i++) {
315 MxVal=ValV[i]; ValN=i;
321 template<
class TVal,
int NVals>
323 TVal MnVal = ValV[0];
325 for (
int i = 1; i < NVals; i++) {
327 MnVal=ValV[i]; ValN=i;
335 template <
class TKey,
class TDat>
351 if (
this!=&KeyDat){
Key=KeyDat.
Key;
Dat=KeyDat.
Dat;}
return *
this;}
359 template <
class TKey,
class TDat>
361 const int Kds=SrcKdV.Len();
363 for (
int KdN=0; KdN<Kds; KdN++){
399 template <
class TVal1,
class TVal2>
419 template <
class TVal,
class TSizeTy =
int>
427 void Resize(
const TSizeTy& _MxVals=-1);
435 explicit TVec(
const TSizeTy& _Vals){
437 if (_Vals==0){
ValT=NULL;}
else {
ValT=
new TVal[_Vals];}}
439 TVec(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
441 if (_MxVals==0){
ValT=NULL;}
else {
ValT=
new TVal[_MxVals];}}
446 explicit TVec(TVal *_ValT,
const TSizeTy& _Vals):
464 bool operator<(const TVec<TVal, TSizeTy>& Vec)
const;
475 return TSizeTy(2*
sizeof(TSizeTy)+
sizeof(TVal*)+
MxVals*
sizeof(TVal));}
478 return TSizeTy(2*
sizeof(TVal)+
sizeof(TSizeTy)*
Vals);}
490 void Gen(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
IAssert((0<=_Vals)&&(_Vals<=_MxVals));
492 if (_MxVals==0){
ValT=NULL;}
else {
ValT=
new TVal[_MxVals];}}
497 void GenExt(TVal *_ValT,
const TSizeTy& _Vals){
513 void Clr(
const bool& DoDel=
true,
const TSizeTy& NoDelLim=-1);
517 void Trunc(
const TSizeTy& _Vals=-1);
559 TSizeTy
Add(){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
564 TSizeTy
Add(
const TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
566 TSizeTy
Add(TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
569 TSizeTy
Add(
const TVal& Val,
const TSizeTy& ResizeLen){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
576 TSizeTy
AddSorted(
const TVal& Val,
const bool& Asc=
true,
const TSizeTy& _MxVals=-1);
603 void Ins(
const TSizeTy& ValN,
const TVal& Val);
605 void Del(
const TSizeTy& ValN);
607 void Del(
const TSizeTy& MnValN,
const TSizeTy& MxValN);
613 void DelAll(
const TVal& Val);
615 void PutAll(
const TVal& Val);
618 void Swap(
const TSizeTy& ValN1,
const TSizeTy& ValN2){
const TVal Val=
ValT[ValN1];
ValT[ValN1]=
ValT[ValN2];
ValT[ValN2]=Val;}
620 static void SwapI(
TIter LVal,
TIter RVal){
const TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
635 TSizeTy
GetPivotValN(
const TSizeTy& LValN,
const TSizeTy& RValN)
const;
639 void BSort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
643 void ISort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
648 TSizeTy
Partition(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
653 void QSort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
658 void Sort(
const bool& Asc=
true);
660 bool IsSorted(
const bool& Asc=
true)
const;
666 void Reverse(TSizeTy LValN, TSizeTy RValN){
Assert(LValN>=0 && RValN<
Len());
while (LValN < RValN){
Swap(LValN++, RValN--);} }
671 template <
class TCmp>
673 TSizeTy SubVals=TSizeTy(EI-BI);
if (SubVals >
TInt::Mx-1) { SubVals =
TInt::Mx-1; }
675 const TVal& Val1 = *(BI+ValN1);
const TVal& Val2 = *(BI+ValN2);
const TVal& Val3 = *(BI+ValN3);
676 if (
Cmp(Val1, Val2)) {
677 if (
Cmp(Val2, Val3))
return BI+ValN2;
678 else if (
Cmp(Val3, Val1))
return BI+ValN1;
679 else return BI+ValN3;
681 if (
Cmp(Val1, Val3))
return BI+ValN1;
682 else if (
Cmp(Val3, Val2))
return BI+ValN2;
683 else return BI+ValN3; } }
685 template <
class TCmp>
688 while (
Cmp(*BI, Pivot)){++BI;} --EI;
689 while (
Cmp(Pivot, *EI)){--EI;}
690 if (!(BI<EI)){
return BI;}
SwapI(BI, EI); ++BI; } }
692 template <
class TCmp>
694 for (
TIter i = BI; i != EI; ++i) {
695 for (
TIter j = EI-1; j != i; --j) {
696 if (
Cmp(*j, *(j-1))) {
SwapI(j, j-1); } } } }
698 template <
class TCmp>
701 for (
TIter i = BI, j; i != EI; ++i) { TVal Tmp=*i; j=i;
702 while (j > BI &&
Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; } *j=Tmp; } } }
704 template <
class TCmp>
707 if (EI - BI < 20) {
ISortCmp(BI, EI, Cmp); }
712 template <
class TCmp>
715 template <
class TCmp>
719 if (
Cmp(*(i+1), *i)){
return false;} }
return true; }
757 TSizeTy
Count(
const TVal& Val)
const;
762 TSizeTy
SearchBin(
const TVal& Val)
const;
766 TSizeTy
SearchBin(
const TVal& Val, TSizeTy& InsValN)
const;
771 TSizeTy
SearchForw(
const TVal& Val,
const TSizeTy& BValN=0)
const;
786 bool IsIn(
const TVal& Val, TSizeTy& ValN)
const { ValN=
SearchForw(Val);
return ValN!=-1;}
796 TVal&
GetAddDat(
const TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
817 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6){
820 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7){
823 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7,
const TVal& Val8){
826 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7,
const TVal& Val8,
const TVal& Val9){
830 template <
class TVal,
class TSizeTy>
832 IAssertR(MxVals!=-1,
TStr::Fmt(
"Can not increase the capacity of the vector. %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
GetTypeNm(*this).
CStr()).CStr());
833 IAssertR(MxVals!=(
TInt::Mx-1024),
TStr::Fmt(
"Buffer size at maximum. %s. [Program refuses to allocate more memory. Solution-1: Send your test case to developers.]",
GetTypeNm(*this).
CStr()).CStr());
835 if (Vals==0){MxVals=16;}
else {MxVals*=2;}
837 if (_MxVals<=MxVals){
return;}
else {MxVals=_MxVals;}
843 try {ValT=
new TVal[MxVals];}
844 catch (std::exception Ex){
845 FailR(
TStr::Fmt(
"TVec::Resize: %s, Length:%s, Capacity:%s, New capacity:%s, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
848 TVal* NewValT = NULL;
850 NewValT=
new TVal[MxVals];}
851 catch (std::exception Ex){
852 FailR(
TStr::Fmt(
"TVec::Resize: %s, Length:%s, Capacity:%s, New capacity:%s, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
855 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
856 delete[] ValT; ValT=NewValT;
860 template <
class TVal,
class TSizeTy>
869 template <
class TVal,
class TSizeTy>
872 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
873 for (TSizeTy ValN=0; ValN<Vec.
Vals; ValN++){ValT[ValN]=Vec.
ValT[ValN];}
876 template <
class TVal,
class TSizeTy>
878 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
879 SIn.
Load(MxVals); SIn.
Load(Vals); MxVals=Vals;
880 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
881 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=TVal(SIn);}
884 template <
class TVal,
class TSizeTy>
886 if (MxVals!=-1){SOut.
Save(MxVals);}
else {SOut.
Save(Vals);}
888 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
891 template <
class TVal,
class TSizeTy>
894 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
895 MxVals=Vals=Vec.
Vals;
896 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
897 for (TSizeTy ValN=0; ValN<Vec.
Vals; ValN++){ValT[ValN]=Vec.
ValT[ValN];}
902 template <
class TVal,
class TSizeTy>
904 if (
this==&Vec){
return true;}
905 if (Len()!=Vec.
Len()){
return false;}
906 for (TSizeTy ValN=0; ValN<Vals; ValN++){
907 if (ValT[ValN]!=Vec.
ValT[ValN]){
return false;}}
911 template <
class TVal,
class TSizeTy>
913 if (
this==&Vec){
return false;}
914 if (Len()==Vec.
Len()){
915 for (TSizeTy ValN=0; ValN<Vals; ValN++){
916 if (ValT[ValN]<Vec.
ValT[ValN]){
return true;}
917 else if (ValT[ValN]>Vec.
ValT[ValN]){
return false;}
922 return Len()<Vec.
Len();
929 template <
class TVal,
class TSizeTy>
932 for (TSizeTy i=0; i<Vals; i++){
941 template <
class TVal,
class TSizeTy>
944 for (TSizeTy i=0; i<Vals; i++){
952 template <
class TVal,
class TSizeTy>
954 if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){
955 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
956 MxVals=Vals=0; ValT=NULL;
958 IAssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
963 template <
class TVal,
class TSizeTy>
965 IAssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
966 IAssert((_Vals==-1)||(_Vals>=0));
967 if ((_Vals!=-1)&&(_Vals>=Vals)){
970 if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){
971 if (ValT!=NULL){
delete[] ValT;}
972 MxVals=Vals=0; ValT=NULL;
975 if (MxVals==Vals){
return;}
else {MxVals=Vals;}
979 TVal* NewValT=
new TVal[MxVals];
981 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
982 delete[] ValT; ValT=NewValT;
986 template <
class TVal,
class TSizeTy>
988 IAssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
990 if (ValT!=NULL){
delete[] ValT;} ValT=NULL;
994 TVal* NewValT=
new TVal[MxVals];
996 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
997 delete[] ValT; ValT=NewValT;
1001 template <
class TVal,
class TSizeTy>
1004 if (ValT!=NULL && MxVals!=-1){
delete[] ValT;}
1010 template <
class TVal,
class TSizeTy>
1019 template <
class TVal,
class TSizeTy>
1021 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1022 for (TSizeTy ValN=0; ValN<ValV.
Vals; ValN++){Add(ValV[ValN]);}
1026 template <
class TVal,
class TSizeTy>
1028 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1029 TSizeTy ValN=Add(Val);
1031 while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){
1032 Swap(ValN, ValN-1); ValN--;}
1034 while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){
1035 Swap(ValN, ValN-1); ValN--;}
1037 if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);}
1041 template <
class TVal,
class TSizeTy>
1043 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1045 TSizeTy ValN=Vals-2;
1046 while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
1047 ValT[ValN+1]=ValT[ValN]; ValN--;}
1052 template <
class TVal,
class TSizeTy>
1054 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1055 TSizeTy ValN=SearchBin(Val);
1056 if (ValN==-1){
return AddSorted(Val);}
1057 else {GetVal(ValN)=Val;
return -1;}
1060 template <
class TVal,
class TSizeTy>
1062 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1063 for (TSizeTy ValN=0; ValN<ValV.
Vals; ValN++){AddMerged(ValV[ValN]);}
1067 template <
class TVal,
class TSizeTy>
1069 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1070 TSizeTy ValN=SearchForw(Val);
1071 if (ValN==-1){
return Add(Val);}
1072 else {GetVal(ValN)=Val;
return -1;}
1075 template <
class TVal,
class TSizeTy>
1079 const TSizeTy SubVals=
TInt::GetMx(0, EValN-BValN+1);
1080 SubValV.
Gen(SubVals, 0);
1081 for (TSizeTy ValN=BValN; ValN<=EValN; ValN++){
1082 SubValV.
Add(GetVal(ValN));}
1085 template <
class TVal,
class TSizeTy>
1087 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1088 Add();
Assert((0<=ValN)&&(ValN<Vals));
1089 for (TSizeTy MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
1093 template <
class TVal,
class TSizeTy>
1095 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1096 Assert((0<=ValN)&&(ValN<Vals));
1097 for (TSizeTy MValN=ValN+1; MValN<Vals; MValN++){
1098 ValT[MValN-1]=ValT[MValN];}
1099 ValT[--Vals]=TVal();
1102 template <
class TVal,
class TSizeTy>
1104 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1105 Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
1107 for (TSizeTy ValN=MxValN+1; ValN<Vals; ValN++){
1108 ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
1109 for (TSizeTy ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
1111 Vals-=MxValN-MnValN+1;
1114 template <
class TVal,
class TSizeTy>
1116 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1117 TSizeTy ValN=SearchForw(Val);
1118 if (ValN!=-1){Del(ValN);
return true;}
1119 else {
return false;}
1122 template <
class TVal,
class TSizeTy>
1124 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1126 while ((ValN=SearchForw(Val))!=-1){Del(ValN);}
1129 template <
class TVal,
class TSizeTy>
1131 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
1134 template <
class TVal,
class TSizeTy>
1136 for (TSizeTy ValN1=MnLValN; ValN1<=MxRValN; ValN1++){
1137 for (TSizeTy ValN2=MxRValN; ValN2>ValN1; ValN2--){
1139 if (ValT[ValN2]<ValT[ValN2-1]){
Swap(ValN2, ValN2-1);}
1141 if (ValT[ValN2]>ValT[ValN2-1]){
Swap(ValN2, ValN2-1);}
1147 template <
class TVal,
class TSizeTy>
1149 if (MnLValN<MxRValN){
1150 for (TSizeTy ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){
1151 TVal Val=ValT[ValN1]; TSizeTy ValN2=ValN1;
1153 while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){
1154 ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1156 while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){
1157 ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1164 template <
class TVal,
class TSizeTy>
1166 TSizeTy SubVals=RValN-LValN+1;
1171 const TVal& Val1=ValT[ValN1];
1172 const TVal& Val2=ValT[ValN2];
1173 const TVal& Val3=ValT[ValN3];
1175 if (Val2<Val3){
return ValN2;}
1176 else if (Val3<Val1){
return ValN1;}
1177 else {
return ValN3;}
1179 if (Val1<Val3){
return ValN1;}
1180 else if (Val3<Val2){
return ValN2;}
1181 else {
return ValN3;}
1185 template <
class TVal,
class TSizeTy>
1187 TSizeTy PivotValN=GetPivotValN(MnLValN, MxRValN);
1188 Swap(PivotValN, MnLValN);
1189 TVal PivotVal=ValT[MnLValN];
1190 TSizeTy LValN=MnLValN-1; TSizeTy RValN=MxRValN+1;
1193 do {RValN--;}
while (ValT[RValN]>PivotVal);
1194 do {LValN++;}
while (ValT[LValN]<PivotVal);
1196 do {RValN--;}
while (ValT[RValN]<PivotVal);
1197 do {LValN++;}
while (ValT[LValN]>PivotVal);
1199 if (LValN<RValN){
Swap(LValN, RValN);}
1200 else {
return RValN;}
1204 template <
class TVal,
class TSizeTy>
1206 if (MnLValN<MxRValN){
1207 if (MxRValN-MnLValN<20){
1208 ISort(MnLValN, MxRValN, Asc);
1210 TSizeTy SplitValN=Partition(MnLValN, MxRValN, Asc);
1211 QSort(MnLValN, SplitValN, Asc);
1212 QSort(SplitValN+1, MxRValN, Asc);
1217 template <
class TVal,
class TSizeTy>
1219 QSort(0, Len()-1, Asc);
1222 template <
class TVal,
class TSizeTy>
1225 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1226 if (ValT[ValN]>ValT[ValN+1]){
return false;}}
1228 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1229 if (ValT[ValN]<ValT[ValN+1]){
return false;}}
1234 template <
class TVal,
class TSizeTy>
1237 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1238 const int Range = int(Vals-ValN);
1242 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1243 const TSizeTy Range = Vals-ValN;
1249 template <
class TVal,
class TSizeTy>
1251 for (TSizeTy ValN=0; ValN<Vals/2; ValN++){
1252 Swap(ValN, Vals-ValN-1);}
1255 template <
class TVal,
class TSizeTy>
1257 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1260 for (TSizeTy ValN=0; ValN<SortedVec.
Len(); ValN++){
1261 if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){
1262 Add(SortedVec[ValN]);}
1266 template <
class TVal,
class TSizeTy>
1269 TSizeTy First = 0, Last = Len(), Next = Len()-1;
1270 if (Last < 2)
return false;
1273 TSizeTy Next1 = Next;
1274 if (GetVal(--Next) < GetVal(Next1)) {
1276 for (; GetVal(Next) >= GetVal(--Mid); ) { }
1278 Reverse(Next1, Last-1);
1281 if (Next == First) {
1288 template <
class TVal,
class TSizeTy>
1290 TSizeTy First = 0, Last = Len(), Next = Len()-1;
1291 if (Last < 2)
return false;
1294 TSizeTy Next1 = Next;
1295 if (GetVal(--Next) >= GetVal(Next1)) {
1297 for (; GetVal(Next) < GetVal(--Mid); ) { }
1299 Reverse(Next1, Last);
1302 if (Next == First) {
1309 template <
class TVal,
class TSizeTy>
1312 Intrs(ValV, IntrsVec);
1316 template <
class TVal,
class TSizeTy>
1319 Union(ValV, UnionVec);
1323 template <
class TVal,
class TSizeTy>
1326 Diff(ValV, DiffVec);
1330 template <
class TVal,
class TSizeTy>
1333 TSizeTy ValN1=0, ValN2=0;
1334 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1335 const TVal& Val1=GetVal(ValN1);
1336 while ((ValN2<ValV.
Len())&&(Val1>ValV.
GetVal(ValN2))){
1338 if ((ValN2<ValV.
Len())&&(Val1==ValV.
GetVal(ValN2))){
1339 DstValV.
Add(Val1); ValN2++;}
1344 template <
class TVal,
class TSizeTy>
1347 TSizeTy ValN1=0, ValN2=0;
1348 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1349 const TVal& Val1=GetVal(ValN1);
1350 const TVal& Val2=ValV.
GetVal(ValN2);
1351 if (Val1<Val2){DstValV.
Add(Val1); ValN1++;}
1352 else if (Val1>Val2){DstValV.
Add(Val2); ValN2++;}
1353 else {DstValV.
Add(Val1); ValN1++; ValN2++;}
1355 for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1356 DstValV.
Add(GetVal(RestValN1));}
1357 for (TSizeTy RestValN2=ValN2; RestValN2<ValV.
Len(); RestValN2++){
1361 template <
class TVal,
class TSizeTy>
1364 TSizeTy ValN1=0, ValN2=0;
1365 while (ValN1<Len() && ValN2<ValV.
Len()) {
1366 const TVal& Val1 = GetVal(ValN1);
1367 while (ValN2<ValV.
Len() && Val1>ValV.
GetVal(ValN2)) ValN2++;
1368 if (ValN2<ValV.
Len()) {
1369 if (Val1!=ValV.
GetVal(ValN2)) { DstValV.
Add(Val1); }
1373 for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1374 DstValV.
Add(GetVal(RestValN1));}
1377 template <
class TVal,
class TSizeTy>
1379 TSizeTy Cnt=0, ValN1=0, ValN2=0;
1380 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1381 const TVal& Val1=GetVal(ValN1);
1382 while ((ValN2<ValV.
Len())&&(Val1>ValV.
GetVal(ValN2))){
1384 if ((ValN2<ValV.
Len())&&(Val1==ValV.
GetVal(ValN2))){
1391 template <
class TVal,
class TSizeTy>
1393 TSizeTy Cnt = 0, ValN1 = 0, ValN2 = 0;
1394 while ((ValN1 < Len()) && (ValN2 < ValV.
Len())) {
1395 const TVal& Val1 = GetVal(ValN1);
1396 const TVal& Val2 = ValV.
GetVal(ValN2);
1399 }
else if (Val1 > Val2) {
1402 Cnt++; ValN1++; ValN2++;
1405 Cnt += (Len() - ValN1) + (ValV.
Len() - ValN2);
1409 template <
class TVal,
class TSizeTy>
1412 for (TSizeTy i = 0; i < Len(); i++){
1413 if (Val == ValT[i]){Count++;}}
1417 template <
class TVal,
class TSizeTy>
1419 TSizeTy LValN=0, RValN=Len()-1;
1420 while (RValN>=LValN){
1421 TSizeTy ValN=(LValN+RValN)/2;
1422 if (Val==ValT[ValN]){
return ValN;}
1423 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
1428 template <
class TVal,
class TSizeTy>
1430 TSizeTy LValN=0, RValN=Len()-1;
1431 while (RValN>=LValN){
1432 TSizeTy ValN=(LValN+RValN)/2;
1433 if (Val==ValT[ValN]){InsValN=ValN;
return ValN;}
1434 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
1436 InsValN=LValN;
return -1;
1439 template <
class TVal,
class TSizeTy>
1441 for (TSizeTy ValN=BValN; ValN<Vals; ValN++){
1442 if (Val==ValT[ValN]){
return ValN;}}
1446 template <
class TVal,
class TSizeTy>
1448 for (TSizeTy ValN=Vals-1; ValN>=0; ValN--){
1449 if (Val==ValT[ValN]){
return ValN;}}
1453 template <
class TVal,
class TSizeTy>
1455 TSizeTy ValVLen=ValV.
Len();
1456 for (TSizeTy ValN=BValN; ValN<Vals-ValVLen+1; ValN++){
1458 for (TSizeTy SubValN=0; SubValN<ValVLen; SubValN++){
1459 if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=
false;
break;}
1461 if (Found){
return ValN;}
1466 template <
class TVal,
class TSizeTy>
1468 if (Vals==0){
return -1;}
1470 for (TSizeTy ValN=1; ValN<Vals; ValN++){
1471 if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
1558 template <
class TVal,
class TSizeTy=
int>
1579 TVecPool(
const TSize& ExpectVals=0,
const TSize& _GrowBy=1000000,
const bool& _FastCopy=
false,
const TVal& _EmptyVal=TVal());
1632 for (::
TSize ValN=0; ValN <
::TSize(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1656 template <
class TVal,
class TSizeTy>
1658 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
1659 if (ValBf == NULL) {
1660 try { ValBf =
new TVal [MxVals]; }
1661 catch (std::exception Ex) {
1662 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()); }
1664 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1667 TVal* NewValBf = NULL;
1668 try { NewValBf =
new TVal [MxVals]; }
1669 catch (std::exception Ex) {
1670 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()); }
1673 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
1675 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1676 if (EmptyVal != TVal()) {
1677 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1684 template <
class TVal,
class TSizeTy>
1690 template <
class TVal,
class TSizeTy>
1694 catch (std::exception Ex) {
1703 template <
class TVal,
class TSizeTy>
1705 uint64 _GrowBy, _MxVals, _Vals;
1711 for (
TSize ValN = 0; ValN <
Vals; ValN++) {
ValBf[ValN] = TVal(SIn); }
1714 for (
int ValN = 0; ValN <
Vals; ValN++) {
1720 template <
class TVal,
class TSizeTy>
1722 SOut.
Save(FastCopy);
1723 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1724 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
1725 SOut.
Save(EmptyVal);
1726 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1727 { SOut.
Save(IdToOffV.Len()); SOut.
Save(IdToOffV.Len());
1728 for (
int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
1729 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
1733 template <
class TVal,
class TSizeTy>
1743 ValBf =
new TVal [MxVals]; }
1744 catch (std::exception Ex) {
1745 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()); }
1748 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
1750 for (
TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
1755 template <
class TVal,
class TSizeTy>
1757 const TSizeTy ValVLen = ValV.
Len();
1758 if (ValVLen == 0) {
return 0; }
1759 if (MxVals < Vals+ValVLen) { Resize(Vals+
max(ValVLen, GrowBy)); }
1760 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
1761 else {
for (
uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1762 Vals+=ValVLen; IdToOffV.
Add(Vals);
1763 return IdToOffV.Len()-1;
1766 template <
class TVal,
class TSizeTy>
1768 if (ValVLen==0){
return 0;}
1769 if (MxVals < Vals+ValVLen){Resize(Vals+
max(
TSize(ValVLen), GrowBy)); }
1770 Vals+=ValVLen; IdToOffV.Add(Vals);
1771 return IdToOffV.Len()-1;
1775 template <
class TVal,
class TSizeTy>
1779 for (
int vid = 1; vid < IdToOffV.Len(); vid++) {
1781 const uint Len = GetVLen(vid);
1782 TVal* ValV = GetValVPt(vid);
1783 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
1784 if (Len == 0) {
continue; }
1786 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
1789 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
1790 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
1794 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
1797 IdToOffV.Last() -= TotalDel;
1798 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
1804 template <
class TVal,
class TSizeTy>
1806 for (::
TSize n = Vals-1; n > 0; n--) {
1808 const TVal Tmp = ValBf[n];
1809 ValBf[n] = ValBf[k];
1821 namespace TGLib_OLD {
1824 template<
class TVal>
1864 if (VId==0){
return 0;}
1877 for (
uint ValN=0; ValN <
uint(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1896 template <
class TVal>
1898 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
1899 if (ValBf == NULL) {
1900 try { ValBf =
new TVal [MxVals]; }
1901 catch (std::exception Ex) {
1902 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()); }
1904 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1907 TVal* NewValBf = NULL;
1908 try { NewValBf =
new TVal [MxVals]; }
1909 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()); }
1912 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
1914 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1915 if (EmptyVal != TVal()) {
1916 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1923 template <
class TVal>
1925 GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
1930 template <
class TVal>
1932 FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy),
1933 MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
1935 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVecPool::TVecPool: %s, MxVals: %d", Ex.what(),
MxVals).CStr()); }
1943 template <
class TVal>
1946 uint64 _GrowBy, _MxVals, _Vals;
1952 for (
TSize ValN = 0; ValN <
Vals; ValN++) {
ValBf[ValN] = TVal(SIn); }
1955 for (
int ValN = 0; ValN <
Vals; ValN++) {
1961 template <
class TVal>
1963 SOut.
Save(FastCopy);
1964 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1965 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
1966 SOut.
Save(EmptyVal);
1967 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1968 { SOut.
Save(IdToOffV.Len()); SOut.
Save(IdToOffV.Len());
1969 for (
int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
1970 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
1974 template <
class TVal>
1983 try { ValBf =
new TVal [MxVals]; }
1984 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVec::operator= : %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
1987 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
1989 for (
uint64 ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
1994 template<
class TVal>
1997 if (ValVLen == 0) {
return 0; }
1998 if (MxVals < Vals+ValVLen) { Resize(Vals+
max(ValVLen, GrowBy)); }
1999 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
2000 else {
for (
uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2001 Vals+=ValVLen; IdToOffV.
Add(Vals);
2002 return IdToOffV.Len()-1;
2005 template<
class TVal>
2007 if (ValVLen==0){
return 0;}
2008 if (MxVals < Vals+ValVLen){Resize(Vals+
max(
TSize(ValVLen), GrowBy)); }
2009 Vals+=ValVLen; IdToOffV.Add(Vals);
2010 return IdToOffV.Len()-1;
2015 template<
class TVal>
2019 for (
int vid = 1; vid < IdToOffV.Len(); vid++) {
2021 const uint Len = GetVLen(vid);
2022 TVal* ValV = GetValVPt(vid);
2023 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
2024 if (Len == 0) {
continue; }
2026 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
2029 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
2030 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
2034 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
2037 IdToOffV.Last() -= TotalDel;
2038 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
2044 template<
class TVal>
2046 for (::
TSize n = Vals-1; n > 0; n--) {
2048 const TVal Tmp = ValBf[n];
2049 ValBf[n] = ValBf[k];
2061 template <
class TVal>
2083 if (
this!=&Vec){
V=Vec.
V;}
return *
this;}
2085 bool operator<(const PVec<TVal>& Vec)
const {
return V<Vec.V;}
2090 TVal
GetVal(
const int& ValN)
const {
return V[ValN];}
2108 template <
class TVal>
2117 TVVec(
const int& _XDim,
const int& _YDim):
2133 void Gen(
const int& _XDim,
const int& _YDim){
2134 Assert((_XDim>=0)&&(_YDim>=0));
2142 const TVal&
At(
const int& X,
const int& Y)
const {
2145 TVal&
At(
const int& X,
const int& Y){
2153 void PutXY(
const int& X,
const int& Y,
const TVal& Val){
At(X, Y)=Val;}
2155 void PutX(
const int& X,
const TVal& Val){
2156 for (
int Y=0; Y<int(
YDim); Y++){
At(X, Y)=Val;}}
2157 void PutY(
const int& Y,
const TVal& Val){
2158 for (
int X=0; X<int(
XDim); X++){
At(X, Y)=Val;}}
2159 TVal
GetXY(
const int& X,
const int& Y)
const {
2165 void SwapX(
const int& X1,
const int& X2);
2166 void SwapY(
const int& Y1,
const int& Y2);
2176 void DelX(
const int& X);
2177 void DelY(
const int& Y);
2180 template <
class TVal>
2182 for (
int Y=0; Y<int(YDim); Y++){
2183 TVal Val=At(X1, Y); At(X1, Y)=At(X2, Y); At(X2, Y)=Val;}
2186 template <
class TVal>
2188 for (
int X=0; X<int(XDim); X++){
2189 TVal Val=At(X, Y1); At(X, Y1)=At(X, Y2); At(X, Y2)=Val;}
2192 template <
class TVal>
2197 ValV.Swap(Vec.
ValV);
2201 template <
class TVal>
2203 for (
int X=0; X<XDim-1; X++){SwapX(X, X+Rnd.
GetUniDevInt(XDim-X));}
2206 template <
class TVal>
2208 for (
int Y=0; Y<YDim-1; Y++){SwapY(Y, Y+Rnd.
GetUniDevInt(YDim-Y));}
2211 template <
class TVal>
2213 int MxValN=ValV.GetMxValN();
2218 template <
class TVal>
2222 for (
int X=0; X<CopyXDim; X++){
2223 for (
int Y=0; Y<CopyYDim; Y++){
2224 At(X, Y)=VVec.
At(X, Y);
2229 template <
class TVal>
2236 template <
class TVal>
2243 template <
class TVal>
2246 for (
int Y=0; Y<YDim; Y++){
2247 for (
int LX=0; LX<X; LX++){
2248 NewVVec.
At(LX, Y)=At(LX, Y);}
2249 for (
int RX=X+1; RX<XDim; RX++){
2250 NewVVec.
At(RX-1, Y)=At(RX, Y);}
2255 template <
class TVal>
2258 for (
int X=0; X<XDim; X++){
2259 for (
int LY=0; LY<Y; LY++){
2260 NewVVec.
At(X, LY)=At(X, LY);}
2261 for (
int RY=Y+1; RY<YDim; RY++){
2262 NewVVec.
At(X, RY-1)=At(X, RY);}
2267 template <
class TVal>
2269 Vec.
Gen(GetCols(), 0);
2270 for (
int col = 0; col < GetCols(); col++) {
2271 Vec.
Add(At(RowN, col));
2275 template <
class TVal>
2277 Vec.
Gen(GetRows(), 0);
2278 for (
int row = 0; row < GetRows(); row++) {
2279 Vec.
Add(At(row, ColN));
2295 template <
class TVal>
2304 TVVVec(
const int& _XDim,
const int& _YDim,
const int& _ZDim):
2321 void Gen(
const int& _XDim,
const int& _YDim,
const int& _ZDim){
2322 Assert((_XDim>=0)&&(_YDim>=0)&&(_ZDim>=0));
2324 TVal&
At(
const int& X,
const int& Y,
const int& Z){
2327 const TVal&
At(
const int& X,
const int& Y,
const int& Z)
const {
2331 return At(X, Y, Z);}
2332 const TVal&
operator()(
const int& X,
const int& Y,
const int& Z)
const {
2333 return At(X, Y, Z);}
2346 template <
class TVal>
2369 int AddNode(
const int& ParentNodeId,
const TVal& NodeVal=TVal()){
2371 if (ParentNodeId!=-1){
NodeV[ParentNodeId].Val2.Add(
NodeV.Len());}
2385 void DelNode(
const int& NodeId);
2386 void CopyTree(
const int& SrcNodeId,
TTree& DstTree,
const int& DstParentNodeId=-1);
2388 void WrTree(
const int& NodeId=0,
const int& Lev=0);
2391 template <
class TVal>
2393 if (NodeId==0){NodeIdV.
Clr();
if (GetNodes()==0){
return;}}
2394 else if (GetParentNodeId(NodeId)==-1){
return;}
2395 NodeIdV.
Add(NodeId);
2396 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2397 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2398 if (ChildNodeId!=-1){
2399 GetNodeIdV(NodeIdV, ChildNodeId);
2404 template <
class TVal>
2409 for (
int NodeN=1; NodeN<Nodes; NodeN++){
2411 AddNode(ParentNodeId, TVal());
2416 template <
class TVal>
2421 TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2422 int ChildNodeIdN=ChildNodeIdV.
SearchForw(NodeId);
2423 ChildNodeIdV[ChildNodeIdN]=-1;
2427 template <
class TVal>
2429 int DstNodeId=DstTree.
AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
2430 for (
int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
2431 int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
2432 if (ChildNodeId!=-1){
2433 CopyTree(ChildNodeId, DstTree, DstNodeId);
2438 template <
class TVal>
2440 for (
int LevN=0; LevN<Lev; LevN++){printf(
"| ");}
2441 printf(
"%d (%d)\n", NodeId, GetChildren(NodeId));
2442 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2443 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2444 if (ChildNodeId!=-1){
2445 WrTree(ChildNodeId, Lev+1);
2460 template <
class TVal>
2472 if (
this!=&Stack){
ValV=Stack.
ValV;}
return *
this;}
2495 template <
class TVal>
2502 TQQueue(
const int& _MxLast=64,
const int& _MxLen=-1):
2522 void Gen(
const int& _MxLast=64,
const int& _MxLen=-1){
2527 SubValV.
Gen(EValN-BValN+1);
2528 for (
int ValN=BValN; ValN<=EValN; ValN++){
2529 SubValV[ValN-BValN]=
ValV[
Last+ValN];}
2547 for (
int ValN=0; ValN<ValV.
Len(); ValN++){
Push(ValV[ValN]);}}
2563 template <
class TVal>
2587 template <
class TVal>
2606 while (Nd!=NULL){
PLstNd NextNd=Nd->
NextNd;
delete Nd; Nd=NextNd;}
2623 void Del(
const TVal& Val);
2634 template <
class TVal>
2636 Nds(0), FirstNd(NULL), LastNd(NULL){
2637 int CheckNds=0; SIn.
Load(CheckNds);
2638 for (
int NdN=0; NdN<CheckNds; NdN++){
AddBack(TVal(SIn));}
2642 template <
class TVal>
2645 PLstNd Nd=FirstNd;
int CheckNds=0;
2647 Nd->
Val.Save(SOut); Nd=Nd->
NextNd; CheckNds++;}
2651 template <
class TVal>
2654 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
2655 else {FirstNd=Nd; LastNd=Nd;}
2659 template <
class TVal>
2662 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
2663 else {FirstNd=Nd; LastNd=Nd;}
2667 template <
class TVal>
2671 return Ins(Nd, Val);
2673 while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
2675 if (Nd==NULL){
return Ins(Nd->Last(),
Val);}
2676 else {
return Ins(Nd->
Prev(),
Val);}
2680 template <
class TVal>
2683 while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->
Val)))){
2685 return Ins(Nd, Val);
2688 template <
class TVal>
2698 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
2699 else {FirstNd=Nd; LastNd=Nd;}
2702 template <
class TVal>
2712 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
2713 else {FirstNd=Nd; LastNd=Nd;}
2716 template <
class TVal>
2718 if (Nd==NULL){
return AddFront(Val);}
2719 else if (Nd->
NextNd==NULL){
return AddBack(Val);}
2727 template <
class TVal>
2729 PLstNd Nd=SearchForw(Val);
2730 if (Nd!=NULL){Del(Nd);}
2733 template <
class TVal>
2743 template <
class TVal>
2753 template <
class TVal>
2780 template <
class THd,
class TRec>
2786 FRnd(
PFRnd(new
TFRnd(FNm, FAccess, CreateIfNo, sizeof(THd), sizeof(TRec)))){}
2803 template <
class TFuncPt>
2819 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.
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
void Save(TSOut &SOut) const
void PutRec(const TRec &Rec, const int &RecN=-1)
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.
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 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
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)
Result is the intersection of this vector with ValV.
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
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 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
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)
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.
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.
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.
void Del(const TVal &Val)
void Union(const TVec< TVal, TSizeTy > &ValV)
Result is the union of this vector with ValV.
TLstNd(TLstNd *_PrevNd, TLstNd *_NextNd, const TVal &_Val)
TKeyDat< TUInt, TUInt > TUIntKd
TVec< TUChUInt64Pr > TUChUInt64PrV
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()
The vector reduces its 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
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.
TTriple< TUCh, TInt, TInt > TUChIntIntTr
int AddEmptyV(const int &ValVLen)
TVec< TFltStrKd > TFltStrKdV
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
Returns a vector on 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.