10 TAPt(TRec* _Addr): Addr(_Addr){}
23 Assert(Addr!=NULL);
return Addr[RecN];}
26 bool Empty()
const {
return Addr==NULL;}
31 template <
class TVal1,
class TVal2>
38 TPair(
const TPair& Pair): Val1(Pair.Val1), Val2(Pair.Val2){}
39 TPair(
const TVal1& _Val1,
const TVal2& _Val2): Val1(_Val1), Val2(_Val2){}
42 Val1.Save(SOut); Val2.Save(SOut);}
43 void Load(
TSIn& SIn) {Val1.Load(SIn); Val2.Load(SIn);}
48 if (
this!=&Pair){Val1=Pair.
Val1; Val2=Pair.
Val2;}
return *
this;}
50 return (Val1==Pair.
Val1)&&(Val2==Pair.
Val2);}
52 return (Val1<Pair.
Val1)||((Val1==Pair.
Val1)&&(Val2<Pair.
Val2));}
54 int GetMemUsed()
const {
return Val1.GetMemUsed()+Val2.GetMemUsed();}
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>
138 Val1(Triple.Val1), Val2(Triple.Val2), Val3(Triple.Val3){}
139 TTriple(
const TVal1& _Val1,
const TVal2& _Val2,
const TVal3& _Val3):
140 Val1(_Val1), Val2(_Val2), Val3(_Val3){}
143 Val1.Save(SOut); Val2.Save(SOut); Val3.Save(SOut);}
148 if (
this!=&Triple){Val1=Triple.
Val1; Val2=Triple.
Val2; Val3=Triple.
Val3;}
151 return (Val1==Triple.
Val1)&&(Val2==Triple.
Val2)&&(Val3==Triple.
Val3);}
153 return (Val1<Triple.
Val1)||((Val1==Triple.
Val1)&&(Val2<Triple.
Val2))||
154 ((Val1==Triple.
Val1)&&(Val2==Triple.
Val2)&&(Val3<Triple.
Val3));}
158 int GetMemUsed()
const {
return Val1.GetMemUsed()+Val2.GetMemUsed()+Val3.GetMemUsed();}
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>
227 Val1(), Val2(), Val3(), Val4(){}
229 Val1(Quad.Val1), Val2(Quad.Val2), Val3(Quad.Val3), Val4(Quad.Val4){}
230 TQuad(
const TVal1& _Val1,
const TVal2& _Val2,
const TVal3& _Val3,
const TVal4& _Val4):
231 Val1(_Val1), Val2(_Val2), Val3(_Val3), Val4(_Val4){}
233 Val1(SIn), Val2(SIn), Val3(SIn), Val4(SIn){}
235 Val1.Save(SOut); Val2.Save(SOut); Val3.Save(SOut); Val4.Save(SOut);}
244 return (Val1==Quad.
Val1)&&(Val2==Quad.
Val2)&&(Val3==Quad.
Val3)&&(Val4==Quad.
Val4);}
246 return (Val1<Quad.
Val1)||((Val1==Quad.
Val1)&&(Val2<Quad.
Val2))||
247 ((Val1==Quad.
Val1)&&(Val2==Quad.
Val2)&&(Val3<Quad.
Val3))||
248 ((Val1==Quad.
Val1)&&(Val2==Quad.
Val2)&&(Val3==Quad.
Val3)&&(Val4<Quad.
Val4));}
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; }
285 const TVal&
operator[] (
const int& ValN)
const {
return ValV[ValN]; }
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>
353 explicit TKeyDat(
const TKey& _Key): Key(_Key), Dat(){}
354 TKeyDat(
const TKey& _Key,
const TDat& _Dat): Key(_Key), Dat(_Dat){}
356 void Save(
TSOut& SOut)
const {Key.Save(SOut); Dat.Save(SOut);}
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>
416 if (IsAsc) {
return P1.
Dat < P2.
Dat; }
else {
return P2.
Dat < P1.
Dat; }
429 template <
class TVal,
class TSizeTy =
int>
438 void Resize(
const TSizeTy& _MxVals=-1);
443 TVec(): MxVals(0), Vals(0), ValT(NULL), IsShM(false) {}
446 explicit TVec(
const TSizeTy& _Vals){
448 IAssert(0<=_Vals); MxVals=Vals=_Vals;
449 if (_Vals==0){ValT=NULL;}
else {ValT=
new TVal[_Vals];}}
451 TVec(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
453 IAssert((0<=_Vals)&&(_Vals<=_MxVals)); MxVals=_MxVals; Vals=_Vals;
454 if (_MxVals==0){ValT=NULL;}
else {ValT=
new TVal[_MxVals];}}
459 explicit TVec(TVal *_ValT,
const TSizeTy& _Vals):
460 MxVals(-1), Vals(_Vals), ValT(_ValT), IsShM(false){}
461 ~TVec() {
if ((ValT!=NULL) && (MxVals!=-1)) {
delete[]
ValT;}}
462 explicit TVec(
TSIn& SIn): MxVals(0), Vals(0), ValT(NULL), IsShM(false) {
Load(SIn);}
471 template <
typename TLoadShMElem>
473 if ((ValT!=NULL) && (MxVals!=-1)) {
delete[]
ValT;}
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);}
524 if (ValT!=NULL && MxVals!=-1){
delete[]
ValT;} MxVals=Vals=_Vals;
525 if (MxVals==0){ValT=NULL;}
else {ValT=
new TVal[
MxVals];}}
527 void Gen(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
IAssert((0<=_Vals)&&(_Vals<=_MxVals));
528 if (ValT!=NULL && MxVals!=-1){
delete[]
ValT;} MxVals=_MxVals; Vals=_Vals;
529 if (_MxVals==0){ValT=NULL;}
else {ValT=
new TVal[_MxVals];}}
534 void GenExt(TVal *_ValT,
const TSizeTy& _Vals){
535 if (ValT!=NULL && MxVals!=-1){
delete[]
ValT;}
536 MxVals=-1; Vals=_Vals; ValT=_ValT;}
541 bool IsExt()
const {
return MxVals==-1;}
545 void Reserve(
const TSizeTy& _MxVals,
const TSizeTy& _Vals){
IAssert((0<=_Vals)&&(_Vals<=_MxVals));
Resize(_MxVals); Vals=_Vals;}
550 void Clr(
const bool& DoDel=
true,
const TSizeTy& NoDelLim=-1);
554 void Trunc(
const TSizeTy& _Vals=-1);
556 void Reduce(
const TSizeTy& _Vals=-1) {Vals = _Vals;}
570 bool Empty()
const {
return Vals==0;}
597 TIter
GetI(
const TSizeTy& ValN)
const {
return ValT+ValN;}
602 TSizeTy
Add(){
AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
603 if (Vals==MxVals){
Resize();}
return Vals++;}
608 TSizeTy
Add(
const TVal& Val){
AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
609 if (Vals==MxVals){
Resize();} ValT[
Vals]=Val;
return Vals++;}
610 TSizeTy
Add(TVal& Val){
AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
611 if (Vals==MxVals){
Resize();} ValT[
Vals]=Val;
return Vals++;}
613 TSizeTy
Add(
const TVal& Val,
const TSizeTy& ResizeLen){
AssertR(MxVals!=-1,
"This vector was obtained from TVecPool. Such vectors cannot change its size!");
614 if (Vals==MxVals){
Resize(MxVals+ResizeLen);} ValT[
Vals]=Val;
return Vals++;}
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){
654 EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
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);
674 void Swap(
const TSizeTy& ValN1,
const TSizeTy& ValN2){
EAssertR(!(IsShM && (MxVals == -1)),
"Cannot write to shared memory");
675 const TVal Val=ValT[ValN1]; ValT[ValN1]=ValT[ValN2]; ValT[ValN2]=Val;}
677 static void SwapI(TIter LVal, TIter RVal){
const TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
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>
775 for (TIter i =
BegI(); i !=
EndI()-1; ++i) {
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;}
1672 template <
class TVal,
class TSizeTy=
int>
1693 TVecPool(
const TSize& ExpectVals=0,
const TSize& _GrowBy=1000000,
const bool& _FastCopy=
false,
const TVal& _EmptyVal=TVal());
1697 static PVecPool
New(
const TSize& ExpectVals=0,
const TSize& GrowBy=1000000,
const bool& FastCopy=
false) {
1698 return new TVecPool(ExpectVals, GrowBy, FastCopy); }
1709 bool IsVId(
const int& VId)
const {
return (0 <= VId) && (VId < IdToOffV.
Len()); }
1720 return sizeof(
TCRef)+
sizeof(
TBool)+3*
sizeof(
TSize)+
sizeof(TVal*)+MxVals*
sizeof(TVal);}
1723 int AddV(
const TValV& ValV);
1729 int GetVLen(
const int& VId)
const {
if (VId==0){
return 0;}
else {
return int(IdToOffV[VId]-IdToOffV[VId-1]);}}
1733 else {
return ValBf+IdToOffV[VId-1];}}
1737 void GetV(
const int& VId, TValV& ValV)
const {
1741 void PutV(
const int& VId,
const TValV& ValV) {
1746 for (::
TSize ValN=0; ValN <
::TSize(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
1761 IdToOffV.
Clr(DoDel); MxVals=0; Vals=0;
1762 if (DoDel && ValBf!=NULL) {
delete []
ValBf; ValBf=NULL;}
1763 if (! DoDel) {
PutAll(EmptyVal); } }
1766 for (
TSize ValN = 0; ValN <
MxVals; ValN++) { ValBf[ValN]=Val; } }
1770 template <
class TVal,
class TSizeTy>
1772 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
1773 if (ValBf == NULL) {
1774 try { ValBf =
new TVal [MxVals]; }
1775 catch (std::exception Ex) {
1776 FailR(
TStr::Fmt(
"TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(),
TInt::GetStr(
uint64(_MxVals)).
CStr()).CStr()); }
1778 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
1781 TVal* NewValBf = NULL;
1782 try { NewValBf =
new TVal [MxVals]; }
1783 catch (std::exception Ex) {
1784 FailR(
TStr::Fmt(
"TVecPool::Resize 1: %s, MxVals: %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(),
TInt::GetStr(
uint64(_MxVals)).
CStr()).CStr()); }
1787 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
1789 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
1790 if (EmptyVal != TVal()) {
1791 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
1798 template <
class TVal,
class TSizeTy>
1804 template <
class TVal,
class TSizeTy>
1807 ValBf =
new TVal [
MxVals]; }
1808 catch (std::exception Ex) {
1809 FailR(
TStr::Fmt(
"TVecPool::TVecPool: %s, MxVals: %s. [Program failed to allocate memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(),
TInt::GetStr(
uint64(MxVals)).
CStr()).CStr()); }
1812 memcpy(ValBf, Pool.
ValBf, MxVals*
sizeof(TVal)); }
1814 for (
TSize ValN = 0; ValN <
MxVals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
1817 template <
class TVal,
class TSizeTy>
1819 uint64 _GrowBy, _MxVals, _Vals;
1823 EmptyVal = TVal(SIn);
1824 if (MxVals==0) { ValBf = NULL; }
else { ValBf =
new TVal [
MxVals]; }
1825 for (
TSize ValN = 0; ValN <
Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
1828 for (
int ValN = 0; ValN <
Vals; ValN++) {
1830 IdToOffV[ValN]=
TSize(Offset);
1834 template <
class TVal,
class TSizeTy>
1836 SOut.
Save(FastCopy);
1837 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
1838 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
1839 SOut.
Save(EmptyVal);
1840 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
1842 for (
int ValN = 0; ValN < IdToOffV.
Len(); ValN++) {
1843 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
1847 template <
class TVal,
class TSizeTy>
1857 ValBf =
new TVal [MxVals]; }
1858 catch (std::exception Ex) {
1859 FailR(
TStr::Fmt(
"TVecPool::operator=: %s, MxVals: %s. [Program failed to allocate memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(),
TInt::GetStr(
uint64(MxVals)).
CStr()).CStr()); }
1862 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
1864 for (
TSize ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
1869 template <
class TVal,
class TSizeTy>
1872 if (ValVLen == 0) {
return 0; }
1873 if (MxVals < Vals+ValVLen) { Resize(Vals+
MAX(ValVLen, GrowBy)); }
1874 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
1875 else {
for (
TSize ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
1876 Vals+=ValVLen; IdToOffV.
Add(Vals);
1877 return IdToOffV.
Len()-1;
1880 template <
class TVal,
class TSizeTy>
1882 if (ValVLen==0){
return 0;}
1883 if (MxVals < Vals+ValVLen){Resize(Vals+
MAX(
TSize(ValVLen), GrowBy)); }
1884 Vals+=ValVLen; IdToOffV.
Add(Vals);
1885 return IdToOffV.
Len()-1;
1889 template <
class TVal,
class TSizeTy>
1893 for (
int vid = 1; vid < IdToOffV.
Len(); vid++) {
1895 const uint Len = GetVLen(vid);
1896 TVal* ValV = GetValVPt(vid);
1897 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
1898 if (Len == 0) {
continue; }
1900 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
1903 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
1904 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
1908 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
1911 IdToOffV.
Last() -= TotalDel;
1912 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
1918 template <
class TVal,
class TSizeTy>
1920 for (::
TSize n = Vals-1; n > 0; n--) {
1922 const TVal Tmp = ValBf[n];
1923 ValBf[n] = ValBf[k];
1938 template<
class TVal>
1958 return new TVecPool(ExpectVals, GrowBy, FastCopy); }
1967 bool IsVId(
const int& VId)
const {
return (0 <= VId) && (VId < IdToOffV.
Len()); }
1973 return sizeof(
TCRef)+
sizeof(
TBool)+3*
sizeof(
TSize)+
sizeof(TVal*)+MxVals*
sizeof(TVal);}
1975 int AddV(
const TValV& ValV);
1978 if (VId==0){
return 0;}
1979 else {
return uint(IdToOffV[VId]-IdToOffV[VId-1]);}}
1982 else {
return ValBf+IdToOffV[VId-1];}}
1983 void GetV(
const int& VId, TValV& ValV)
const {
1986 void PutV(
const int& VId,
const TValV& ValV) {
1991 for (
uint ValN=0; ValN <
uint(ValV.
Len()); ValN++, ValPt++) { *ValPt=ValV[ValN]; }
2000 IdToOffV.
Clr(DoDel); MxVals=0; Vals=0;
2001 if (DoDel && ValBf!=NULL) {
delete []
ValBf; ValBf=NULL;}
2002 if (! DoDel) {
PutAll(EmptyVal); }
2005 for (
TSize ValN = 0; ValN <
MxVals; ValN++) { ValBf[ValN]=Val; } }
2010 template <
class TVal>
2012 if (_MxVals <= MxVals){
return; }
else { MxVals = _MxVals; }
2013 if (ValBf == NULL) {
2014 try { ValBf =
new TVal [MxVals]; }
2015 catch (std::exception Ex) {
2016 FailR(
TStr::Fmt(
"TVecPool::Resize 1: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
2018 if (EmptyVal != TVal()) { PutAll(EmptyVal); }
2021 TVal* NewValBf = NULL;
2022 try { NewValBf =
new TVal [MxVals]; }
2023 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVecPool::Resize 2: %s, MxVals: %d. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), _MxVals).CStr()); }
2026 memcpy(NewValBf, ValBf, Vals*
sizeof(TVal)); }
2028 for (
TSize ValN = 0; ValN < Vals; ValN++){ NewValBf[ValN] = ValBf[ValN]; } }
2029 if (EmptyVal != TVal()) {
2030 for (
TSize ValN = Vals; ValN < MxVals; ValN++) { NewValBf[ValN] = EmptyVal; }
2037 template <
class TVal>
2039 GrowBy(_GrowBy), MxVals(0), Vals(0), EmptyVal(_EmptyVal), ValBf(NULL) {
2044 template <
class TVal>
2046 FastCopy(Pool.FastCopy), GrowBy(Pool.GrowBy),
2047 MxVals(Pool.MxVals), Vals(Pool.Vals), EmptyVal(Pool.EmptyVal), IdToOffV(Pool.IdToOffV) {
2048 try { ValBf =
new TVal [
MxVals]; }
2049 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVecPool::TVecPool: %s, MxVals: %d", Ex.what(),
MxVals).CStr()); }
2052 memcpy(ValBf, Pool.
ValBf, MxVals*
sizeof(TVal)); }
2054 for (
TSize ValN = 0; ValN <
MxVals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
2057 template <
class TVal>
2060 uint64 _GrowBy, _MxVals, _Vals;
2064 EmptyVal = TVal(SIn);
2065 if (MxVals==0) { ValBf = NULL; }
else { ValBf =
new TVal [
MxVals]; }
2066 for (
TSize ValN = 0; ValN <
Vals; ValN++) { ValBf[ValN] = TVal(SIn); }
2069 for (
int ValN = 0; ValN <
Vals; ValN++) {
2071 IdToOffV[ValN]=
TSize(Offset);
2075 template <
class TVal>
2077 SOut.
Save(FastCopy);
2078 uint64 _GrowBy=GrowBy, _MxVals=MxVals, _Vals=Vals;
2079 SOut.
Save(_GrowBy); SOut.
Save(_MxVals); SOut.
Save(_Vals);
2080 SOut.
Save(EmptyVal);
2081 for (
TSize ValN = 0; ValN < Vals; ValN++) { ValBf[ValN].Save(SOut); }
2083 for (
int ValN = 0; ValN < IdToOffV.
Len(); ValN++) {
2084 const uint64 Offset=IdToOffV[ValN]; SOut.
Save(Offset);
2088 template <
class TVal>
2097 try { ValBf =
new TVal [MxVals]; }
2098 catch (std::exception Ex) {
FailR(
TStr::Fmt(
"TVec::operator= : %s, MxVals: %d", Ex.what(), MxVals).CStr()); }
2101 memcpy(ValBf, Pool.
ValBf, Vals*
sizeof(TVal)); }
2103 for (
uint64 ValN = 0; ValN < Vals; ValN++){ ValBf[ValN] = Pool.
ValBf[ValN]; } }
2108 template<
class TVal>
2111 if (ValVLen == 0) {
return 0; }
2112 if (MxVals < Vals+ValVLen) { Resize(Vals+
MAX(ValVLen, GrowBy)); }
2113 if (FastCopy) { memcpy(ValBf+Vals, ValV.
BegI(),
sizeof(TVal)*ValV.
Len()); }
2114 else {
for (
uint ValN=0; ValN < ValVLen; ValN++) { ValBf[Vals+ValN]=ValV[ValN]; } }
2115 Vals+=ValVLen; IdToOffV.
Add(Vals);
2116 return IdToOffV.
Len()-1;
2119 template<
class TVal>
2121 if (ValVLen==0){
return 0;}
2122 if (MxVals < Vals+ValVLen){Resize(Vals+
MAX(
TSize(ValVLen), GrowBy)); }
2123 Vals+=ValVLen; IdToOffV.
Add(Vals);
2124 return IdToOffV.
Len()-1;
2129 template<
class TVal>
2133 for (
int vid = 1; vid < IdToOffV.
Len(); vid++) {
2135 const uint Len = GetVLen(vid);
2136 TVal* ValV = GetValVPt(vid);
2137 if (TotalDel > 0) { IdToOffV[vid-1] -= TotalDel; }
2138 if (Len == 0) {
continue; }
2140 for (TVal* v = ValV; v < ValV+Len-NDel; v++) {
2143 while (*v == DelVal && v < ValV+Len) { v++; NDel++; }
2144 memcpy(Beg, v,
sizeof(TVal)*
int(Len - ::
TSize(v - ValV)));
2148 memcpy(ValV-TotalDel, ValV,
sizeof(TVal)*Len);
2151 IdToOffV.
Last() -= TotalDel;
2152 for (::
TSize i = Vals-TotalDel; i < Vals; i++) { ValBf[i] = EmptyVal; }
2158 template<
class TVal>
2160 for (::
TSize n = Vals-1; n > 0; n--) {
2162 const TVal Tmp = ValBf[n];
2163 ValBf[n] = ValBf[k];
2175 template <
class TVal>
2197 if (
this!=&Vec){V=Vec.
V;}
return *
this;}
2199 bool operator<(const PVec<TVal>& Vec)
const {
return V<Vec.V;}
2204 TVal
GetVal(
const int& ValN)
const {
return V[ValN];}
2222 template <
class TVal,
class TSizeTy =
int>
2230 XDim(Vec.XDim), YDim(Vec.YDim), ValV(Vec.ValV){}
2231 TVVec(
const TSizeTy& _XDim,
const TSizeTy& _YDim):
2232 XDim(), YDim(), ValV(){
Gen(_XDim, _YDim);}
2234 XDim(_XDim), YDim(_YDim), ValV(_ValV){
IAssert(ValV.
Len()==XDim*
YDim); }
2241 if (
this!=&Vec){XDim=Vec.
XDim; YDim=Vec.
YDim; ValV=Vec.
ValV;}
return *
this;}
2243 return (XDim==Vec.
XDim)&&(YDim==Vec.
YDim)&&(ValV==Vec.
ValV);}
2247 void Gen(
const TSizeTy& _XDim,
const TSizeTy& _YDim){
2248 Assert((_XDim>=0)&&(_YDim>=0));
2249 XDim=_XDim; YDim=_YDim; ValV.
Gen(XDim*YDim);}
2256 const TVal&
At(
const TSizeTy& X,
const TSizeTy& Y)
const {
2257 Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim)));
2258 return ValV[X*YDim+Y];}
2259 TVal&
At(
const TSizeTy& X,
const TSizeTy& Y){
2260 Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim)));
2261 return ValV[X*YDim+Y];}
2264 const TVal&
operator()(
const TSizeTy& X,
const TSizeTy& Y)
const {
2267 void PutXY(
const TSizeTy& X,
const TSizeTy& Y,
const TVal& Val){
At(X, Y)=Val;}
2269 void PutX(
const TSizeTy& X,
const TVal& Val){
2270 for (TSizeTy Y=0; Y<TSizeTy(YDim); Y++){
At(X, Y)=Val;}}
2271 void PutY(
const TSizeTy& Y,
const TVal& Val){
2272 for (TSizeTy X=0; X<TSizeTy(XDim); X++){
At(X, Y)=Val;}}
2273 TVal
GetXY(
const TSizeTy& X,
const TSizeTy& Y)
const {
2274 Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim)));
2275 return ValV[X*YDim+Y];}
2279 void SwapX(
const TSizeTy& X1,
const TSizeTy& X2);
2280 void SwapY(
const TSizeTy& Y1,
const TSizeTy& Y2);
2285 void GetMxValXY(TSizeTy& X, TSizeTy& Y)
const;
2290 void DelX(
const TSizeTy& X);
2291 void DelY(
const TSizeTy& Y);
2294 template <
class TVal,
class TSizeTy>
2296 for (TSizeTy Y=0; Y<TSizeTy(YDim); Y++){
2297 TVal Val=At(X1, Y); At(X1, Y)=At(X2, Y); At(X2, Y)=Val;}
2300 template <
class TVal,
class TSizeTy>
2302 for (TSizeTy X=0; X<TSizeTy(XDim); X++){
2303 TVal Val=At(X, Y1); At(X, Y1)=At(X, Y2); At(X, Y2)=Val;}
2306 template <
class TVal,
class TSizeTy>
2311 ValV.Swap(Vec.
ValV);
2315 template <
class TVal,
class TSizeTy>
2317 for (TSizeTy X=0; X<XDim-1; X++){SwapX(X, X+Rnd.
GetUniDevInt(XDim-X));}
2320 template <
class TVal,
class TSizeTy>
2322 for (TSizeTy Y=0; Y<YDim-1; Y++){SwapY(Y, Y+Rnd.
GetUniDevInt(YDim-Y));}
2325 template <
class TVal,
class TSizeTy>
2327 TSizeTy MxValN=ValV.GetMxValN();
2332 template <
class TVal,
class TSizeTy>
2334 TSizeTy CopyXDim = (GetXDim() < VVec.
GetXDim()) ? GetXDim() : VVec.
GetXDim();
2335 TSizeTy CopyYDim = (GetYDim() < VVec.
GetYDim()) ? GetYDim() : VVec.
GetYDim();
2336 for (TSizeTy X=0; X<CopyXDim; X++){
2337 for (TSizeTy Y=0; Y<CopyYDim; Y++){
2338 At(X, Y)=VVec.
At(X, Y);
2343 template <
class TVal,
class TSizeTy>
2350 template <
class TVal,
class TSizeTy>
2357 template <
class TVal,
class TSizeTy>
2360 for (TSizeTy Y=0; Y<YDim; Y++){
2361 for (TSizeTy LX=0; LX<X; LX++){
2362 NewVVec.
At(LX, Y)=At(LX, Y);}
2363 for (TSizeTy RX=X+1; RX<XDim; RX++){
2364 NewVVec.
At(RX-1, Y)=At(RX, Y);}
2369 template <
class TVal,
class TSizeTy>
2372 for (TSizeTy X=0; X<XDim; X++){
2373 for (TSizeTy LY=0; LY<Y; LY++){
2374 NewVVec.
At(X, LY)=At(X, LY);}
2375 for (TSizeTy RY=Y+1; RY<YDim; RY++){
2376 NewVVec.
At(X, RY-1)=At(X, RY);}
2381 template <
class TVal,
class TSizeTy >
2383 Vec.
Gen(GetCols(), 0);
2384 for (TSizeTy col = 0; col < GetCols(); col++) {
2385 Vec.
Add(At(RowN, col));
2389 template <
class TVal,
class TSizeTy>
2391 Vec.
Gen(GetRows(), 0);
2392 for (TSizeTy row = 0; row < GetRows(); row++) {
2393 Vec.
Add(At(row, ColN));
2409 template <
class TVal,
class TSizeTy =
int>
2417 XDim(Vec.XDim), YDim(Vec.YDim), ZDim(Vec.ZDim), ValV(Vec.ValV){}
2418 TVVVec(
const TSizeTy& _XDim,
const TSizeTy& _YDim,
const TSizeTy& _ZDim):
2419 XDim(), YDim(), ZDim(), ValV(){
Gen(_XDim, _YDim, _ZDim);}
2421 XDim(SIn), YDim(SIn), ZDim(SIn), ValV(SIn){}
2430 return (XDim==Vec.
XDim)&&(YDim==Vec.
YDim)&&(ZDim==Vec.
ZDim)&&
2434 void Clr(){XDim=0; YDim=0; ZDim=0; ValV.
Clr();}
2435 void Gen(
const TSizeTy& _XDim,
const TSizeTy& _YDim,
const TSizeTy& _ZDim){
2436 Assert((_XDim>=0)&&(_YDim>=0)&&(_ZDim>=0));
2437 XDim=_XDim; YDim=_YDim; ZDim=_ZDim; ValV.
Gen(XDim*YDim*ZDim);}
2438 TVal&
At(
const TSizeTy& X,
const TSizeTy& Y,
const TSizeTy& Z){
2439 Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim))&&(0<=Z)&&(Z<TSizeTy(ZDim)));
2440 return ValV[X*YDim*ZDim+Y*ZDim+Z];}
2441 const TVal&
At(
const TSizeTy& X,
const TSizeTy& Y,
const TSizeTy& Z)
const {
2442 Assert((0<=X)&&(X<TSizeTy(XDim))&&(0<=Y)&&(Y<TSizeTy(YDim))&&(0<=Z)&&(Z<TSizeTy(ZDim)));
2443 return ValV[X*YDim*ZDim+Y*ZDim+Z];}
2444 TVal&
operator()(
const TSizeTy& X,
const TSizeTy& Y,
const TSizeTy& Z){
2445 return At(X, Y, Z);}
2446 const TVal&
operator()(
const TSizeTy& X,
const TSizeTy& Y,
const TSizeTy& Z)
const {
2447 return At(X, Y, Z);}
2460 template <
class TVal>
2483 int AddNode(
const int& ParentNodeId,
const TVal& NodeVal=TVal()){
2484 IAssert(((ParentNodeId==-1)&&(NodeV.
Len()==0))||(NodeV.
Len()>0));
2485 if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.
Add(NodeV.
Len());}
2494 int GetChildNodeId(
const int& NodeId,
const int& ChildN)
const {
return NodeV[NodeId].Val2[ChildN];}
2499 void DelNode(
const int& NodeId);
2500 void CopyTree(
const int& SrcNodeId,
TTree& DstTree,
const int& DstParentNodeId=-1);
2502 void WrTree(
const int& NodeId=0,
const int& Lev=0);
2505 template <
class TVal>
2507 if (NodeId==0){NodeIdV.
Clr();
if (GetNodes()==0){
return;}}
2508 else if (GetParentNodeId(NodeId)==-1){
return;}
2509 NodeIdV.
Add(NodeId);
2510 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2511 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2512 if (ChildNodeId!=-1){
2513 GetNodeIdV(NodeIdV, ChildNodeId);
2518 template <
class TVal>
2523 for (
int NodeN=1; NodeN<Nodes; NodeN++){
2525 AddNode(ParentNodeId, TVal());
2530 template <
class TVal>
2535 TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2536 int ChildNodeIdN=ChildNodeIdV.
SearchForw(NodeId);
2537 ChildNodeIdV[ChildNodeIdN]=-1;
2541 template <
class TVal>
2543 int DstNodeId=DstTree.
AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
2544 for (
int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
2545 int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
2546 if (ChildNodeId!=-1){
2547 CopyTree(ChildNodeId, DstTree, DstNodeId);
2552 template <
class TVal>
2554 for (
int LevN=0; LevN<Lev; LevN++){printf(
"| ");}
2555 printf(
"%d (%d)\n", NodeId, GetChildren(NodeId));
2556 for (
int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2557 int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2558 if (ChildNodeId!=-1){
2559 WrTree(ChildNodeId, Lev+1);
2574 template <
class TVal>
2586 if (
this!=&Stack){ValV=Stack.
ValV;}
return *
this;}
2592 void Clr(
const bool& DoDel=
false) {ValV.
Clr(DoDel);}
2593 bool IsIn(
const TVal& Val)
const {
return ValV.
IsIn(Val);}
2609 template <
class TVal>
2616 TQQueue(
const int& _MxLast=64,
const int& _MxLen=-1):
2617 MxLast(_MxLast), MxLen(_MxLen), First(0), Last(0), ValV(){
2618 Assert(
int(MxLast)>0);
Assert((MxLen==-1)||(
int(MxLen)>0));}
2620 MxLast(Queue.MxLast), MxLen(Queue.MxLen),
2621 First(Queue.First), Last(Queue.Last), ValV(Queue.ValV){}
2623 MxLast(SIn), MxLen(SIn), First(SIn), Last(SIn), ValV(SIn){}
2625 MxLast.
Save(SOut); MxLen.
Save(SOut);
2629 if (
this!=&Queue){MxLast=Queue.
MxLast; MxLen=Queue.
MxLen;
2633 return ValV[Last+ValN];}
2635 void Clr(
const bool& DoDel=
true){ValV.
Clr(DoDel); First=Last=0;}
2636 void Gen(
const int& _MxLast=64,
const int& _MxLen=-1){
2637 MxLast=_MxLast; MxLen=_MxLen; First=0; Last=0; ValV.
Clr();}
2641 SubValV.
Gen(EValN-BValN+1);
2642 for (
int ValN=BValN; ValN<=EValN; ValN++){
2643 SubValV[ValN-BValN]=ValV[Last+ValN];}
2652 if (First==Last){ValV.
Clr(); First=Last=0;}}
2654 if (Last>MxLast){ValV.
Del(0, Last-1); First-=
Last; Last=0;}
2655 if ((MxLen!=-1)&&(MxLen==
Len())){
Pop();}
2656 First++; ValV.
Add(Val);}
2661 for (
int ValN=0; ValN<ValV.
Len(); ValN++){
Push(ValV[ValN]);}}
2677 template <
class TVal>
2684 TLstNd(): PrevNd(NULL), NextNd(NULL), Val(){}
2687 PrevNd(_PrevNd), NextNd(_NextNd), Val(_Val){}
2691 bool IsPrev()
const {
return (PrevNd != NULL); }
2692 bool IsNext()
const {
return (NextNd != NULL); }
2701 template <
class TVal>
2710 TLst(): Nds(0), FirstNd(NULL), LastNd(NULL){}
2720 while (Nd!=NULL){PLstNd NextNd=Nd->
NextNd;
delete Nd; Nd=NextNd;}
2721 Nds=0; FirstNd=NULL; LastNd=NULL;}
2731 PLstNd
AddBack(
const TVal& Val);
2733 PLstNd
AddBackSorted(
const TVal& Val,
const bool& Asc=
true);
2735 void PutBack(
const PLstNd& Nd);
2736 PLstNd
Ins(
const PLstNd& Nd,
const TVal& Val);
2737 void Del(
const TVal& Val);
2738 void Del(
const PLstNd& Nd);
2748 template <
class TVal>
2750 Nds(0), FirstNd(NULL), LastNd(NULL){
2751 int CheckNds=0; SIn.
Load(CheckNds);
2752 for (
int NdN=0; NdN<CheckNds; NdN++){
AddBack(TVal(SIn));}
2756 template <
class TVal>
2759 PLstNd Nd=FirstNd;
int CheckNds=0;
2761 Nd->
Val.Save(SOut); Nd=Nd->
NextNd; CheckNds++;}
2765 template <
class TVal>
2768 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
2769 else {FirstNd=Nd; LastNd=Nd;}
2773 template <
class TVal>
2776 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
2777 else {FirstNd=Nd; LastNd=Nd;}
2781 template <
class TVal>
2785 return Ins(Nd, Val);
2787 while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
2789 if (Nd==NULL){
return Ins(Nd->Last(),
Val);}
2790 else {
return Ins(Nd->
Prev(),
Val);}
2794 template <
class TVal>
2797 while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->
Val)))){
2799 return Ins(Nd, Val);
2802 template <
class TVal>
2812 if (FirstNd!=NULL){FirstNd->
PrevNd=Nd; FirstNd=Nd;}
2813 else {FirstNd=Nd; LastNd=Nd;}
2816 template <
class TVal>
2826 if (LastNd!=NULL){LastNd->
NextNd=Nd; LastNd=Nd;}
2827 else {FirstNd=Nd; LastNd=Nd;}
2830 template <
class TVal>
2832 if (Nd==NULL){
return AddFront(Val);}
2833 else if (Nd->
NextNd==NULL){
return AddBack(Val);}
2841 template <
class TVal>
2843 PLstNd Nd=SearchForw(Val);
2844 if (Nd!=NULL){Del(Nd);}
2847 template <
class TVal>
2857 template <
class TVal>
2867 template <
class TVal>
2894 template <
class THd,
class TRec>
2900 FRnd(
PFRnd(new
TFRnd(FNm, FAccess, CreateIfNo, sizeof(THd), sizeof(TRec)))){}
2912 void PutRec(
const TRec& Rec,
const int& RecN=-1){FRnd->
PutRec(&Rec, RecN);}
2917 template <
class TFuncPt>
2924 TFunc(
const TFuncPt& _FuncPt): FuncPt(_FuncPt){}
2929 if (
this!=&Func){FuncPt=Func.
FuncPt;}
return *
this;}
2931 return FuncPt==Func.
FuncPt;}
2933 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.