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;}
1478 namespace TGLib_OLD {
1480 template <
class TVal>
1488 void Resize(
const int& _MxVals=-1);
1495 if (_Vals==0){
ValT=NULL;}
else {
ValT=
new TVal[_Vals];}}
1496 TVec(
const int& _MxVals,
const int& _Vals){
1498 if (_MxVals==0){
ValT=NULL;}
else {
ValT=
new TVal[_MxVals];}}
1499 explicit TVec(TVal *_ValT,
const int& _Vals):
1511 bool operator<(const TVec<TVal>& Vec)
const;
1519 return int(2*
sizeof(
int)+
sizeof(TVal*)+
MxVals*
sizeof(TVal));}
1528 void Gen(
const int& _MxVals,
const int& _Vals){
1529 IAssert((0<=_Vals)&&(_Vals<=_MxVals));
1531 if (_MxVals==0){
ValT=NULL;}
else {
ValT=
new TVal[_MxVals];}}
1537 void Reserve(
const int& _MxVals,
const int& _Vals){
1538 IAssert((0<=_Vals)&&(_Vals<=_MxVals));
1540 void Clr(
const bool& DoDel=
true,
const int& NoDelLim=-1);
1541 void Trunc(
const int& _Vals=-1);
1567 int Add(
const TVal& Val,
const int& ResizeLen){
1570 int AddSorted(
const TVal& Val,
const bool& Asc=
true,
const int& _MxVals=-1);
1578 void Ins(
const int& ValN,
const TVal& Val);
1579 void Del(
const int& ValN);
1580 void Del(
const int& MnValN,
const int& MxValN);
1582 bool DelIfIn(
const TVal& Val);
1583 void DelAll(
const TVal& Val);
1584 void PutAll(
const TVal& Val);
1586 void Swap(
const int& ValN1,
const int& ValN2){
1589 TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
1591 int GetPivotValN(
const int& LValN,
const int& RValN)
const;
1592 void BSort(
const int& MnLValN,
const int& MxRValN,
const bool& Asc);
1593 void ISort(
const int& MnLValN,
const int& MxRValN,
const bool& Asc);
1594 int Partition(
const int& MnLValN,
const int& MxRValN,
const bool& Asc);
1595 void QSort(
const int& MnLValN,
const int& MxRValN,
const bool& Asc);
1596 void Sort(
const bool& Asc=
true);
1597 bool IsSorted(
const bool& Asc=
true)
const;
1601 Last--;
while (First < Last){
Swap(First++, Last--);}}
1617 template <
class TCmp>
1619 int Parent = (HoleIdx-1)/2;
1620 while (HoleIdx > Top &&
Cmp(
ValT[First+Parent], Val)) {
1621 ValT[First+HoleIdx] =
ValT[First+Parent];
1622 HoleIdx = Parent; Parent = (HoleIdx-1)/2; }
1623 ValT[First+HoleIdx] = Val;
1625 template <
class TCmp>
1627 const int Top = HoleIdx;
1628 int Right = 2*HoleIdx+2;
1629 while (Right < Len) {
1630 if (
Cmp(
ValT[First+Right],
ValT[First+Right-1])) { Right--; }
1631 ValT[First+HoleIdx] =
ValT[First+Right];
1632 HoleIdx = Right; Right = 2*(Right+1); }
1634 ValT[First+HoleIdx] =
ValT[First+Right-1];
1635 HoleIdx = Right-1; }
1636 PushHeap(First, HoleIdx, Top, Val, Cmp);
1638 template <
class TCmp>
1640 if (Len < 2) {
return; }
1641 int Parent = (Len-2)/2;
1644 if (Parent == 0) {
return; } Parent--; }
1647 template <
class TCmp>
1649 const int SubVals=int(EI-BI);
1653 const TVal& Val1 = *(BI+ValN1);
1654 const TVal& Val2 = *(BI+ValN2);
1655 const TVal& Val3 = *(BI+ValN3);
1656 if (
Cmp(Val1, Val2)) {
1657 if (
Cmp(Val2, Val3))
return BI+ValN2;
1658 else if (
Cmp(Val3, Val1))
return BI+ValN1;
1659 else return BI+ValN3;
1661 if (
Cmp(Val1, Val3))
return BI+ValN1;
1662 else if (
Cmp(Val3, Val2))
return BI+ValN2;
1663 else return BI+ValN3;
1667 template <
class TCmp>
1670 while (
Cmp(*BI, Pivot)) ++BI;
1672 while (
Cmp(Pivot, *EI)) --EI;
1673 if (!(BI < EI))
return BI;
1679 template <
class TCmp>
1681 for (
TIter i = BI; i != EI; ++i) {
1682 for (
TIter j = EI-1; j != i; --j) {
1683 if (
Cmp(*j, *(j-1)))
SwapI(j, j-1); }
1687 template <
class TCmp>
1690 for (
TIter i = BI, j; i != EI; ++i) {
1691 TVal Tmp = *i; j = i;
1692 while (j > BI &&
Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; }
1698 template <
class TCmp>
1716 template <
class TCmp>
1724 template <
class TCmp>
1728 if (
Cmp(*(i+1), *i)){
return false;}}
1745 int Count(
const TVal& Val)
const;
1747 int SearchBin(
const TVal& Val,
int& InsValN)
const;
1748 int SearchForw(
const TVal& Val,
const int& BValN=0)
const;
1752 bool IsIn(
const TVal& Val,
int& ValN)
const {
1762 if (ValN==-1){
Add(Val);
return Last();}
1772 static TVec<TVal> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4){
1774 static TVec<TVal> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5){
1776 static TVec<TVal> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6){
1778 static TVec<TVal> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7){
1780 static TVec<TVal> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7,
const TVal& Val8){
1782 static TVec<TVal> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7,
const TVal& Val8,
const TVal& Val9){
1788 template <
class TVal>
1790 IAssertR(MxVals!=-1,
TStr::Fmt(
"Can not resize buffer. %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
GetTypeNm(*this).
CStr()).CStr());
1791 IAssertR(MxVals!=(
TInt::Mx-1024),
TStr::Fmt(
"Buffer size at maximum. %s. [Program refuses to allocate more memory. Solution-2: Send your test case to developers.]",
GetTypeNm(*this).
CStr()).CStr());
1793 if (Vals==0){MxVals=16;}
else {MxVals*=2;}
1795 if (_MxVals<=MxVals){
return;}
else {MxVals=_MxVals;}
1801 try {ValT=
new TVal[MxVals];}
1802 catch (std::exception Ex){
1803 FailR(
TStr::Fmt(
"TVec::Resize 1: %s, Vals:%d, MxVals:%d, _MxVals:%d, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
1804 Ex.what(), Vals, MxVals, _MxVals,
GetTypeNm(*this).
CStr()).CStr());}
1808 TVal* NewValT = NULL;
1810 NewValT=
new TVal[MxVals];}
1811 catch (std::exception Ex){
1812 FailR(
TStr::Fmt(
"TVec::Resize 2: %s, Vals:%d, MxVals:%d, _MxVals:%d, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
1813 Ex.what(), Vals, MxVals, _MxVals,
GetTypeNm(*this).
CStr()).CStr());}
1815 for (
int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1816 delete[] ValT; ValT=NewValT;
1820 template <
class TVal>
1829 template <
class TVal>
1832 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
1833 for (
int ValN=0; ValN<Vec.
Vals; ValN++){ValT[ValN]=Vec.
ValT[ValN];}
1836 template <
class TVal>
1838 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
1839 SIn.
Load(MxVals); SIn.
Load(Vals); MxVals=Vals;
1840 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
1841 for (
int ValN=0; ValN<Vals; ValN++){
1842 ValT[ValN]=TVal(SIn);}
1845 template <
class TVal>
1847 if (MxVals!=-1){SOut.
Save(MxVals);}
else {SOut.
Save(Vals);}
1849 for (
int ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
1852 template <
class TVal>
1855 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
1856 MxVals=Vals=Vec.
Vals;
1857 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
1858 for (
int ValN=0; ValN<Vec.
Vals; ValN++){ValT[ValN]=Vec.
ValT[ValN];}
1863 template <
class TVal>
1865 if (
this==&Vec){
return true;}
1866 if (Len()!=Vec.
Len()){
return false;}
1867 for (
int ValN=0; ValN<Vals; ValN++){
1868 if (ValT[ValN]!=Vec.
ValT[ValN]){
return false;}}
1872 template <
class TVal>
1874 if (
this==&Vec){
return false;}
1875 if (Len()==Vec.
Len()){
1876 for (
int ValN=0; ValN<Vals; ValN++){
1877 if (ValT[ValN]<Vec.
ValT[ValN]){
return true;}
1878 else if (ValT[ValN]>Vec.
ValT[ValN]){
return false;}
1883 return Len()<Vec.
Len();
1887 template <
class TVal>
1890 for (
int ValN=0; ValN<Vals; ValN++){
1891 HashCd+=ValT[ValN].GetPrimHashCd();}
1895 template <
class TVal>
1898 for (
int ValN=0; ValN<Vals; ValN++){
1899 HashCd+=ValT[ValN].GetSecHashCd();}
1903 template <
class TVal>
1905 if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){
1906 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
1907 MxVals=Vals=0; ValT=NULL;
1913 template <
class TVal>
1916 IAssert((_Vals==-1)||(_Vals>=0));
1917 if ((_Vals!=-1)&&(_Vals>=Vals)){
1920 if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){
1921 if (ValT!=NULL){
delete[] ValT;}
1922 MxVals=Vals=0; ValT=NULL;
1925 if (MxVals==Vals){
return;}
else {MxVals=Vals;}
1929 TVal* NewValT=
new TVal[MxVals];
1931 for (
int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1932 delete[] ValT; ValT=NewValT;
1936 template <
class TVal>
1940 if (ValT!=NULL){
delete[] ValT;} ValT=NULL;
1944 TVal* NewValT=
new TVal[MxVals];
1946 for (
int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1947 delete[] ValT; ValT=NewValT;
1951 template <
class TVal>
1954 if (ValT!=NULL && MxVals!=-1){
delete[] ValT;}
1960 template <
class TVal>
1969 template <
class TVal>
1972 for (
int ValN=0; ValN<ValV.
Vals; ValN++){Add(ValV[ValN]);}
1976 template <
class TVal>
1981 while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){
1982 Swap(ValN, ValN-1); ValN--;}
1984 while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){
1985 Swap(ValN, ValN-1); ValN--;}
1987 if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);}
1991 template <
class TVal>
1996 while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
1997 ValT[ValN+1]=ValT[ValN]; ValN--;}
2002 template <
class TVal>
2005 int ValN=SearchBin(Val);
2006 if (ValN==-1){
return AddSorted(Val);}
2007 else {GetVal(ValN)=Val;
return -1;}
2010 template <
class TVal>
2013 for (
int ValN=0; ValN<ValV.
Vals; ValN++){AddMerged(ValV[ValN]);}
2017 template <
class TVal>
2020 int ValN=SearchForw(Val);
2021 if (ValN==-1){
return Add(Val);}
2022 else {GetVal(ValN)=Val;
return -1;}
2025 template <
class TVal>
2027 const int& _BValN,
const int& _EValN,
TVec<TVal>& SubValV)
const {
2031 SubValV.
Gen(SubVals, 0);
2032 for (
int ValN=BValN; ValN<=EValN; ValN++){
2033 SubValV.
Add(GetVal(ValN));}
2036 template <
class TVal>
2039 Add();
Assert((0<=ValN)&&(ValN<Vals));
2040 for (
int MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
2044 template <
class TVal>
2047 Assert((0<=ValN)&&(ValN<Vals));
2048 for (
int MValN=ValN+1; MValN<Vals; MValN++){
2049 ValT[MValN-1]=ValT[MValN];}
2050 ValT[--Vals]=TVal();
2053 template <
class TVal>
2056 Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
2058 for (
int ValN=MxValN+1; ValN<Vals; ValN++){
2059 ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
2060 for (
int ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
2062 Vals-=MxValN-MnValN+1;
2065 template <
class TVal>
2068 int ValN=SearchForw(Val);
2069 if (ValN!=-1){Del(ValN);
return true;}
2070 else {
return false;}
2073 template <
class TVal>
2077 while ((ValN=SearchForw(Val))!=-1){
2081 template <
class TVal>
2083 for (
int ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
2086 template <
class TVal>
2088 const int& MnLValN,
const int& MxRValN,
const bool& Asc){
2089 for (
int ValN1=MnLValN; ValN1<=MxRValN; ValN1++){
2090 for (
int ValN2=MxRValN; ValN2>ValN1; ValN2--){
2092 if (ValT[ValN2]<ValT[ValN2-1]){
Swap(ValN2, ValN2-1);}
2094 if (ValT[ValN2]>ValT[ValN2-1]){
Swap(ValN2, ValN2-1);}
2100 template <
class TVal>
2102 const int& MnLValN,
const int& MxRValN,
const bool& Asc){
2103 if (MnLValN<MxRValN){
2104 for (
int ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){
2105 TVal Val=ValT[ValN1];
int ValN2=ValN1;
2107 while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){
2108 ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
2110 while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){
2111 ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
2118 template <
class TVal>
2120 int SubVals=RValN-LValN+1;
2124 const TVal& Val1=ValT[ValN1];
2125 const TVal& Val2=ValT[ValN2];
2126 const TVal& Val3=ValT[ValN3];
2128 if (Val2<Val3){
return ValN2;}
2129 else if (Val3<Val1){
return ValN1;}
2130 else {
return ValN3;}
2132 if (Val1<Val3){
return ValN1;}
2133 else if (Val3<Val2){
return ValN2;}
2134 else {
return ValN3;}
2138 template <
class TVal>
2140 const int& MnLValN,
const int& MxRValN,
const bool& Asc){
2141 int PivotValN=GetPivotValN(MnLValN, MxRValN);
2142 Swap(PivotValN, MnLValN);
2143 TVal PivotVal=ValT[MnLValN];
2144 int LValN=MnLValN-1;
int RValN=MxRValN+1;
2147 do {RValN--;}
while (ValT[RValN]>PivotVal);
2148 do {LValN++;}
while (ValT[LValN]<PivotVal);
2150 do {RValN--;}
while (ValT[RValN]<PivotVal);
2151 do {LValN++;}
while (ValT[LValN]>PivotVal);
2153 if (LValN<RValN){
Swap(LValN, RValN);}
2154 else {
return RValN;}
2158 template <
class TVal>
2160 const int& MnLValN,
const int& MxRValN,
const bool& Asc){
2161 if (MnLValN<MxRValN){
2162 if (MxRValN-MnLValN<20){
2163 ISort(MnLValN, MxRValN, Asc);
2165 int SplitValN=Partition(MnLValN, MxRValN, Asc);
2166 QSort(MnLValN, SplitValN, Asc);
2167 QSort(SplitValN+1, MxRValN, Asc);
2172 template <
class TVal>
2174 QSort(0, Len()-1, Asc);
2177 template <
class TVal>
2180 for (
int ValN=0; ValN<Vals-1; ValN++){
2181 if (ValT[ValN]>ValT[ValN+1]){
return false;}}
2183 for (
int ValN=0; ValN<Vals-1; ValN++){
2184 if (ValT[ValN]<ValT[ValN+1]){
return false;}}
2189 template <
class TVal>
2191 for (
int ValN=0; ValN<Vals-1; ValN++){
2195 template <
class TVal>
2197 for (
int ValN=0; ValN<Vals/2; ValN++){
2198 Swap(ValN, Vals-ValN-1);}
2201 template <
class TVal>
2206 for (
int ValN=0; ValN<SortedVec.
Len(); ValN++){
2207 if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){
2208 Add(SortedVec[ValN]);}
2212 template <
class TVal>
2215 int First = 0, Last = Len(), Next = Len()-1;
2216 if (Last < 2)
return false;
2220 if (GetVal(--Next) < GetVal(Next1)) {
2222 for (; GetVal(Next) >= GetVal(--Mid); ) { }
2224 Reverse(Next1, Last);
2227 if (Next == First) {
2234 template <
class TVal>
2236 int First = 0, Last = Len(), Next = Len()-1;
2237 if (Last < 2)
return false;
2241 if (GetVal(--Next) >= GetVal(Next1)) {
2243 for (; GetVal(Next) < GetVal(--Mid); ) { }
2245 Reverse(Next1, Last);
2248 if (Next == First) {
2255 template <
class TVal>
2258 Intrs(ValV, IntrsVec);
2262 template <
class TVal>
2265 Union(ValV, UnionVec);
2269 template <
class TVal>
2272 Diff(ValV, DiffVec);
2276 template <
class TVal>
2279 Minus(ValV, MinusVec);
2283 template <
class TVal>
2286 int ValN1=0;
int ValN2=0;
2287 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
2288 const TVal& Val1=GetVal(ValN1);
2289 while ((ValN2<ValV.
Len())&&(Val1>ValV.
GetVal(ValN2))){
2291 if ((ValN2<ValV.
Len())&&(Val1==ValV.
GetVal(ValN2))){
2292 DstValV.
Add(Val1); ValN2++;}
2297 template <
class TVal>
2300 int ValN1=0;
int ValN2=0;
2301 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
2302 const TVal& Val1=GetVal(ValN1);
2303 const TVal& Val2=ValV.
GetVal(ValN2);
2304 if (Val1<Val2){DstValV.
Add(Val1); ValN1++;}
2305 else if (Val1>Val2){DstValV.
Add(Val2); ValN2++;}
2306 else {DstValV.
Add(Val1); ValN1++; ValN2++;}
2308 for (
int RestValN1=ValN1; RestValN1<Len(); RestValN1++){
2309 DstValV.
Add(GetVal(RestValN1));}
2310 for (
int RestValN2=ValN2; RestValN2<ValV.
Len(); RestValN2++){
2345 template <
class TVal>
2348 int ValN1=0;
int ValN2=0;
2349 while (ValN1<Len() && ValN2<ValV.
Len()) {
2350 const TVal& Val1 = GetVal(ValN1);
2351 while (ValN2<ValV.
Len() && Val1>ValV.
GetVal(ValN2)) ValN2++;
2352 if (ValN2<ValV.
Len()) {
2353 if (Val1!=ValV.
GetVal(ValN2)) { DstValV.
Add(Val1); }
2357 for (
int RestValN1=ValN1; RestValN1<Len(); RestValN1++){
2358 DstValV.
Add(GetVal(RestValN1));}
2361 template <
class TVal>
2363 int Cnt=0, ValN1=0;
int ValN2=0;
2364 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
2365 const TVal& Val1=GetVal(ValN1);
2366 while ((ValN2<ValV.
Len())&&(Val1>ValV.
GetVal(ValN2))){
2368 if ((ValN2<ValV.
Len())&&(Val1==ValV.
GetVal(ValN2))){
2375 template <
class TVal>
2377 int Cnt = 0, ValN1 = 0, ValN2 = 0;
2378 while ((ValN1 < Len()) && (ValN2 < ValV.
Len())) {
2379 const TVal& Val1 = GetVal(ValN1);
2380 const TVal& Val2 = ValV.
GetVal(ValN2);
2383 }
else if (Val1 > Val2) {
2386 Cnt++; ValN1++; ValN2++;
2389 Cnt += (Len() - ValN1) + (ValV.
Len() - ValN2);
2393 template <
class TVal>
2395 Diff(ValV, DstValV);
2398 template <
class TVal>
2401 for (
int i = 0; i < Len(); i++){
2402 if (Val == ValT[i]){Count++;}}
2406 template <
class TVal>
2408 int LValN=0;
int RValN=Len()-1;
2409 while (RValN>=LValN){
2410 int ValN=(LValN+RValN)/2;
2411 if (Val==ValT[ValN]){
return ValN;}
2412 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
2417 template <
class TVal>
2419 int LValN=0;
int RValN=Len()-1;
2420 while (RValN>=LValN){
2421 int ValN=(LValN+RValN)/2;
2422 if (Val==ValT[ValN]){InsValN=ValN;
return ValN;}
2423 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
2425 InsValN=LValN;
return -1;
2428 template <
class TVal>
2430 for (
int ValN=BValN; ValN<Vals; ValN++){
2431 if (Val==ValT[ValN]){
return ValN;}}
2435 template <
class TVal>
2437 for (
int ValN=Vals-1; ValN>=0; ValN--){
2438 if (Val==ValT[ValN]){
return ValN;}}
2442 template <
class TVal>
2444 int ValVLen=ValV.
Len();
2445 for (
int ValN=BValN; ValN<Vals-ValVLen+1; ValN++){
2447 for (
int SubValN=0; SubValN<ValVLen; SubValN++){
2448 if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=
false;
break;}
2450 if (Found){
return ValN;}
2455 template <
class TVal>
2457 if (Vals==0){
return -1;}
2459 for (
int ValN=1; ValN<Vals; ValN++){
2460 if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
2549 template <
class TVal,
class TSizeTy=
int>
2570 TVecPool(
const TSize& ExpectVals=0,
const TSize& _GrowBy=1000000,
const bool& _FastCopy=
false,
const TVal& _EmptyVal=TVal());
2623 for (::
TSize ValN=0; ValN <
::TSize(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
2647 template <
class TVal,
class TSizeTy>
2649 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
2650 if (ValBf == NULL) {
2651 try { ValBf =
new TVal [MxVals]; }
2652 catch (std::exception Ex) {
2653 FailR(
TStr::Fmt(
"TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(),
TInt::GetStr(
uint64(_MxVals)).
CStr()).CStr()); }
2655 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
2658 TVal* NewValBf = NULL;
2659 try { NewValBf =
new TVal [MxVals]; }
2660 catch (std::exception Ex) {
2661 FailR(
TStr::Fmt(
"TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(),
TInt::GetStr(
uint64(_MxVals)).
CStr()).CStr()); }
2664 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
2666 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
2667 if (EmptyVal != TVal()) {
2668 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
2675 template <
class TVal,
class TSizeTy>
2681 template <
class TVal,
class TSizeTy>
2685 catch (std::exception Ex) {
2694 template <
class TVal,
class TSizeTy>
2696 uint64 _GrowBy, _MxVals, _Vals;
2702 for (
TSize ValN = 0; ValN <
Vals; ValN++) {
ValBf[ValN] = TVal(SIn); }
2705 for (
int ValN = 0; ValN <
Vals; ValN++) {
2711 template <
class TVal,
class TSizeTy>
2713 SOut.
Save(FastCopy);
2714 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2715 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
2716 SOut.
Save(EmptyVal);
2717 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2718 { SOut.
Save(IdToOffV.Len()); SOut.
Save(IdToOffV.Len());
2719 for (
int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
2720 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
2724 template <
class TVal,
class TSizeTy>
2734 ValBf =
new TVal [MxVals]; }
2735 catch (std::exception Ex) {
2736 FailR(
TStr::Fmt(
"TVecPool::operator=: %s, MxVals: %s. [Program failed to allocate memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(),
TInt::GetStr(
uint64(MxVals)).
CStr()).CStr()); }
2739 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
2741 for (
TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
2746 template <
class TVal,
class TSizeTy>
2748 const TSizeTy ValVLen = ValV.
Len();
2749 if (ValVLen == 0) {
return 0; }
2750 if (MxVals < Vals+ValVLen) { Resize(Vals+
max(ValVLen, GrowBy)); }
2751 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
2752 else {
for (
uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2753 Vals+=ValVLen; IdToOffV.
Add(Vals);
2754 return IdToOffV.Len()-1;
2757 template <
class TVal,
class TSizeTy>
2759 if (ValVLen==0){
return 0;}
2760 if (MxVals < Vals+ValVLen){Resize(Vals+
max(
TSize(ValVLen), GrowBy)); }
2761 Vals+=ValVLen; IdToOffV.Add(Vals);
2762 return IdToOffV.Len()-1;
2766 template <
class TVal,
class TSizeTy>
2770 for (
int vid = 1; vid < IdToOffV.Len(); vid++) {
2772 const uint Len = GetVLen(vid);
2773 TVal* ValV = GetValVPt(vid);
2774 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
2775 if (Len == 0) {
continue; }
2777 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
2780 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
2781 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
2785 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
2788 IdToOffV.Last() -= TotalDel;
2789 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
2795 template <
class TVal,
class TSizeTy>
2797 for (::
TSize n = Vals-1; n > 0; n--) {
2799 const TVal Tmp = ValBf[n];
2800 ValBf[n] = ValBf[k];
2812 namespace TGLib_OLD {
2815 template<
class TVal>
2855 if (VId==0){
return 0;}
2868 for (
uint ValN=0; ValN <
uint(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
2887 template <
class TVal>
2889 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
2890 if (ValBf == NULL) {
2891 try { ValBf =
new TVal [MxVals]; }
2892 catch (std::exception Ex) {
2893 FailR(
TStr::Fmt(
"TVecPool::Resize 1: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
2895 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
2898 TVal* NewValBf = NULL;
2899 try { NewValBf =
new TVal [MxVals]; }
2900 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVecPool::Resize 2: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
2903 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
2905 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
2906 if (EmptyVal != TVal()) {
2907 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
2914 template <
class TVal>
2916 GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
2921 template <
class TVal>
2923 FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy),
2924 MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
2926 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVecPool::TVecPool: %s, MxVals: %d", Ex.what(),
MxVals).CStr()); }
2934 template <
class TVal>
2937 uint64 _GrowBy, _MxVals, _Vals;
2943 for (
TSize ValN = 0; ValN <
Vals; ValN++) {
ValBf[ValN] = TVal(SIn); }
2946 for (
int ValN = 0; ValN <
Vals; ValN++) {
2952 template <
class TVal>
2954 SOut.
Save(FastCopy);
2955 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2956 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
2957 SOut.
Save(EmptyVal);
2958 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2959 { SOut.
Save(IdToOffV.Len()); SOut.
Save(IdToOffV.Len());
2960 for (
int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
2961 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
2965 template <
class TVal>
2974 try { ValBf =
new TVal [MxVals]; }
2975 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVec::operator= : %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
2978 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
2980 for (
uint64 ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
2985 template<
class TVal>
2988 if (ValVLen == 0) {
return 0; }
2989 if (MxVals < Vals+ValVLen) { Resize(Vals+
max(ValVLen, GrowBy)); }
2990 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
2991 else {
for (
uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2992 Vals+=ValVLen; IdToOffV.
Add(Vals);
2993 return IdToOffV.Len()-1;
2996 template<
class TVal>
2998 if (ValVLen==0){
return 0;}
2999 if (MxVals < Vals+ValVLen){Resize(Vals+
max(
TSize(ValVLen), GrowBy)); }
3000 Vals+=ValVLen; IdToOffV.Add(Vals);
3001 return IdToOffV.Len()-1;
3006 template<
class TVal>
3010 for (
int vid = 1; vid < IdToOffV.Len(); vid++) {
3012 const uint Len = GetVLen(vid);
3013 TVal* ValV = GetValVPt(vid);
3014 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
3015 if (Len == 0) {
continue; }
3017 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
3020 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
3021 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
3025 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
3028 IdToOffV.Last() -= TotalDel;
3029 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
3035 template<
class TVal>
3037 for (::
TSize n = Vals-1; n > 0; n--) {
3039 const TVal Tmp = ValBf[n];
3040 ValBf[n] = ValBf[k];
3052 template <
class TVal>
3074 if (
this!=&Vec){
V=Vec.
V;}
return *
this;}
3076 bool operator<(const PVec<TVal>& Vec)
const {
return V<Vec.V;}
3081 TVal
GetVal(
const int& ValN)
const {
return V[ValN];}
3099 template <
class TVal>
3108 TVVec(
const int& _XDim,
const int& _YDim):
3124 void Gen(
const int& _XDim,
const int& _YDim){
3125 Assert((_XDim>=0)&&(_YDim>=0));
3133 const TVal&
At(
const int& X,
const int& Y)
const {
3136 TVal&
At(
const int& X,
const int& Y){
3144 void PutXY(
const int& X,
const int& Y,
const TVal& Val){
At(X, Y)=Val;}
3146 void PutX(
const int& X,
const TVal& Val){
3147 for (
int Y=0; Y<int(
YDim); Y++){
At(X, Y)=Val;}}
3148 void PutY(
const int& Y,
const TVal& Val){
3149 for (
int X=0; X<int(
XDim); X++){
At(X, Y)=Val;}}
3150 TVal
GetXY(
const int& X,
const int& Y)
const {
3156 void SwapX(
const int& X1,
const int& X2);
3157 void SwapY(
const int& Y1,
const int& Y2);
3167 void DelX(
const int& X);
3168 void DelY(
const int& Y);
3171 template <
class TVal>
3173 for (
int Y=0; Y<int(YDim); Y++){
3174 TVal Val=At(X1, Y); At(X1, Y)=At(X2, Y); At(X2, Y)=Val;}
3177 template <
class TVal>
3179 for (
int X=0; X<int(XDim); X++){
3180 TVal Val=At(X, Y1); At(X, Y1)=At(X, Y2); At(X, Y2)=Val;}
3183 template <
class TVal>
3188 ValV.Swap(Vec.
ValV);
3192 template <
class TVal>
3194 for (
int X=0; X<XDim-1; X++){SwapX(X, X+Rnd.
GetUniDevInt(XDim-X));}
3197 template <
class TVal>
3199 for (
int Y=0; Y<YDim-1; Y++){SwapY(Y, Y+Rnd.
GetUniDevInt(YDim-Y));}
3202 template <
class TVal>
3204 int MxValN=ValV.GetMxValN();
3209 template <
class TVal>
3213 for (
int X=0; X<CopyXDim; X++){
3214 for (
int Y=0; Y<CopyYDim; Y++){
3215 At(X, Y)=VVec.
At(X, Y);
3220 template <
class TVal>
3227 template <
class TVal>
3234 template <
class TVal>
3237 for (
int Y=0; Y<YDim; Y++){
3238 for (
int LX=0; LX<X; LX++){
3239 NewVVec.
At(LX, Y)=At(LX, Y);}
3240 for (
int RX=X+1; RX<XDim; RX++){
3241 NewVVec.
At(RX-1, Y)=At(RX, Y);}
3246 template <
class TVal>
3249 for (
int X=0; X<XDim; X++){
3250 for (
int LY=0; LY<Y; LY++){
3251 NewVVec.
At(X, LY)=At(X, LY);}
3252 for (
int RY=Y+1; RY<YDim; RY++){
3253 NewVVec.
At(X, RY-1)=At(X, RY);}
3258 template <
class TVal>
3260 Vec.
Gen(GetCols(), 0);
3261 for (
int col = 0; col < GetCols(); col++) {
3262 Vec.
Add(At(RowN, col));
3266 template <
class TVal>
3268 Vec.
Gen(GetRows(), 0);
3269 for (
int row = 0; row < GetRows(); row++) {
3270 Vec.
Add(At(row, ColN));
3286 template <
class TVal>
3295 TVVVec(
const int& _XDim,
const int& _YDim,
const int& _ZDim):
3312 void Gen(
const int& _XDim,
const int& _YDim,
const int& _ZDim){
3313 Assert((_XDim>=0)&&(_YDim>=0)&&(_ZDim>=0));
3315 TVal&
At(
const int& X,
const int& Y,
const int& Z){
3318 const TVal&
At(
const int& X,
const int& Y,
const int& Z)
const {
3322 return At(X, Y, Z);}
3323 const TVal&
operator()(
const int& X,
const int& Y,
const int& Z)
const {
3324 return At(X, Y, Z);}
3337 template <
class TVal>
3360 int AddNode(
const int& ParentNodeId,
const TVal& NodeVal=TVal()){
3362 if (ParentNodeId!=-1){
NodeV[ParentNodeId].Val2.Add(
NodeV.Len());}
3368 void GetNodeIdV(TIntV& NodeIdV,
const int& NodeId=0);
3376 void DelNode(
const int& NodeId);
3377 void CopyTree(
const int& SrcNodeId,
TTree& DstTree,
const int& DstParentNodeId=-1);
3379 void WrTree(
const int& NodeId=0,
const int& Lev=0);
3382 template <
class TVal>
3384 if (NodeId==0){NodeIdV.
Clr();
if (GetNodes()==0){
return;}}
3385 else if (GetParentNodeId(NodeId)==-1){
return;}
3386 NodeIdV.
Add(NodeId);
3387 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
3388 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
3389 if (ChildNodeId!=-1){
3390 GetNodeIdV(NodeIdV, ChildNodeId);
3395 template <
class TVal>
3400 for (
int NodeN=1; NodeN<Nodes; NodeN++){
3402 AddNode(ParentNodeId, TVal());
3407 template <
class TVal>
3412 TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
3413 int ChildNodeIdN=ChildNodeIdV.
SearchForw(NodeId);
3414 ChildNodeIdV[ChildNodeIdN]=-1;
3418 template <
class TVal>
3420 int DstNodeId=DstTree.
AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
3421 for (
int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
3422 int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
3423 if (ChildNodeId!=-1){
3424 CopyTree(ChildNodeId, DstTree, DstNodeId);
3429 template <
class TVal>
3431 for (
int LevN=0; LevN<Lev; LevN++){printf(
"| ");}
3432 printf(
"%d (%d)\n", NodeId, GetChildren(NodeId));
3433 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
3434 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
3435 if (ChildNodeId!=-1){
3436 WrTree(ChildNodeId, Lev+1);
3451 template <
class TVal>
3463 if (
this!=&Stack){
ValV=Stack.
ValV;}
return *
this;}
3486 template <
class TVal>
3493 TQQueue(
const int& _MxLast=64,
const int& _MxLen=-1):
3513 void Gen(
const int& _MxLast=64,
const int& _MxLen=-1){
3518 SubValV.
Gen(EValN-BValN+1);
3519 for (
int ValN=BValN; ValN<=EValN; ValN++){
3520 SubValV[ValN-BValN]=
ValV[
Last+ValN];}
3538 for (
int ValN=0; ValN<ValV.
Len(); ValN++){
Push(ValV[ValN]);}}
3554 template <
class TVal>
3578 template <
class TVal>
3597 while (Nd!=NULL){
PLstNd NextNd=Nd->
NextNd;
delete Nd; Nd=NextNd;}
3614 void Del(
const TVal& Val);
3625 template <
class TVal>
3627 Nds(0), FirstNd(NULL), LastNd(NULL){
3628 int CheckNds=0; SIn.
Load(CheckNds);
3629 for (
int NdN=0; NdN<CheckNds; NdN++){
AddBack(TVal(SIn));}
3633 template <
class TVal>
3636 PLstNd Nd=FirstNd;
int CheckNds=0;
3638 Nd->
Val.Save(SOut); Nd=Nd->
NextNd; CheckNds++;}
3642 template <
class TVal>
3645 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
3646 else {FirstNd=Nd; LastNd=Nd;}
3650 template <
class TVal>
3653 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
3654 else {FirstNd=Nd; LastNd=Nd;}
3658 template <
class TVal>
3662 return Ins(Nd, Val);
3664 while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
3666 if (Nd==NULL){
return Ins(Nd->Last(),
Val);}
3667 else {
return Ins(Nd->
Prev(),
Val);}
3671 template <
class TVal>
3674 while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->
Val)))){
3676 return Ins(Nd, Val);
3679 template <
class TVal>
3689 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
3690 else {FirstNd=Nd; LastNd=Nd;}
3693 template <
class TVal>
3703 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
3704 else {FirstNd=Nd; LastNd=Nd;}
3707 template <
class TVal>
3709 if (Nd==NULL){
return AddFront(Val);}
3710 else if (Nd->
NextNd==NULL){
return AddBack(Val);}
3718 template <
class TVal>
3720 PLstNd Nd=SearchForw(Val);
3721 if (Nd!=NULL){Del(Nd);}
3724 template <
class TVal>
3734 template <
class TVal>
3744 template <
class TVal>
3771 template <
class THd,
class TRec>
3777 FRnd(
PFRnd(new
TFRnd(FNm, FAccess, CreateIfNo, sizeof(THd), sizeof(TRec)))){}
3794 template <
class TFuncPt>
3810 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 PushHeap(const TVal &Val, const TCmp &Cmp)
void Save(TSOut &SOut) const
bool operator==(const TTree &Tree) const
TQuad< TStr, TStr, TStr, TStr > TStrQu
TVec< TFltIntKd > TFltIntKdV
int AddMerged(const TVal &Val)
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)
void Reserve(const int &_MxVals)
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.
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7)
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)
static TIter PartitionCmp(TIter BI, TIter EI, const TVal Pivot, const TCmp &Cmp)
TSizeTy Reserved() const
Returns the size of allocated storage capacity.
TVec< TIntIntVIntTr > TIntIntVIntTrV
#define IAssertR(Cond, Reason)
TPair< TUInt, TUInt > TUIntUIntPr
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7, const TVal &Val8)
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 Reserve(const int &_MxVals, const int &_Vals)
void Save(TSOut &SOut) const
static int GetInRng(const int &Val, const int &Mn, const int &Mx)
bool operator==(const TVVVec &Vec) const
void Diff(const TVec< TVal > &ValV)
TQQueue & operator=(const TQQueue &Queue)
static void SwapI(TIter LVal, TIter RVal)
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.
bool IsSorted(const bool &Asc=true) const
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
const TVal & LastLast() const
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)
int SearchVForw(const TVec< TVal > &ValV, const int &BValN=0) const
void QSort(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Quick sorts the values between positions MnLValN...MxLValN.
int GetPrimHashCd() const
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 MoveFrom(TVec< TVal > &Vec)
void Minus(const TVec< TVal > &ValV)
void CopyFrom(const TVVec< TVal > &VVec)
TSizeTy Len() const
Returns the number of elements in the vector.
TKeyDat< TInt, TFlt > TIntFltKd
TVec< TIntIntIntVTr > TIntIntIntVTrV
static void BSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
void PutRec(const void *Rec, const int &RecN=-1)
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6)
int GetSecHashCd() const
Returns secondary hash code of the vector. Used by THash.
void ISort(const int &MnLValN, const int &MxRValN, const bool &Asc)
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)
int SearchForw(const TVal &Val, const int &BValN=0) const
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.
bool IsIn(const TVal &Val) const
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 AdjustHeap(const int &First, int HoleIdx, const int &Len, TVal Val, const TCmp &Cmp)
bool IsInBin(const TVal &Val) const
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4)
void Resize(const TSize &_MxVals)
void SaveXml(TSOut &SOut, const TStr &Nm) const
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 GetSubValV(const int &BValN, const int &EValN, TVec< TVal > &ValV) const
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...
TVec(TVal *_ValT, const int &_Vals)
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
void Gen(const int &_Vals)
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 Union(const TVec< TVal > &ValV)
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 Sort(const bool &Asc=true)
bool DelIfIn(const TVal &Val)
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.
void DelAll(const TVal &Val)
void PutAll(const TVal &Val)
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3)
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
void Del(const int &ValN)
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.
void SortCmp(const TCmp &Cmp)
void MakeHeap(const TCmp &Cmp)
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
int AddVMerged(const TVec< TVal > &ValV)
int SearchBack(const TVal &Val) 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)
int AddSorted(const TVal &Val, const bool &Asc=true, const int &_MxVals=-1)
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.
void Swap(const int &ValN1, const int &ValN2)
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
TVec< TVal > & operator=(const TVec< TVal > &Vec)
void Clr(bool DoDel=true)
Clears the contents of the pool.
TCmpTripleByVal2(const bool &AscSort=true)
TCmpTripleByVal3(const bool &AscSort=true)
int AddV(const TVec< TVal > &ValV)
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 UnionLen(const TVec< TVal > &ValV) const
Returns the size of the union with vector ValV. Method assumes both vectors are sorted in ascending o...
void Reverse(int First, int Last)
void Gen(const int &_MxVals, const int &_Vals)
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 & TopHeap() const
const TVal & GetEmptyVal() const
Returns the reference to an empty value.
void Save(TSOut &SOut) const
TPair< TUInt64, TUInt64 > TUInt64Pr
int IntrsLen(const TVec< TVal > &ValV) const
Returns the size of the intersection (number of common elements) with vector ValV. Method assumes both vectors are sorted in ascending order!
TVecPool< TInt > TIntVecPool
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2)
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
void Swap(TVec< TVal > &Vec)
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
void BSort(const int &MnLValN, const int &MxRValN, const bool &Asc)
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
int AddUnique(const TVal &Val)
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.
TVec(const int &_MxVals, const int &_Vals)
void GetRow(const int &RowN, TVec< TVal > &Vec) const
TVec< TAscFltIntPr > TAscFltIntPrV
TVec< TFltUInt64Pr > TFltUInt64PrV
TPair< TBool, TFlt > TBoolFltPr
TVVVec(const TVVVec &Vec)
int SearchBin(const TVal &Val) const
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.
int Add(const TVal &Val, const int &ResizeLen)
void Save(const bool &Bool)
static TPt< PVec< TVal > > Load(TSIn &SIn)
TPair< TStr, TStrV > TStrStrVPr
TPair< TAscFlt, TAscFlt > TAscFltPr
TVec< TIntStrIntIntQu > TIntStrIntIntQuV
static TIter GetPivotValNCmp(const TIter &BI, const TIter &EI, const TCmp &Cmp)
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
TVec< TVal > & operator+(const TVal &Val)
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 MakeHeap(const int &First, const int &Len, const TCmp &Cmp)
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
void Ins(const int &ValN, const TVal &Val)
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.
void GenExt(TVal *_ValT, const int &_Vals)
bool IsIn(const TVal &Val, int &ValN) const
TVal & GetAddDat(const TVal &Val)
int AddRoot(const TVal &NodeVal=TVal())
TVec< TTriple< TInt, TIntV, TVal > > NodeV
static TVec< TVal > GetV(const TVal &Val1)
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)
const TVal & operator[](const int &ValN) const
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
TIter GetI(const int &ValN) const
void Trunc(const int &_Vals=-1)
void PutBack(const PLstNd &Nd)
void Resize(const int &_MxVals=-1)
void QSort(const int &MnLValN, const int &MxRValN, const bool &Asc)
TSizeTy Partition(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Partitions the values between positions MnLValN...MxLValN.
TSStack< TBoolChPr > TBoolChS
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7, const TVal &Val8, const TVal &Val9)
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.
void PushHeap(const int &First, int HoleIdx, const int &Top, TVal Val, const TCmp &Cmp)
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
bool operator<(const TVec< TVal > &Vec) const
static void QSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Quick sorts the values between positions BI...EI under the comparator Cmp.
int Partition(const int &MnLValN, const int &MxRValN, const bool &Asc)
TCmpPairByVal2(const bool &AscSort=true)
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
void Save(TSOut &SOut) const
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
int GetPivotValN(const int &LValN, const int &RValN) const
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
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
TVec< uint64, int > IdToOffV
const TVal & Last() const
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...
void Clr(const bool &DoDel=true, const int &NoDelLim=-1)
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.
TVal & GetVal(const int &ValN)
const TVal & GetVal(const int &ValN) const
TRec & operator[](const int &RecN) const
TPair< TFlt, TStr > TFltStrPr
void SetRecN(const int &RecN)
TVal & operator[](const int &ValN)
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 PushHeap(const TVal &Val)
int AddBackSorted(const TVal &Val, const bool &Asc)
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
TVal PopHeap(const TCmp &Cmp)
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
void Intrs(const TVec< TVal > &ValV)
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
TStr GetXOutOfBoundsErrMsg(const int &ValN) const
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
bool operator==(const TVec< TVal > &Vec) 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
TVal & GetDat(const TVal &Val) const
void Save(TSOut &SOut) const
TSizeTy GetMxValN() const
Returns the position of the largest element in the vector.
static void QSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
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
bool IsSortedCmp(const TCmp &Cmp) const
static void ISortCmp(TIter BI, TIter EI, const TCmp &Cmp)
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.
int Count(const TVal &Val) const
static TVec< TVal > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5)
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.