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++){
116 template <
class TVal1,
class TVal2>
129 template <
class TVal1,
class TVal2,
class TVal3>
139 TTriple(
const TVal1& _Val1,
const TVal2& _Val2,
const TVal3& _Val3):
160 void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3)
const {
193 template <
class TVal1,
class TVal2,
class TVal3>
205 template <
class TVal1,
class TVal2,
class TVal3>
218 template <
class TVal1,
class TVal2,
class TVal3,
class TVal4>
230 TQuad(
const TVal1& _Val1,
const TVal2& _Val2,
const TVal3& _Val3,
const TVal4& _Val4):
253 void GetVal(TVal1& _Val1, TVal2& _Val2, TVal3& _Val3, TVal4& _Val4)
const {
271 template<
class TVal,
int NVals>
277 TTuple(
const TVal& InitVal) {
for (
int i=0; i<
Len(); i++)
ValV[i]=InitVal; }
283 int Len()
const {
return NVals; }
287 for (
int i=0; i<
Len(); i++)
ValV[i]=Tup[i]; }
return *
this; }
289 if (
Len()!=Tup.
Len()) {
return false; }
if (&Tup==
this) {
return true; }
290 for (
int i=0; i<
Len(); i++)
if(
ValV[i]!=Tup[i]){
return false;}
return true; }
292 if (
Len() == Tup.
Len()) {
for (
int i=0; i<
Len(); i++) {
293 if(
ValV[i]<Tup[i]){
return true;}
else if(
ValV[i]>Tup[i]){
return false;} }
return false; }
294 else {
return Len() < Tup.
Len(); } }
295 void Sort(
const bool& Asc=
true);
307 for (
int i=0; i<
Len(); i++) { ValsStr+=
" "+
ValV[i].GetStr(); }
311 template<
class TVal,
int NVals>
314 for (
int i=0; i<NVals; i++) { V.
Add(ValV[i]); }
316 for (
int i=0; i<NVals; i++) { ValV[i] = V[i]; }
319 template<
class TVal,
int NVals>
321 TVal MxVal = ValV[0];
323 for (
int i = 1; i < NVals; i++) {
325 MxVal=ValV[i]; ValN=i;
331 template<
class TVal,
int NVals>
333 TVal MnVal = ValV[0];
335 for (
int i = 1; i < NVals; i++) {
337 MnVal=ValV[i]; ValN=i;
345 template <
class TKey,
class TDat>
361 if (
this!=&KeyDat){
Key=KeyDat.
Key;
Dat=KeyDat.
Dat;}
return *
this;}
369 template <
class TKey,
class TDat>
371 const int Kds=SrcKdV.Len();
373 for (
int KdN=0; KdN<Kds; KdN++){
409 template <
class TVal1,
class TVal2>
429 template <
class TVal,
class TSizeTy =
int>
438 void Resize(
const TSizeTy& _MxVals=-1);
446 explicit TVec(
const TSizeTy& _Vals){
449 if (_Vals==0){
ValT=NULL;}
else {
ValT=
new TVal[_Vals];}}
451 TVec(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
454 if (_MxVals==0){
ValT=NULL;}
else {
ValT=
new TVal[_MxVals];}}
459 explicit TVec(TVal *_ValT,
const TSizeTy& _Vals):
471 template <
typename TLoadShMElem>
480 for (TSizeTy ValN=0; ValN<
Vals; ValN++) {
481 LoadFromShMFn(
ValT+ValN, ShMIn);
501 bool operator<(const TVec<TVal, TSizeTy>& Vec)
const;
512 return TSizeTy(2*
sizeof(TSizeTy)+
sizeof(TVal*)+
MxVals*
sizeof(TVal));}
515 return TSizeTy(2*
sizeof(TVal)+
sizeof(TSizeTy)*
Vals);}
527 void Gen(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
IAssert((0<=_Vals)&&(_Vals<=_MxVals));
529 if (_MxVals==0){
ValT=NULL;}
else {
ValT=
new TVal[_MxVals];}}
534 void GenExt(TVal *_ValT,
const TSizeTy& _Vals){
550 void Clr(
const bool& DoDel=
true,
const TSizeTy& NoDelLim=-1);
554 void Trunc(
const TSizeTy& _Vals=-1);
602 TSizeTy
Add(){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
608 TSizeTy
Add(
const TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
610 TSizeTy
Add(TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
613 TSizeTy
Add(
const TVal& Val,
const TSizeTy& ResizeLen){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
616 TSizeTy
AddMP(
const TVal& Val){
const int Idx = __sync_fetch_and_add(&
Vals, 1);
618 ValT[Idx]=Val;
return Idx;}
622 TSizeTy
MoveLastMP(
const TVal& Val,
int Inc){
const int Idx = __sync_fetch_and_add(&
Vals, Inc);
630 TSizeTy
AddSorted(
const TVal& Val,
const bool& Asc=
true,
const TSizeTy& _MxVals=-1);
653 void SetVal(
const TSizeTy& ValN,
const TVal& Val){
659 void Ins(
const TSizeTy& ValN,
const TVal& Val);
661 void Del(
const TSizeTy& ValN);
663 void Del(
const TSizeTy& MnValN,
const TSizeTy& MxValN);
669 void DelAll(
const TVal& Val);
671 void PutAll(
const TVal& Val);
677 static void SwapI(
TIter LVal,
TIter RVal){
const TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
692 TSizeTy
GetPivotValN(
const TSizeTy& LValN,
const TSizeTy& RValN)
const;
696 void BSort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
700 void ISort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
705 TSizeTy
Partition(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
710 void QSort(
const TSizeTy& MnLValN,
const TSizeTy& MxRValN,
const bool& Asc);
715 void Sort(
const bool& Asc=
true);
717 bool IsSorted(
const bool& Asc=
true)
const;
723 void Reverse(TSizeTy LValN, TSizeTy RValN){
Assert(LValN>=0 && RValN<
Len());
while (LValN < RValN){
Swap(LValN++, RValN--);} }
728 template <
class TCmp>
730 TSizeTy SubVals=TSizeTy(EI-BI);
if (SubVals >
TInt::Mx-1) { SubVals =
TInt::Mx-1; }
732 const TVal& Val1 = *(BI+ValN1);
const TVal& Val2 = *(BI+ValN2);
const TVal& Val3 = *(BI+ValN3);
733 if (
Cmp(Val1, Val2)) {
734 if (
Cmp(Val2, Val3))
return BI+ValN2;
735 else if (
Cmp(Val3, Val1))
return BI+ValN1;
736 else return BI+ValN3;
738 if (
Cmp(Val1, Val3))
return BI+ValN1;
739 else if (
Cmp(Val3, Val2))
return BI+ValN2;
740 else return BI+ValN3; } }
742 template <
class TCmp>
745 while (
Cmp(*BI, Pivot)){++BI;} --EI;
746 while (
Cmp(Pivot, *EI)){--EI;}
747 if (!(BI<EI)){
return BI;}
SwapI(BI, EI); ++BI; } }
749 template <
class TCmp>
751 for (
TIter i = BI; i != EI; ++i) {
752 for (
TIter j = EI-1; j != i; --j) {
753 if (
Cmp(*j, *(j-1))) {
SwapI(j, j-1); } } } }
755 template <
class TCmp>
758 for (
TIter i = BI, j; i != EI; ++i) { TVal Tmp=*i; j=i;
759 while (j > BI &&
Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; } *j=Tmp; } } }
761 template <
class TCmp>
764 if (EI - BI < 20) {
ISortCmp(BI, EI, Cmp); }
769 template <
class TCmp>
772 template <
class TCmp>
776 if (
Cmp(*(i+1), *i)){
return false;} }
return true; }
799 TSizeTy
Count(
const TVal& Val)
const;
804 TSizeTy
SearchBin(
const TVal& Val)
const;
808 TSizeTy
SearchBin(
const TVal& Val, TSizeTy& InsValN)
const;
812 TSizeTy
SearchBinLeft(
const TVal& Val, TSizeTy& InsValN)
const;
817 TSizeTy
SearchForw(
const TVal& Val,
const TSizeTy& BValN=0)
const;
832 bool IsIn(
const TVal& Val, TSizeTy& ValN)
const { ValN=
SearchForw(Val);
return ValN!=-1;}
842 TVal&
GetAddDat(
const TVal& Val){
AssertR(
MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
863 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6){
866 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7){
869 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7,
const TVal& Val8){
872 static TVec<TVal, TSizeTy> GetV(
const TVal& Val1,
const TVal& Val2,
const TVal& Val3,
const TVal& Val4,
const TVal& Val5,
const TVal& Val6,
const TVal& Val7,
const TVal& Val8,
const TVal& Val9){
876 template <
class TVal,
class TSizeTy>
878 IAssertR(MxVals!=-1 || IsShM,
TStr::Fmt(
"Can not increase the capacity of the vector. %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
GetTypeNm(*this).
CStr()).CStr());
879 IAssertR(MxVals!=(
TInt::Mx-1024),
TStr::Fmt(
"Buffer size at maximum. %s. [Program refuses to allocate more memory. Solution-1: Send your test case to developers.]",
GetTypeNm(*this).
CStr()).CStr());
880 TSizeTy OldMxVals = MxVals;
881 if (MxVals == -1) {MxVals = Vals;}
883 if (Vals==0){MxVals=16;}
else {MxVals*=2;}
885 if (_MxVals<=MxVals){
return;}
else {MxVals=_MxVals;}
892 ValT=
new TVal[MxVals];
894 catch (std::exception Ex){
895 FailR(
TStr::Fmt(
"TVec::Resize: %s, Length:%s, Capacity:%s, New capacity:%s, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]",
898 TVal* NewValT = NULL;
900 NewValT=
new TVal[MxVals];
902 catch (std::exception Ex){
903 FailR(
TStr::Fmt(
"TVec::Resize: %s, Length:%s, Capacity:%s, New capacity:%s, Type:%s [Program failed to allocate more memory. Solution-1: Get a bigger machine and a 64-bit compiler.]",
906 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
907 if (OldMxVals != -1) {
delete[] ValT;} ValT=NewValT;
912 template <
class TVal,
class TSizeTy>
921 template <
class TVal,
class TSizeTy>
925 if (MxVals==0) {ValT=NULL;}
else {ValT=
new TVal[MxVals];}
926 for (TSizeTy ValN=0; ValN<Vec.
Vals; ValN++){ValT[ValN]=Vec.
ValT[ValN];}
931 template <
class TVal,
class TSizeTy>
933 if ((ValT!=NULL) && (MxVals!=-1)) {
delete[] ValT;}
945 template <
class TVal,
class TSizeTy>
947 if ( (ValT!=NULL) && (MxVals!=-1)) {
delete[] ValT;}
948 SIn.
Load(MxVals); SIn.
Load(Vals); MxVals=Vals;
949 if ( MxVals==0 ){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
950 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=TVal(SIn);}
953 template <
class TVal,
class TSizeTy>
955 if (MxVals!=-1){SOut.
Save(MxVals);}
else {SOut.
Save(Vals);}
957 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
960 template <
class TVal,
class TSizeTy>
963 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
964 MxVals=Vals=Vec.
Vals;
965 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[MxVals];}
966 for (TSizeTy ValN=0; ValN<Vec.
Vals; ValN++){ValT[ValN]=Vec.
ValT[ValN];}
971 template <
class TVal,
class TSizeTy>
973 if (
this==&Vec){
return true;}
974 if (Len()!=Vec.
Len()){
return false;}
975 for (TSizeTy ValN=0; ValN<Vals; ValN++){
976 if (ValT[ValN]!=Vec.
ValT[ValN]){
return false;}}
980 template <
class TVal,
class TSizeTy>
982 if (
this==&Vec){
return false;}
983 if (Len()==Vec.
Len()){
984 for (TSizeTy ValN=0; ValN<Vals; ValN++){
985 if (ValT[ValN]<Vec.
ValT[ValN]){
return true;}
986 else if (ValT[ValN]>Vec.
ValT[ValN]){
return false;}
991 return Len()<Vec.
Len();
998 template <
class TVal,
class TSizeTy>
1001 for (TSizeTy i=0; i<Vals; i++){
1010 template <
class TVal,
class TSizeTy>
1013 for (TSizeTy i=0; i<Vals; i++){
1021 template <
class TVal,
class TSizeTy>
1023 if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){
1024 if ((ValT!=NULL)&&(MxVals!=-1)){
delete[] ValT;}
1025 MxVals=Vals=0; ValT=NULL;
1027 IAssertR(MxVals!=-1 || IsShM,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1032 template <
class TVal,
class TSizeTy>
1034 EAssertR(!(MxVals==-1 && IsShM),
"Cannot truncate a shared memory vector");
1035 IAssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1036 IAssert((_Vals==-1)||(_Vals>=0));
1037 if ((_Vals!=-1)&&(_Vals>=Vals)){
1040 if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){
1041 if (ValT!=NULL){
delete[] ValT;}
1042 MxVals=Vals=0; ValT=NULL;
1045 if (MxVals==Vals){
return;}
else {MxVals=Vals;}
1049 TVal* NewValT=
new TVal[MxVals];
1051 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1052 delete[] ValT; ValT=NewValT;
1056 template <
class TVal,
class TSizeTy>
1058 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot pack accessed shared memory");
1059 IAssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1061 if (ValT!=NULL){
delete[] ValT;} ValT=NULL;
1065 TVal* NewValT=
new TVal[MxVals];
1067 for (TSizeTy ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1068 delete[] ValT; ValT=NewValT;
1072 template <
class TVal,
class TSizeTy>
1075 if (ValT!=NULL && MxVals!=-1){
delete[] ValT;}
1081 template <
class TVal,
class TSizeTy>
1083 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1085 if (ValT!=NULL && MxVals!=-1 && MxVals < Sz){
1089 if (Sz == 0) { Vals = 0;
return; }
1090 ValT[0] = Vec.
ValT[Offset];
1092 for (TSizeTy ValN=1; ValN<Sz; ValN++){
1093 if (ValT[Vals-1] != Vec.
ValT[Offset+ValN]) {
1094 ValT[Vals++] = Vec.
ValT[Offset+ValN];
1100 template <
class TVal,
class TSizeTy>
1109 template <
class TVal,
class TSizeTy>
1111 AssertR(MxVals!=-1 || IsShM,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1112 for (TSizeTy ValN=0; ValN<ValV.
Vals; ValN++){Add(ValV[ValN]);}
1116 template <
class TVal,
class TSizeTy>
1118 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1119 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1120 TSizeTy ValN=Add(Val);
1122 while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){
1123 Swap(ValN, ValN-1); ValN--;}
1125 while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){
1126 Swap(ValN, ValN-1); ValN--;}
1128 if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);}
1132 template <
class TVal,
class TSizeTy>
1134 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1135 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1137 TSizeTy ValN=Vals-2;
1138 while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
1139 ValT[ValN+1]=ValT[ValN]; ValN--;}
1144 template <
class TVal,
class TSizeTy>
1146 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1147 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1148 TSizeTy ValN=SearchBin(Val);
1149 if (ValN==-1){
return AddSorted(Val);}
1150 else {GetVal(ValN)=Val;
return -1;}
1153 template <
class TVal,
class TSizeTy>
1155 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1156 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1157 for (TSizeTy ValN=0; ValN<ValV.
Vals; ValN++){AddMerged(ValV[ValN]);}
1161 template <
class TVal,
class TSizeTy>
1163 AssertR(MxVals!=-1 || IsShM,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1164 TSizeTy ValN=SearchForw(Val);
1165 if (ValN==-1){
return Add(Val);}
1166 else {GetVal(ValN)=Val;
return -1;}
1169 template <
class TVal,
class TSizeTy>
1173 const TSizeTy SubVals=
TInt::GetMx(0, EValN-BValN+1);
1174 SubValV.
Gen(SubVals, 0);
1175 for (TSizeTy ValN=BValN; ValN<=EValN; ValN++){
1176 SubValV.
Add(GetVal(ValN));}
1179 template <
class TVal,
class TSizeTy>
1181 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1182 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1183 Add();
Assert((0<=ValN)&&(ValN<Vals));
1184 for (TSizeTy MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
1188 template <
class TVal,
class TSizeTy>
1190 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1191 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1192 Assert((0<=ValN)&&(ValN<Vals));
1193 for (TSizeTy MValN=ValN+1; MValN<Vals; MValN++){
1194 ValT[MValN-1]=ValT[MValN];}
1195 ValT[--Vals]=TVal();
1198 template <
class TVal,
class TSizeTy>
1200 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1201 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1202 Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
1204 for (TSizeTy ValN=MxValN+1; ValN<Vals; ValN++){
1205 ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
1206 for (TSizeTy ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
1208 Vals-=MxValN-MnValN+1;
1211 template <
class TVal,
class TSizeTy>
1213 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1214 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1215 TSizeTy ValN=SearchForw(Val);
1216 if (ValN!=-1){Del(ValN);
return true;}
1217 else {
return false;}
1220 template <
class TVal,
class TSizeTy>
1222 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1223 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1225 while ((ValN=SearchForw(Val))!=-1){Del(ValN);}
1228 template <
class TVal,
class TSizeTy>
1230 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1231 for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
1234 template <
class TVal,
class TSizeTy>
1236 for (TSizeTy ValN1=MnLValN; ValN1<=MxRValN; ValN1++){
1237 for (TSizeTy ValN2=MxRValN; ValN2>ValN1; ValN2--){
1239 if (ValT[ValN2]<ValT[ValN2-1]){
Swap(ValN2, ValN2-1);}
1241 if (ValT[ValN2]>ValT[ValN2-1]){
Swap(ValN2, ValN2-1);}
1247 template <
class TVal,
class TSizeTy>
1249 if (MnLValN<MxRValN){
1250 for (TSizeTy ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){
1251 TVal Val=ValT[ValN1]; TSizeTy ValN2=ValN1;
1253 while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){
1254 ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1256 while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){
1257 ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
1264 template <
class TVal,
class TSizeTy>
1266 TSizeTy SubVals=RValN-LValN+1;
1271 const TVal& Val1=ValT[ValN1];
1272 const TVal& Val2=ValT[ValN2];
1273 const TVal& Val3=ValT[ValN3];
1275 if (Val2<Val3){
return ValN2;}
1276 else if (Val3<Val1){
return ValN1;}
1277 else {
return ValN3;}
1279 if (Val1<Val3){
return ValN1;}
1280 else if (Val3<Val2){
return ValN2;}
1281 else {
return ValN3;}
1285 template <
class TVal,
class TSizeTy>
1287 TSizeTy PivotValN=GetPivotValN(MnLValN, MxRValN);
1288 Swap(PivotValN, MnLValN);
1289 TVal PivotVal=ValT[MnLValN];
1290 TSizeTy LValN=MnLValN-1; TSizeTy RValN=MxRValN+1;
1293 do {RValN--;}
while (ValT[RValN]>PivotVal);
1294 do {LValN++;}
while (ValT[LValN]<PivotVal);
1296 do {RValN--;}
while (ValT[RValN]<PivotVal);
1297 do {LValN++;}
while (ValT[LValN]>PivotVal);
1299 if (LValN<RValN){
Swap(LValN, RValN);}
1300 else {
return RValN;}
1304 template <
class TVal,
class TSizeTy>
1306 if (MnLValN<MxRValN){
1307 if (MxRValN-MnLValN<20){
1308 ISort(MnLValN, MxRValN, Asc);
1310 TSizeTy SplitValN=Partition(MnLValN, MxRValN, Asc);
1311 QSort(MnLValN, SplitValN, Asc);
1312 QSort(SplitValN+1, MxRValN, Asc);
1317 template <
class TVal,
class TSizeTy>
1319 QSort(0, Len()-1, Asc);
1322 template <
class TVal,
class TSizeTy>
1325 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1326 if (ValT[ValN]>ValT[ValN+1]){
return false;}}
1328 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1329 if (ValT[ValN]<ValT[ValN+1]){
return false;}}
1334 template <
class TVal,
class TSizeTy>
1337 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1338 const int Range = int(Vals-ValN);
1342 for (TSizeTy ValN=0; ValN<Vals-1; ValN++){
1343 const TSizeTy Range = Vals-ValN;
1349 template <
class TVal,
class TSizeTy>
1351 for (TSizeTy ValN=0; ValN<Vals/2; ValN++){
1352 Swap(ValN, Vals-ValN-1);}
1355 template <
class TVal,
class TSizeTy>
1357 IAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
1358 AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
1361 for (TSizeTy ValN=0; ValN<SortedVec.
Len(); ValN++){
1362 if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){
1363 Add(SortedVec[ValN]);}
1367 template <
class TVal,
class TSizeTy>
1370 TSizeTy First = 0, Last = Len(), Next = Len()-1;
1371 if (Last < 2)
return false;
1374 TSizeTy Next1 = Next;
1375 if (GetVal(--Next) < GetVal(Next1)) {
1377 for (; GetVal(Next) >= GetVal(--Mid); ) { }
1379 Reverse(Next1, Last-1);
1382 if (Next == First) {
1389 template <
class TVal,
class TSizeTy>
1391 TSizeTy First = 0, Last = Len(), Next = Len()-1;
1392 if (Last < 2)
return false;
1395 TSizeTy Next1 = Next;
1396 if (GetVal(--Next) >= GetVal(Next1)) {
1398 for (; GetVal(Next) < GetVal(--Mid); ) { }
1400 Reverse(Next1, Last);
1403 if (Next == First) {
1410 template <
class TVal,
class TSizeTy>
1413 Intrs(ValV, IntrsVec);
1417 template <
class TVal,
class TSizeTy>
1420 Union(ValV, UnionVec);
1424 template <
class TVal,
class TSizeTy>
1427 Diff(ValV, DiffVec);
1431 template <
class TVal,
class TSizeTy>
1434 TSizeTy ValN1=0, ValN2=0;
1435 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1436 const TVal& Val1=GetVal(ValN1);
1437 while ((ValN2<ValV.
Len())&&(Val1>ValV.
GetVal(ValN2))){
1439 if ((ValN2<ValV.
Len())&&(Val1==ValV.
GetVal(ValN2))){
1440 DstValV.
Add(Val1); ValN2++;}
1445 template <
class TVal,
class TSizeTy>
1448 TSizeTy ValN1=0, ValN2=0;
1449 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1450 const TVal& Val1=GetVal(ValN1);
1451 const TVal& Val2=ValV.
GetVal(ValN2);
1452 if (Val1<Val2){DstValV.
Add(Val1); ValN1++;}
1453 else if (Val1>Val2){DstValV.
Add(Val2); ValN2++;}
1454 else {DstValV.
Add(Val1); ValN1++; ValN2++;}
1456 for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1457 DstValV.
Add(GetVal(RestValN1));}
1458 for (TSizeTy RestValN2=ValN2; RestValN2<ValV.
Len(); RestValN2++){
1462 template <
class TVal,
class TSizeTy>
1465 TSizeTy ValN1=0, ValN2=0;
1466 while (ValN1<Len() && ValN2<ValV.
Len()) {
1467 const TVal& Val1 = GetVal(ValN1);
1468 while (ValN2<ValV.
Len() && Val1>ValV.
GetVal(ValN2)) ValN2++;
1469 if (ValN2<ValV.
Len()) {
1470 if (Val1!=ValV.
GetVal(ValN2)) { DstValV.
Add(Val1); }
1474 for (TSizeTy RestValN1=ValN1; RestValN1<Len(); RestValN1++){
1475 DstValV.
Add(GetVal(RestValN1));}
1478 template <
class TVal,
class TSizeTy>
1480 TSizeTy Cnt=0, ValN1=0, ValN2=0;
1481 while ((ValN1<Len())&&(ValN2<ValV.
Len())){
1482 const TVal& Val1=GetVal(ValN1);
1483 while ((ValN2<ValV.
Len())&&(Val1>ValV.
GetVal(ValN2))){
1485 if ((ValN2<ValV.
Len())&&(Val1==ValV.
GetVal(ValN2))){
1492 template <
class TVal,
class TSizeTy>
1494 TSizeTy Cnt = 0, ValN1 = 0, ValN2 = 0;
1495 while ((ValN1 < Len()) && (ValN2 < ValV.
Len())) {
1496 const TVal& Val1 = GetVal(ValN1);
1497 const TVal& Val2 = ValV.
GetVal(ValN2);
1500 }
else if (Val1 > Val2) {
1503 Cnt++; ValN1++; ValN2++;
1506 Cnt += (Len() - ValN1) + (ValV.
Len() - ValN2);
1510 template <
class TVal,
class TSizeTy>
1513 for (TSizeTy i = 0; i < Len(); i++){
1514 if (Val == ValT[i]){Count++;}}
1518 template <
class TVal,
class TSizeTy>
1520 TSizeTy LValN=0, RValN=Len()-1;
1521 while (RValN>=LValN){
1522 TSizeTy ValN=(LValN+RValN)/2;
1523 if (Val==ValT[ValN]){
return ValN;}
1524 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
1529 template <
class TVal,
class TSizeTy>
1531 TSizeTy LValN=0, RValN=Len()-1;
1532 while (RValN>=LValN){
1533 TSizeTy ValN=(LValN+RValN)/2;
1534 if (Val==ValT[ValN]){InsValN=ValN;
return ValN;}
1535 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
1537 InsValN=LValN;
return -1;
1540 template <
class TVal,
class TSizeTy>
1542 TSizeTy LValN=0, RValN=Len()-1;
1543 while (RValN>=LValN){
1544 TSizeTy ValN=(LValN+RValN)/2;
1545 if (Val==ValT[ValN]){InsValN=ValN;
return ValN;}
1546 if (Val<ValT[ValN]){RValN=ValN-1;}
else {LValN=ValN+1;}
1548 InsValN=RValN;
return -1;
1551 template <
class TVal,
class TSizeTy>
1553 for (TSizeTy ValN=BValN; ValN<Vals; ValN++){
1554 if (Val==ValT[ValN]){
return ValN;}}
1558 template <
class TVal,
class TSizeTy>
1560 for (TSizeTy ValN=Vals-1; ValN>=0; ValN--){
1561 if (Val==ValT[ValN]){
return ValN;}}
1565 template <
class TVal,
class TSizeTy>
1567 TSizeTy ValVLen=ValV.
Len();
1568 for (TSizeTy ValN=BValN; ValN<Vals-ValVLen+1; ValN++){
1570 for (TSizeTy SubValN=0; SubValN<ValVLen; SubValN++){
1571 if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=
false;
break;}
1573 if (Found){
return ValN;}
1578 template <
class TVal,
class TSizeTy>
1580 if (Vals==0){
return -1;}
1582 for (TSizeTy ValN=1; ValN<Vals; ValN++){
1583 if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
1671 template <
class TVal,
class TSizeTy=
int>
1692 TVecPool(
const TSize& ExpectVals=0,
const TSize& _GrowBy=1000000,
const bool& _FastCopy=
false,
const TVal& _EmptyVal=TVal());
1745 for (::
TSize ValN=0; ValN <
::TSize(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1769 template <
class TVal,
class TSizeTy>
1771 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
1772 if (ValBf == NULL) {
1773 try { ValBf =
new TVal [MxVals]; }
1774 catch (std::exception Ex) {
1775 FailR(
TStr::Fmt(
"TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(),
TInt::GetStr(
uint64(_MxVals)).
CStr()).CStr()); }
1777 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1780 TVal* NewValBf = NULL;
1781 try { NewValBf =
new TVal [MxVals]; }
1782 catch (std::exception Ex) {
1783 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()); }
1786 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
1788 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1789 if (EmptyVal != TVal()) {
1790 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1797 template <
class TVal,
class TSizeTy>
1803 template <
class TVal,
class TSizeTy>
1807 catch (std::exception Ex) {
1816 template <
class TVal,
class TSizeTy>
1818 uint64 _GrowBy, _MxVals, _Vals;
1824 for (
TSize ValN = 0; ValN <
Vals; ValN++) {
ValBf[ValN] = TVal(SIn); }
1827 for (
int ValN = 0; ValN <
Vals; ValN++) {
1833 template <
class TVal,
class TSizeTy>
1835 SOut.
Save(FastCopy);
1836 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1837 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
1838 SOut.
Save(EmptyVal);
1839 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1840 { SOut.
Save(IdToOffV.Len()); SOut.
Save(IdToOffV.Len());
1841 for (
int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
1842 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
1846 template <
class TVal,
class TSizeTy>
1856 ValBf =
new TVal [MxVals]; }
1857 catch (std::exception Ex) {
1858 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()); }
1861 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
1863 for (
TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
1868 template <
class TVal,
class TSizeTy>
1871 if (ValVLen == 0) {
return 0; }
1872 if (MxVals < Vals+ValVLen) { Resize(Vals+
MAX(ValVLen, GrowBy)); }
1873 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
1874 else {
for (
TSize ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1875 Vals+=ValVLen; IdToOffV.
Add(Vals);
1876 return IdToOffV.Len()-1;
1879 template <
class TVal,
class TSizeTy>
1881 if (ValVLen==0){
return 0;}
1882 if (MxVals < Vals+ValVLen){Resize(Vals+
MAX(
TSize(ValVLen), GrowBy)); }
1883 Vals+=ValVLen; IdToOffV.Add(Vals);
1884 return IdToOffV.Len()-1;
1888 template <
class TVal,
class TSizeTy>
1892 for (
int vid = 1; vid < IdToOffV.Len(); vid++) {
1894 const uint Len = GetVLen(vid);
1895 TVal* ValV = GetValVPt(vid);
1896 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
1897 if (Len == 0) {
continue; }
1899 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
1902 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
1903 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
1907 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
1910 IdToOffV.Last() -= TotalDel;
1911 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
1917 template <
class TVal,
class TSizeTy>
1919 for (::
TSize n = Vals-1; n > 0; n--) {
1921 const TVal Tmp = ValBf[n];
1922 ValBf[n] = ValBf[k];
1934 namespace TGLib_OLD {
1937 template<
class TVal>
1977 if (VId==0){
return 0;}
1990 for (
uint ValN=0; ValN <
uint(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
2009 template <
class TVal>
2011 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
2012 if (ValBf == NULL) {
2013 try { ValBf =
new TVal [MxVals]; }
2014 catch (std::exception Ex) {
2015 FailR(
TStr::Fmt(
"TVecPool::Resize 1: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
2017 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
2020 TVal* NewValBf = NULL;
2021 try { NewValBf =
new TVal [MxVals]; }
2022 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()); }
2025 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
2027 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
2028 if (EmptyVal != TVal()) {
2029 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
2036 template <
class TVal>
2038 GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
2043 template <
class TVal>
2045 FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy),
2046 MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
2048 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVecPool::TVecPool: %s, MxVals: %d", Ex.what(),
MxVals).CStr()); }
2056 template <
class TVal>
2059 uint64 _GrowBy, _MxVals, _Vals;
2065 for (
TSize ValN = 0; ValN <
Vals; ValN++) {
ValBf[ValN] = TVal(SIn); }
2068 for (
int ValN = 0; ValN <
Vals; ValN++) {
2074 template <
class TVal>
2076 SOut.
Save(FastCopy);
2077 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2078 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
2079 SOut.
Save(EmptyVal);
2080 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2081 { SOut.
Save(IdToOffV.Len()); SOut.
Save(IdToOffV.Len());
2082 for (
int ValN = 0; ValN < IdToOffV.Len(); ValN++) {
2083 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
2087 template <
class TVal>
2096 try { ValBf =
new TVal [MxVals]; }
2097 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVec::operator= : %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
2100 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
2102 for (
uint64 ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
2107 template<
class TVal>
2110 if (ValVLen == 0) {
return 0; }
2111 if (MxVals < Vals+ValVLen) { Resize(Vals+
MAX(ValVLen, GrowBy)); }
2112 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
2113 else {
for (
uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2114 Vals+=ValVLen; IdToOffV.
Add(Vals);
2115 return IdToOffV.Len()-1;
2118 template<
class TVal>
2120 if (ValVLen==0){
return 0;}
2121 if (MxVals < Vals+ValVLen){Resize(Vals+
MAX(
TSize(ValVLen), GrowBy)); }
2122 Vals+=ValVLen; IdToOffV.Add(Vals);
2123 return IdToOffV.Len()-1;
2128 template<
class TVal>
2132 for (
int vid = 1; vid < IdToOffV.Len(); vid++) {
2134 const uint Len = GetVLen(vid);
2135 TVal* ValV = GetValVPt(vid);
2136 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
2137 if (Len == 0) {
continue; }
2139 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
2142 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
2143 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
2147 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
2150 IdToOffV.Last() -= TotalDel;
2151 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
2157 template<
class TVal>
2159 for (::
TSize n = Vals-1; n > 0; n--) {
2161 const TVal Tmp = ValBf[n];
2162 ValBf[n] = ValBf[k];
2174 template <
class TVal>
2196 if (
this!=&Vec){
V=Vec.
V;}
return *
this;}
2198 bool operator<(const PVec<TVal>& Vec)
const {
return V<Vec.V;}
2203 TVal
GetVal(
const int& ValN)
const {
return V[ValN];}
2221 template <
class TVal,
class TSizeTy =
int>
2230 TVVec(
const TSizeTy& _XDim,
const TSizeTy& _YDim):
2246 void Gen(
const TSizeTy& _XDim,
const TSizeTy& _YDim){
2247 Assert((_XDim>=0)&&(_YDim>=0));
2255 const TVal&
At(
const TSizeTy& X,
const TSizeTy& Y)
const {
2258 TVal&
At(
const TSizeTy& X,
const TSizeTy& Y){
2263 const TVal&
operator()(
const TSizeTy& X,
const TSizeTy& Y)
const {
2266 void PutXY(
const TSizeTy& X,
const TSizeTy& Y,
const TVal& Val){
At(X, Y)=Val;}
2268 void PutX(
const TSizeTy& X,
const TVal& Val){
2269 for (TSizeTy Y=0; Y<TSizeTy(
YDim); Y++){
At(X, Y)=Val;}}
2270 void PutY(
const TSizeTy& Y,
const TVal& Val){
2271 for (TSizeTy X=0; X<TSizeTy(
XDim); X++){
At(X, Y)=Val;}}
2272 TVal
GetXY(
const TSizeTy& X,
const TSizeTy& Y)
const {
2278 void SwapX(
const TSizeTy& X1,
const TSizeTy& X2);
2279 void SwapY(
const TSizeTy& Y1,
const TSizeTy& Y2);
2284 void GetMxValXY(TSizeTy& X, TSizeTy& Y)
const;
2289 void DelX(
const TSizeTy& X);
2290 void DelY(
const TSizeTy& Y);
2293 template <
class TVal,
class TSizeTy>
2295 for (TSizeTy Y=0; Y<TSizeTy(YDim); Y++){
2296 TVal Val=At(X1, Y); At(X1, Y)=At(X2, Y); At(X2, Y)=Val;}
2299 template <
class TVal,
class TSizeTy>
2301 for (TSizeTy X=0; X<TSizeTy(XDim); X++){
2302 TVal Val=At(X, Y1); At(X, Y1)=At(X, Y2); At(X, Y2)=Val;}
2305 template <
class TVal,
class TSizeTy>
2310 ValV.Swap(Vec.
ValV);
2314 template <
class TVal,
class TSizeTy>
2316 for (TSizeTy X=0; X<XDim-1; X++){SwapX(X, X+Rnd.
GetUniDevInt(XDim-X));}
2319 template <
class TVal,
class TSizeTy>
2321 for (TSizeTy Y=0; Y<YDim-1; Y++){SwapY(Y, Y+Rnd.
GetUniDevInt(YDim-Y));}
2324 template <
class TVal,
class TSizeTy>
2326 TSizeTy MxValN=ValV.GetMxValN();
2331 template <
class TVal,
class TSizeTy>
2333 TSizeTy CopyXDim = (GetXDim() < VVec.
GetXDim()) ? GetXDim() : VVec.
GetXDim();
2334 TSizeTy CopyYDim = (GetYDim() < VVec.
GetYDim()) ? GetYDim() : VVec.
GetYDim();
2335 for (TSizeTy X=0; X<CopyXDim; X++){
2336 for (TSizeTy Y=0; Y<CopyYDim; Y++){
2337 At(X, Y)=VVec.
At(X, Y);
2342 template <
class TVal,
class TSizeTy>
2349 template <
class TVal,
class TSizeTy>
2356 template <
class TVal,
class TSizeTy>
2359 for (TSizeTy Y=0; Y<YDim; Y++){
2360 for (TSizeTy LX=0; LX<X; LX++){
2361 NewVVec.
At(LX, Y)=At(LX, Y);}
2362 for (TSizeTy RX=X+1; RX<XDim; RX++){
2363 NewVVec.
At(RX-1, Y)=At(RX, Y);}
2368 template <
class TVal,
class TSizeTy>
2371 for (TSizeTy X=0; X<XDim; X++){
2372 for (TSizeTy LY=0; LY<Y; LY++){
2373 NewVVec.
At(X, LY)=At(X, LY);}
2374 for (TSizeTy RY=Y+1; RY<YDim; RY++){
2375 NewVVec.
At(X, RY-1)=At(X, RY);}
2380 template <
class TVal,
class TSizeTy >
2382 Vec.
Gen(GetCols(), 0);
2383 for (TSizeTy col = 0; col < GetCols(); col++) {
2384 Vec.
Add(At(RowN, col));
2388 template <
class TVal,
class TSizeTy>
2390 Vec.
Gen(GetRows(), 0);
2391 for (TSizeTy row = 0; row < GetRows(); row++) {
2392 Vec.
Add(At(row, ColN));
2408 template <
class TVal,
class TSizeTy =
int>
2417 TVVVec(
const TSizeTy& _XDim,
const TSizeTy& _YDim,
const TSizeTy& _ZDim):
2434 void Gen(
const TSizeTy& _XDim,
const TSizeTy& _YDim,
const TSizeTy& _ZDim){
2435 Assert((_XDim>=0)&&(_YDim>=0)&&(_ZDim>=0));
2437 TVal&
At(
const TSizeTy& X,
const TSizeTy& Y,
const TSizeTy& Z){
2438 Assert((0<=X)&&(X<TSizeTy(
XDim))&&(0<=Y)&&(Y<TSizeTy(
YDim))&&(0<=Z)&&(Z<TSizeTy(
ZDim)));
2440 const TVal&
At(
const TSizeTy& X,
const TSizeTy& Y,
const TSizeTy& Z)
const {
2441 Assert((0<=X)&&(X<TSizeTy(
XDim))&&(0<=Y)&&(Y<TSizeTy(
YDim))&&(0<=Z)&&(Z<TSizeTy(
ZDim)));
2443 TVal&
operator()(
const TSizeTy& X,
const TSizeTy& Y,
const TSizeTy& Z){
2444 return At(X, Y, Z);}
2445 const TVal&
operator()(
const TSizeTy& X,
const TSizeTy& Y,
const TSizeTy& Z)
const {
2446 return At(X, Y, Z);}
2459 template <
class TVal>
2482 int AddNode(
const int& ParentNodeId,
const TVal& NodeVal=TVal()){
2484 if (ParentNodeId!=-1){
NodeV[ParentNodeId].Val2.Add(
NodeV.Len());}
2498 void DelNode(
const int& NodeId);
2499 void CopyTree(
const int& SrcNodeId,
TTree& DstTree,
const int& DstParentNodeId=-1);
2501 void WrTree(
const int& NodeId=0,
const int& Lev=0);
2504 template <
class TVal>
2506 if (NodeId==0){NodeIdV.
Clr();
if (GetNodes()==0){
return;}}
2507 else if (GetParentNodeId(NodeId)==-1){
return;}
2508 NodeIdV.
Add(NodeId);
2509 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2510 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2511 if (ChildNodeId!=-1){
2512 GetNodeIdV(NodeIdV, ChildNodeId);
2517 template <
class TVal>
2522 for (
int NodeN=1; NodeN<Nodes; NodeN++){
2524 AddNode(ParentNodeId, TVal());
2529 template <
class TVal>
2534 TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2535 int ChildNodeIdN=ChildNodeIdV.
SearchForw(NodeId);
2536 ChildNodeIdV[ChildNodeIdN]=-1;
2540 template <
class TVal>
2542 int DstNodeId=DstTree.
AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
2543 for (
int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
2544 int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
2545 if (ChildNodeId!=-1){
2546 CopyTree(ChildNodeId, DstTree, DstNodeId);
2551 template <
class TVal>
2553 for (
int LevN=0; LevN<Lev; LevN++){printf(
"| ");}
2554 printf(
"%d (%d)\n", NodeId, GetChildren(NodeId));
2555 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2556 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2557 if (ChildNodeId!=-1){
2558 WrTree(ChildNodeId, Lev+1);
2573 template <
class TVal>
2585 if (
this!=&Stack){
ValV=Stack.
ValV;}
return *
this;}
2608 template <
class TVal>
2615 TQQueue(
const int& _MxLast=64,
const int& _MxLen=-1):
2635 void Gen(
const int& _MxLast=64,
const int& _MxLen=-1){
2640 SubValV.
Gen(EValN-BValN+1);
2641 for (
int ValN=BValN; ValN<=EValN; ValN++){
2642 SubValV[ValN-BValN]=
ValV[
Last+ValN];}
2660 for (
int ValN=0; ValN<ValV.
Len(); ValN++){
Push(ValV[ValN]);}}
2676 template <
class TVal>
2700 template <
class TVal>
2719 while (Nd!=NULL){
PLstNd NextNd=Nd->
NextNd;
delete Nd; Nd=NextNd;}
2736 void Del(
const TVal& Val);
2747 template <
class TVal>
2749 Nds(0), FirstNd(NULL), LastNd(NULL){
2750 int CheckNds=0; SIn.
Load(CheckNds);
2751 for (
int NdN=0; NdN<CheckNds; NdN++){
AddBack(TVal(SIn));}
2755 template <
class TVal>
2758 PLstNd Nd=FirstNd;
int CheckNds=0;
2760 Nd->
Val.Save(SOut); Nd=Nd->
NextNd; CheckNds++;}
2764 template <
class TVal>
2767 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
2768 else {FirstNd=Nd; LastNd=Nd;}
2772 template <
class TVal>
2775 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
2776 else {FirstNd=Nd; LastNd=Nd;}
2780 template <
class TVal>
2784 return Ins(Nd, Val);
2786 while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
2788 if (Nd==NULL){
return Ins(Nd->Last(),
Val);}
2789 else {
return Ins(Nd->
Prev(),
Val);}
2793 template <
class TVal>
2796 while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->
Val)))){
2798 return Ins(Nd, Val);
2801 template <
class TVal>
2811 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
2812 else {FirstNd=Nd; LastNd=Nd;}
2815 template <
class TVal>
2825 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
2826 else {FirstNd=Nd; LastNd=Nd;}
2829 template <
class TVal>
2831 if (Nd==NULL){
return AddFront(Val);}
2832 else if (Nd->
NextNd==NULL){
return AddBack(Val);}
2840 template <
class TVal>
2842 PLstNd Nd=SearchForw(Val);
2843 if (Nd!=NULL){Del(Nd);}
2846 template <
class TVal>
2856 template <
class TVal>
2866 template <
class TVal>
2893 template <
class THd,
class TRec>
2899 FRnd(
PFRnd(new
TFRnd(FNm, FAccess, CreateIfNo, sizeof(THd), sizeof(TRec)))){}
2916 template <
class TFuncPt>
2932 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
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)
void SwapX(const TSizeTy &X1, const TSizeTy &X2)
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
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.
TVal & At(const TSizeTy &X, const TSizeTy &Y)
TVec< TAscFltIntKd > TAscFltIntKdV
TTuple & operator=(const TTuple &Tup)
int64 GetUniDevInt64(const int64 &Range=0)
static int GetInRng(const int &Val, const int &Mn, const int &Mx)
TQQueue & operator=(const TQQueue &Queue)
TTriple< TStr, TInt, TStrV > TStrIntStrVTr
TPair< TStr, TStr > TStrPr
TVec< TVal, TSizeTy > & Get1DVec()
TPair< TStr, TFlt > TStrFltPr
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.
TVVec(const TSizeTy &_XDim, const TSizeTy &_YDim)
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
TVVVec(const TVVVec &Vec)
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)
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)
char * AdvanceCursor(TSize N)
Return the current pointer and advance the cursor.
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
const TVal & operator()(const TSizeTy &X, const TSizeTy &Y) const
TVVVec< TVal, TSizeTy > & operator=(const TVVVec< TVal, TSizeTy > &Vec)
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.
void GetSwitchedKdV(const TVec< TKeyDat< TKey, TDat >, int > &SrcKdV, TVec< TKeyDat< TDat, TKey >, int > &DstKdV)
void Diff(const TVec< TVal, TSizeTy > &ValV)
Subtracts ValV from this vector. Assumes the vectors are sorted!
const TVal3 & GetVal3() const
void Save(TSOut &SOut) const
const TVal & At(const TSizeTy &X, const TSizeTy &Y, const TSizeTy &Z) 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
void Save(TSOut &SOut) const
bool IsVId(const int &VId) const
TSizeTy AddMP(const TVal &Val)
Adds element Val at the end of the vector in a thread safe manner, returns the element index in the v...
void Save(TSOut &SOut) const
void PutRec(const TRec &Rec, const int &RecN=-1)
TVal & GetRndVal(TRnd &Rnd=TInt::Rnd)
Returns a reference to a random element in the vector.
int AddV(const TValV &ValV)
void SetEmptyVal(const TVal &_EmptyVal)
Sets the empty value.
void Swap(TVVec< TVal, TSizeTy > &Vec)
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
void DelX(const TSizeTy &X)
TQQueue< TIntPr > TIntPrQ
const TVal2 & GetVal2() const
TSizeTy Add(const TVal &Val, const TSizeTy &ResizeLen)
Adds element Val at the end of the vector. #TVec::Add2.
TSizeTy SearchBinLeft(const TVal &Val, TSizeTy &InsValN) const
Returns the position of an element with value Val.
void Clr(const bool &DoDel=false)
bool operator==(const TKeyDat &KeyDat) const
void Swap(const TSizeTy &ValN1, const TSizeTy &ValN2)
Swaps elements at positions ValN1 and ValN2.
TKeyDat< TFlt, TFlt > TFltKd
TVec< TStrStrVPr > TStrStrVPrV
TTriple< TStr, TInt, TInt > TStrIntIntTr
void CompactPool(const TVal &DelVal)
Deletes all elements of value DelVal from all vectors.
TPair< TUInt, TInt > TUIntIntPr
PLstNd AddFront(const TVal &Val)
void CopyUniqueFrom(TVec< TVal, TSizeTy > &Vec, TInt Offset, TInt Sz)
Copy Sz values from Vec starting at Offset.
void Resize(const TSize &_MxVals)
TVec(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
TPair< TInt, TVec< TInt, int > > TIntIntVPr
TVal & LastLast()
Returns a reference to the one before last element of the vector.
TRec * operator()() const
TSizeTy GetMemUsed() const
Returns the memory footprint (the number of bytes) of the vector.
TVal & operator[](const int &ValN)
void PutFront(const PLstNd &Nd)
TSizeTy AddVMerged(const TVec< TVal, TSizeTy > &ValV)
Adds elements of ValV to a sorted vector only if a particular element is not already in the vector...
TLst & operator=(const TLst &)
bool operator<(const TKeyDat &KeyDat) const
void Reduce(const TSizeTy &_Vals=-1)
Reduces the vector's length to _Vals elements, which must be less than the current length...
static PVecPool Load(const TStr &FNm)
TPt< TVecPool< TVal, TSizeTy > > PVecPool
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
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
TVVVec(const TSizeTy &_XDim, const TSizeTy &_YDim, const TSizeTy &_ZDim)
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.
TVVec(const TVec< TVal, TSizeTy > &_ValV, const TSizeTy &_XDim, const TSizeTy &_YDim)
void Intrs(const TVec< TVal, TSizeTy > &ValV)
Sets this vector to its intersection with ValV. Assumes the vectors are sorted!
TVec< TIntUInt64Pr > TIntUInt64PrV
TKeyDat< TStr, TFlt > TStrFltKd
const TVal & operator[](const int &ValN) const
TLstNd & operator=(const TLstNd &)
TPair< TInt, TFlt > TIntFltPr
uint GetVLen(const int &VId) const
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
TVec< TIntFltPr > TIntFltPrV
void GetVal(TVal1 &_Val1, TVal2 &_Val2, TVal3 &_Val3, TVal4 &_Val4) const
const TVal & GetRndVal(TRnd &Rnd=TInt::Rnd) const
Returns a reference to a random element in the vector.
const TVal & operator()(const TSizeTy &X, const TSizeTy &Y, const TSizeTy &Z) 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 MoveLastMP(const TVal &Val, int Inc)
Reserves space after the current last element in a thread safe manner, returning the old vector size...
TSizeTy GetPivotValN(const TSizeTy &LValN, const TSizeTy &RValN) const
Picks three random elements at positions LValN...RValN and returns the middle one.
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
TTriple< TFlt, TFlt, TInt > TFltFltIntTr
void Gen(const int &_MxLast=64, const int &_MxLen=-1)
TVec< TStrFltFltTr > TStrFltFltTrV
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 PutX(const TSizeTy &X, const TVal &Val)
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
bool operator==(const TTuple &Tup) const
bool NextPerm()
Generates next permutation of the elements in the vector.
TVec< TVal, TSizeTy > & operator=(const TVec< TVal, TSizeTy > &Vec)
Assigns new contents to the vector, replacing its current content.
TVec< TUIntIntKd > TUIntIntKdV
TPt< TVecPool< TVal > > PVecPool
const TVal1 & GetVal1() const
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
TVec< TStrStrIntTr > TStrStrIntTrV
TFRec(const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)
unsigned long long uint64
TVal & operator[](const int &ValN) const
const TVal & LastLast() const
Returns a reference to the one before last element of the vector.
TVec< TFltFltStrTr > TFltFltStrTrV
bool operator==(const TPair &Pair) const
void Save(TSOut &SOut) 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.
void PutAll(const TVal &Val)
TQuad< TInt, TInt, TFlt, TFlt > TIntIntFltFltQu
TPair< TBool, TCh > TBoolChPr
TVec< TFltUInt64Kd > TFltUInt64KdV
void Clr(bool DoDel=true)
Clears the contents of the pool.
TCmpTripleByVal2(const bool &AscSort=true)
TCmpTripleByVal3(const bool &AscSort=true)
const TVal2 & GetVal2() const
static TIter GetPivotValNCmp(const TIter &BI, const TIter &EI, const TCmp &Cmp)
Picks three random elements at positions BI...EI and returns the middle one under the comparator Cmp...
void Resize(const ::TSize &_MxVals)
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3)
Returns a vector on elements Val1...Val3.
void Save(TSOut &SOut) const
int GetPrimHashCd() const
TVal & Last()
Returns a reference to the last element of the vector.
TVec< TUInt64StrKd > TUInt64StrKdV
TSizeTy SearchVForw(const TVec< TVal, TSizeTy > &ValV, const TSizeTy &BValN=0) const
Returns the starting position of vector ValV.
TVec< TVal, TSizeTy > 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)
const TVal & GetEmptyVal() const
Returns the reference to an empty value.
const TVal2 & GetVal2() const
TTriple< TInt, TStr, TStr > TIntStrStrTr
void Save(TSOut &SOut) const
TPair< TUInt64, TUInt64 > TUInt64Pr
TVecPool< TInt > TIntVecPool
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5)
Returns a vector on elements Val1...Val5.
void PutAll(const TVal &Val)
Sets the values of all elements in the pool to Val.
Compares the triple by the second value.
const TVal & Last() const
Returns a reference to the last element of the vector.
TPt< TAscFltVP > PAscFltV
static int GetHashCd(const int hc1, const int hc2)
static PVecPool Load(TSIn &SIn)
TVal & At(const TSizeTy &X, const TSizeTy &Y, const TSizeTy &Z)
TSizeTy MxVals
Vector capacity. Capacity is the size of allocated storage. If MxVals==-1, then ValT is not owned by ...
bool operator==(const TVVec &Vec) const
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
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
TQQueue(const TQQueue &Queue)
TPair< TInt, TStr > TIntStrPr
TVec< TStrIntKd > TStrIntKdV
const TVal & operator[](const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
TVal GetXY(const TSizeTy &X, const TSizeTy &Y) const
TAPt & operator=(TRec *_Addr)
TTriple< TUInt64, TUInt64, TUInt64 > TUInt64Tr
TSizeTy IntrsLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the intersection of vectors this and ValV. Assumes the vectors are sorted! ...
TFRec & operator=(const TFRec &)
TVal GetVal(const int &ValN) const
TPair< TInt, TCh > TIntChPr
TPair< TIntPr, TInt > TIntPrIntPr
void PutHd(const THd &Hd)
TPair< TFlt, TFlt > TFltPr
Compares the triple by the third value.
TVal & operator()(const TSizeTy &X, const TSizeTy &Y)
TVec< TAscFltIntPr > TAscFltIntPrV
TVec< TFltUInt64Pr > TFltUInt64PrV
TPair< TBool, TFlt > TBoolFltPr
PLstNd AddFrontSorted(const TVal &Val, const bool &Asc=true)
void GetRow(const TSizeTy &RowN, TVec< TVal, TSizeTy > &Vec) const
void Save(TSOut &SOut) const
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
TVec< TStrIntPr > TStrIntPrV
const TVal & operator[](const int &ValN) const
void ShuffleAll(TRnd &Rnd=TInt::Rnd)
TPair< TAscFlt, TStr > TAscFltStrPr
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.
void LoadShM(TShMIn &ShMIn)
Constructs the vector from a shared memory input.
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.
void PutXY(const TSizeTy &X, const TSizeTy &Y, const TVal &Val)
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
void GetMxValXY(TSizeTy &X, TSizeTy &Y) const
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 DelY(const TSizeTy &Y)
int AddRoot(const TVal &NodeVal=TVal())
TVec< TTriple< TInt, TIntV, TVal > > NodeV
int GetPrimHashCd() const
TVal & operator[](const TSizeTy &ValN)
Returns a reference to the element at position ValN in the vector.
TSizeTy UnionLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the union of vectors this and ValV. Assumes the vectors are sorted! ...
void Del(const TVal &Val)
void LoadShM(TShMIn &ShMIn, TLoadShMElem LoadFromShMFn)
Constructs vector from shared memory input passing in functor to initialize elements.
void Union(const TVec< TVal, TSizeTy > &ValV)
Sets this vector to its union with ValV. Assumes the vectors are sorted!
TLstNd(TLstNd *_PrevNd, TLstNd *_NextNd, const TVal &_Val)
TKeyDat< TUInt, TUInt > TUIntKd
TVec< TUChUInt64Pr > TUChUInt64PrV
const TVal1 & GetVal1() const
void PutBack(const PLstNd &Nd)
TSizeTy Partition(const TSizeTy &MnLValN, const TSizeTy &MxRValN, const bool &Asc)
Partitions the values between positions MnLValN...MxLValN.
TSStack< TBoolChPr > TBoolChS
TTriple< TStr, TStr, TStr > TStrTr
TKeyDat(const TKeyDat &KeyDat)
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
static TStr Fmt(const char *FmtStr,...)
TQuad & operator=(const TQuad &Quad)
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
void Pack()
Reduces vector capacity (frees memory) to match its size.
bool operator<(const TAPt &Pt) const
TQQueue(const int &_MxLast=64, const int &_MxLen=-1)
TVec< TVal, TSizeTy > ValV
TVec< TFltStrPrPr > TFltStrPrPrV
TAPt & operator=(const TAPt &Pt)
void Save(TSOut &SOut) const
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)
void GetCol(const TSizeTy &ColN, TVec< TVal, TSizeTy > &Vec) const
TPair< TStr, TInt > TStrIntPr
void ShuffleAll(TRnd &Rnd=TInt::Rnd)
Shuffles the order of all elements in the pool.
#define EAssertR(Cond, MsgStr)
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
void SwapY(const TSizeTy &Y1, const TSizeTy &Y2)
#define AssertR(Cond, Reason)
TQuad< TInt, TStr, TInt, TInt > TIntStrIntIntQu
void GenRandomTree(const int &Nodes, TRnd &Rnd)
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
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< TFltIntPr > TFltIntPrV
TVVec< TVal, TSizeTy > & operator=(const TVVec< TVal, TSizeTy > &Vec)
bool IsVId(const int &VId) const
Tests whether vector of id VId is in the pool.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
TTuple(const TTuple &Tup)
TSizeTy GetMemSize() const
Returns the memory size (the number of bytes) of a binary representation.
TPt< TIntVecPool > PIntVecPool
void CompactPool(const TVal &DelVal)
void DelLast()
Removes the last element of the vector.
PLstNd SearchForw(const TVal &Val)
TTriple< TInt, TInt, TStr > TIntIntStrTr
void Trunc(const TSizeTy &_Vals=-1)
Truncates the vector's length and capacity to _Vals elements.
static void SwapI(TIter LVal, TIter RVal)
Swaps the elements that iterators LVal and RVal point to.
TVec< TIntFltKd > TIntFltKdV
TPair & operator=(const TPair &Pair)
TKeyDat< TStr, TAscFlt > TStrAscFltKd
TVec< TQQueue< TInt > > TIntQV
bool operator<(const TTree &Tree) const
TVec< TIntStrStrTr > TIntStrStrTrV
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
TVal * GetValVPt(const int &VId) const
static TVec< TVal, TSizeTy > GetV(const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7, const TVal &Val8, const TVal &Val9)
Returns a vector on elements Val1...Val9.
TPair< TUCh, TInt > TUChIntPr
void CopyFrom(const TVVec< TVal, TSizeTy > &VVec)
TLst< TAscFltIntKd > TAscFltIntKdL
TPair< TUInt64, TInt > TUInt64IntPr
void GetRec(TRec &Rec, const int &RecN=-1)
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim, const TSizeTy &_ZDim)
int GetPrimHashCd() const
TVec< TIntStrIntTr > TIntStrIntTrV
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.
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim)
TSizeTy SearchBack(const TVal &Val) const
Returns the position of an element with value Val.
TKeyDat< TFlt, TUInt64 > TFltUInt64Kd
::TSize GetMemUsed() const
TVal * ValT
Pointer to the memory where the elements of the vector are stored.
void Reserve(const TSizeTy &_MxVals, const TSizeTy &_Vals)
Reserves enough memory for the vector to store _MxVals elements and sets its length to _Vals...
void PutY(const TSizeTy &Y, const TVal &Val)
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
bool operator==(const TVVVec &Vec) const
TPair< TVec< TInt, int >, TVec< TFlt, int > > TIntVFltVPr
Compares the pair by the second value.
TVec< TIntUInt64Kd > TIntUInt64KdV
void Save(TSOut &SOut) const
TSizeTy GetMxValN() const
Returns the position of the largest element in the vector.
void Swap(TRec &Rec1, TRec &Rec2)
TKeyDat< TStr, TStr > TStrKd
TTriple & operator=(const TTriple &Triple)
Vector is a sequence TVal objects representing an array that can change in size.
const TVal4 & GetVal4() const
TTriple< TUCh, TInt, TInt > TUChIntIntTr
int AddEmptyV(const int &ValVLen)
TVec< TFltStrKd > TFltStrKdV
const TVal3 & GetVal3() const
TPair< TUInt64, TStr > TUInt64StrPr
void WrTree(const int &NodeId=0, const int &Lev=0)
TTriple< TStr, TFlt, TFlt > TStrFltFltTr
TTriple< TChA, TChA, TChA > TChATr
TSizeTy AddV(const TVec< TVal, TSizeTy > &ValV)
Adds the elements of the vector ValV to the to end of the vector.
void GetSubValV(const TSizeTy &BValN, const TSizeTy &EValN, TVec< TVal, TSizeTy > &ValV) const
Fills ValV with elements at positions BValN...EValN.
bool operator<(const TTriple &Triple) const
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
TVal & operator()(const TSizeTy &X, const TSizeTy &Y, const TSizeTy &Z)
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.