SNAP Library 2.1, Developer Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <ds.h>
Public Types | |
typedef TVal * | TIter |
Public Member Functions | |
TVec () | |
TVec (const TVec &Vec) | |
TVec (const int &_Vals) | |
TVec (const int &_MxVals, const int &_Vals) | |
TVec (TVal *_ValT, const int &_Vals) | |
~TVec () | |
TVec (TSIn &SIn) | |
void | Load (TSIn &SIn) |
void | Save (TSOut &SOut) const |
void | LoadXml (const PXmlTok &XmlTok, const TStr &Nm="") |
void | SaveXml (TSOut &SOut, const TStr &Nm) const |
TVec< TVal > & | operator= (const TVec< TVal > &Vec) |
TVec< TVal > & | operator+ (const TVal &Val) |
bool | operator== (const TVec< TVal > &Vec) const |
bool | operator< (const TVec< TVal > &Vec) const |
const TVal & | operator[] (const int &ValN) const |
TVal & | operator[] (const int &ValN) |
int | GetMemUsed () const |
int | GetPrimHashCd () const |
int | GetSecHashCd () const |
void | Gen (const int &_Vals) |
void | Gen (const int &_MxVals, const int &_Vals) |
void | GenExt (TVal *_ValT, const int &_Vals) |
bool | IsExt () const |
void | Reserve (const int &_MxVals) |
void | Reserve (const int &_MxVals, const int &_Vals) |
void | Clr (const bool &DoDel=true, const int &NoDelLim=-1) |
void | Trunc (const int &_Vals=-1) |
void | Pack () |
void | MoveFrom (TVec< TVal > &Vec) |
void | Swap (TVec< TVal > &Vec) |
bool | Empty () const |
int | Len () const |
int | Reserved () const |
const TVal & | Last () const |
TVal & | Last () |
int | LastValN () const |
const TVal & | LastLast () const |
TVal & | LastLast () |
TIter | BegI () const |
TIter | EndI () const |
TIter | GetI (const int &ValN) const |
int | Add () |
int | Add (const TVal &Val) |
int | Add (const TVal &Val, const int &ResizeLen) |
int | AddV (const TVec< TVal > &ValV) |
int | AddSorted (const TVal &Val, const bool &Asc=true, const int &_MxVals=-1) |
int | AddBackSorted (const TVal &Val, const bool &Asc) |
int | AddMerged (const TVal &Val) |
int | AddVMerged (const TVec< TVal > &ValV) |
int | AddUnique (const TVal &Val) |
const TVal & | GetVal (const int &ValN) const |
TVal & | GetVal (const int &ValN) |
void | GetSubValV (const int &BValN, const int &EValN, TVec< TVal > &ValV) const |
void | Ins (const int &ValN, const TVal &Val) |
void | Del (const int &ValN) |
void | Del (const int &MnValN, const int &MxValN) |
void | DelLast () |
bool | DelIfIn (const TVal &Val) |
void | DelAll (const TVal &Val) |
void | PutAll (const TVal &Val) |
void | Swap (const int &ValN1, const int &ValN2) |
int | GetPivotValN (const int &LValN, const int &RValN) const |
void | BSort (const int &MnLValN, const int &MxRValN, const bool &Asc) |
void | ISort (const int &MnLValN, const int &MxRValN, const bool &Asc) |
int | Partition (const int &MnLValN, const int &MxRValN, const bool &Asc) |
void | QSort (const int &MnLValN, const int &MxRValN, const bool &Asc) |
void | Sort (const bool &Asc=true) |
bool | IsSorted (const bool &Asc=true) const |
void | Shuffle (TRnd &Rnd) |
void | Reverse () |
void | Reverse (int First, int Last) |
void | Merge () |
bool | NextPerm () |
bool | PrevPerm () |
void | MakeHeap () |
void | PushHeap (const TVal &Val) |
const TVal & | TopHeap () const |
TVal | PopHeap () |
template<class TCmp > | |
void | MakeHeap (const TCmp &Cmp) |
template<class TCmp > | |
void | PushHeap (const TVal &Val, const TCmp &Cmp) |
template<class TCmp > | |
TVal | PopHeap (const TCmp &Cmp) |
template<class TCmp > | |
void | PushHeap (const int &First, int HoleIdx, const int &Top, TVal Val, const TCmp &Cmp) |
template<class TCmp > | |
void | AdjustHeap (const int &First, int HoleIdx, const int &Len, TVal Val, const TCmp &Cmp) |
template<class TCmp > | |
void | MakeHeap (const int &First, const int &Len, const TCmp &Cmp) |
template<class TCmp > | |
void | SortCmp (const TCmp &Cmp) |
template<class TCmp > | |
bool | IsSortedCmp (const TCmp &Cmp) const |
void | Intrs (const TVec< TVal > &ValV) |
void | Union (const TVec< TVal > &ValV) |
void | Diff (const TVec< TVal > &ValV) |
void | Minus (const TVec< TVal > &ValV) |
void | Intrs (const TVec< TVal > &ValV, TVec< TVal > &DstValV) const |
void | Union (const TVec< TVal > &ValV, TVec< TVal > &DstValV) const |
void | Diff (const TVec< TVal > &ValV, TVec< TVal > &DstValV) const |
int | IntrsLen (const TVec< TVal > &ValV) const |
Returns the size of the intersection (number of common elements) with vector ValV . Method assumes both vectors are sorted in ascending order! | |
int | UnionLen (const TVec< TVal > &ValV) const |
Returns the size of the union with vector ValV . Method assumes both vectors are sorted in ascending order! | |
void | Minus (const TVec< TVal > &ValV, TVec< TVal > &DstValV) const |
int | Count (const TVal &Val) const |
int | SearchBin (const TVal &Val) const |
int | SearchBin (const TVal &Val, int &InsValN) const |
int | SearchForw (const TVal &Val, const int &BValN=0) const |
int | SearchBack (const TVal &Val) const |
int | SearchVForw (const TVec< TVal > &ValV, const int &BValN=0) const |
bool | IsIn (const TVal &Val) const |
bool | IsIn (const TVal &Val, int &ValN) const |
bool | IsInBin (const TVal &Val) const |
int | GetMxValN () const |
TVal & | GetDat (const TVal &Val) const |
TVal & | GetAddDat (const TVal &Val) |
Static Public Member Functions | |
static void | SwapI (TIter LVal, TIter RVal) |
template<class TCmp > | |
static TIter | GetPivotValNCmp (const TIter &BI, const TIter &EI, const TCmp &Cmp) |
template<class TCmp > | |
static TIter | PartitionCmp (TIter BI, TIter EI, const TVal Pivot, const TCmp &Cmp) |
template<class TCmp > | |
static void | BSortCmp (TIter BI, TIter EI, const TCmp &Cmp) |
template<class TCmp > | |
static void | ISortCmp (TIter BI, TIter EI, const TCmp &Cmp) |
template<class TCmp > | |
static void | QSortCmp (TIter BI, TIter EI, const TCmp &Cmp) |
static TVec< TVal > | GetV (const TVal &Val1) |
static TVec< TVal > | GetV (const TVal &Val1, const TVal &Val2) |
static TVec< TVal > | GetV (const TVal &Val1, const TVal &Val2, const TVal &Val3) |
static TVec< TVal > | GetV (const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4) |
static TVec< TVal > | GetV (const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5) |
static TVec< TVal > | GetV (const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6) |
static TVec< TVal > | GetV (const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7) |
static TVec< TVal > | GetV (const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7, const TVal &Val8) |
static TVec< TVal > | GetV (const TVal &Val1, const TVal &Val2, const TVal &Val3, const TVal &Val4, const TVal &Val5, const TVal &Val6, const TVal &Val7, const TVal &Val8, const TVal &Val9) |
Protected Member Functions | |
void | Resize (const int &_MxVals=-1) |
TStr | GetXOutOfBoundsErrMsg (const int &ValN) const |
Protected Attributes | |
int | MxVals |
int | Vals |
TVal * | ValT |
typedef TVal* TGLib_OLD::TVec< TVal >::TIter |
TGLib_OLD::TVec< TVal >::TVec | ( | ) | [inline] |
TGLib_OLD::TVec< TVal >::TVec | ( | const TVec< TVal > & | Vec | ) |
TGLib_OLD::TVec< TVal >::TVec | ( | const int & | _Vals | ) | [inline, explicit] |
TGLib_OLD::TVec< TVal >::TVec | ( | const int & | _MxVals, |
const int & | _Vals | ||
) | [inline] |
TGLib_OLD::TVec< TVal >::TVec | ( | TVal * | _ValT, |
const int & | _Vals | ||
) | [inline, explicit] |
TGLib_OLD::TVec< TVal >::~TVec | ( | ) | [inline] |
TGLib_OLD::TVec< TVal >::TVec | ( | TSIn & | SIn | ) | [inline, explicit] |
int TGLib_OLD::TVec< TVal >::Add | ( | ) | [inline] |
Definition at line 1559 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::GetAddDat(), TGLib_OLD::TVec< ::TSize >::operator+(), TGLib_OLD::TVec< ::TSize >::PushHeap(), and TGLib_OLD::TVecPool< TVal >::TVecPool().
int TGLib_OLD::TVec< TVal >::Add | ( | const TVal & | Val | ) | [inline] |
int TGLib_OLD::TVec< TVal >::Add | ( | const TVal & | Val, |
const int & | ResizeLen | ||
) | [inline] |
int TVec< TVal >::AddBackSorted | ( | const TVal & | Val, |
const bool & | Asc | ||
) |
int TVec< TVal >::AddSorted | ( | const TVal & | Val, |
const bool & | Asc = true , |
||
const int & | _MxVals = -1 |
||
) |
Definition at line 1969 of file ds.h.
References Assert, and Swap().
{ Assert(MxVals!=-1); int ValN=Add(Val); if (Asc){ while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){ Swap(ValN, ValN-1); ValN--;} } else { while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){ Swap(ValN, ValN-1); ValN--;} } if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);} return ValN; }
int TVec< TVal >::AddVMerged | ( | const TVec< TVal > & | ValV | ) |
void TGLib_OLD::TVec< TVal >::AdjustHeap | ( | const int & | First, |
int | HoleIdx, | ||
const int & | Len, | ||
TVal | Val, | ||
const TCmp & | Cmp | ||
) | [inline] |
Definition at line 1622 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::MakeHeap(), and TGLib_OLD::TVec< ::TSize >::PopHeap().
{ const int Top = HoleIdx; int Right = 2*HoleIdx+2; while (Right < Len) { if (Cmp(ValT[First+Right], ValT[First+Right-1])) { Right--; } ValT[First+HoleIdx] = ValT[First+Right]; HoleIdx = Right; Right = 2*(Right+1); } if (Right == Len) { ValT[First+HoleIdx] = ValT[First+Right-1]; HoleIdx = Right-1; } PushHeap(First, HoleIdx, Top, Val, Cmp); }
TIter TGLib_OLD::TVec< TVal >::BegI | ( | ) | const [inline] |
Definition at line 1555 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::IsSortedCmp(), and TGLib_OLD::TVec< ::TSize >::SortCmp().
{return ValT;}
void TVec< TVal >::BSort | ( | const int & | MnLValN, |
const int & | MxRValN, | ||
const bool & | Asc | ||
) |
Definition at line 2079 of file ds.h.
References Swap().
{ for (int ValN1=MnLValN; ValN1<=MxRValN; ValN1++){ for (int ValN2=MxRValN; ValN2>ValN1; ValN2--){ if (Asc){ if (ValT[ValN2]<ValT[ValN2-1]){Swap(ValN2, ValN2-1);} } else { if (ValT[ValN2]>ValT[ValN2-1]){Swap(ValN2, ValN2-1);} } } } }
static void TGLib_OLD::TVec< TVal >::BSortCmp | ( | TIter | BI, |
TIter | EI, | ||
const TCmp & | Cmp | ||
) | [inline, static] |
void TVec< TVal >::Clr | ( | const bool & | DoDel = true , |
const int & | NoDelLim = -1 |
||
) |
Definition at line 1896 of file ds.h.
References IAssert.
Referenced by TGLib_OLD::TVecPool< TVal >::Clr().
{ if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){ if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;} MxVals=Vals=0; ValT=NULL; } else { IAssert(MxVals!=-1); Vals=0; } }
Definition at line 2037 of file ds.h.
References Assert.
Referenced by TGLib_OLD::TVec< ::TSize >::DelLast().
{ Assert(MxVals!=-1); Assert((0<=ValN)&&(ValN<Vals)); for (int MValN=ValN+1; MValN<Vals; MValN++){ ValT[MValN-1]=ValT[MValN];} ValT[--Vals]=TVal(); }
void TGLib_OLD::TVec< TVal >::DelLast | ( | ) | [inline] |
Definition at line 1577 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::PopHeap().
Definition at line 2262 of file ds.h.
{ TVec<TVal> DiffVec; Diff(ValV, DiffVec); MoveFrom(DiffVec); }
void TVec< TVal >::Diff | ( | const TVec< TVal > & | ValV, |
TVec< TVal > & | DstValV | ||
) | const |
Definition at line 2338 of file ds.h.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), TVec< TVal, TSizeTy >::GetVal(), and TVec< TVal, TSizeTy >::Len().
{ DstValV.Clr(); int ValN1=0; int ValN2=0; while (ValN1<Len() && ValN2<ValV.Len()) { const TVal& Val1 = GetVal(ValN1); while (ValN2<ValV.Len() && Val1>ValV.GetVal(ValN2)) ValN2++; if (ValN2<ValV.Len()) { if (Val1!=ValV.GetVal(ValN2)) { DstValV.Add(Val1); } ValN1++; } } for (int RestValN1=ValN1; RestValN1<Len(); RestValN1++){ DstValV.Add(GetVal(RestValN1));} }
bool TGLib_OLD::TVec< TVal >::Empty | ( | ) | const [inline] |
Definition at line 1542 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::PopHeap().
{return Vals==0;}
TIter TGLib_OLD::TVec< TVal >::EndI | ( | ) | const [inline] |
Definition at line 1556 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::IsSortedCmp(), and TGLib_OLD::TVec< ::TSize >::SortCmp().
void TGLib_OLD::TVec< TVal >::Gen | ( | const int & | _Vals | ) | [inline] |
void TGLib_OLD::TVec< TVal >::Gen | ( | const int & | _MxVals, |
const int & | _Vals | ||
) | [inline] |
void TGLib_OLD::TVec< TVal >::GenExt | ( | TVal * | _ValT, |
const int & | _Vals | ||
) | [inline] |
TVal& TGLib_OLD::TVec< TVal >::GetAddDat | ( | const TVal & | Val | ) | [inline] |
Definition at line 1755 of file ds.h.
{ Assert(MxVals!=-1); int ValN=SearchForw(Val); if (ValN==-1){Add(Val); return Last();} else {return operator[](ValN);}}
TVal& TGLib_OLD::TVec< TVal >::GetDat | ( | const TVal & | Val | ) | const [inline] |
Definition at line 1752 of file ds.h.
{ int ValN=SearchForw(Val); return operator[](ValN);}
TIter TGLib_OLD::TVec< TVal >::GetI | ( | const int & | ValN | ) | const [inline] |
int TGLib_OLD::TVec< TVal >::GetMemUsed | ( | ) | const [inline] |
int TVec< TVal >::GetPivotValN | ( | const int & | LValN, |
const int & | RValN | ||
) | const |
Definition at line 2111 of file ds.h.
References TInt::GetRnd().
{ int SubVals=RValN-LValN+1; int ValN1=LValN+TInt::GetRnd(SubVals); int ValN2=LValN+TInt::GetRnd(SubVals); int ValN3=LValN+TInt::GetRnd(SubVals); const TVal& Val1=ValT[ValN1]; const TVal& Val2=ValT[ValN2]; const TVal& Val3=ValT[ValN3]; if (Val1<Val2){ if (Val2<Val3){return ValN2;} else if (Val3<Val1){return ValN1;} else {return ValN3;} } else { if (Val1<Val3){return ValN1;} else if (Val3<Val2){return ValN2;} else {return ValN3;} } }
static TIter TGLib_OLD::TVec< TVal >::GetPivotValNCmp | ( | const TIter & | BI, |
const TIter & | EI, | ||
const TCmp & | Cmp | ||
) | [inline, static] |
Definition at line 1644 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::QSortCmp().
{ const int SubVals=int(EI-BI); const int ValN1=TInt::GetRnd(SubVals); const int ValN2=TInt::GetRnd(SubVals); const int ValN3=TInt::GetRnd(SubVals); const TVal& Val1 = *(BI+ValN1); const TVal& Val2 = *(BI+ValN2); const TVal& Val3 = *(BI+ValN3); if (Cmp(Val1, Val2)) { if (Cmp(Val2, Val3)) return BI+ValN2; else if (Cmp(Val3, Val1)) return BI+ValN1; else return BI+ValN3; } else { if (Cmp(Val1, Val3)) return BI+ValN1; else if (Cmp(Val3, Val2)) return BI+ValN2; else return BI+ValN3; } }
int TVec< TVal >::GetPrimHashCd | ( | ) | const |
int TVec< TVal >::GetSecHashCd | ( | ) | const |
void TVec< TVal >::GetSubValV | ( | const int & | BValN, |
const int & | EValN, | ||
TVec< TVal > & | ValV | ||
) | const |
Definition at line 2018 of file ds.h.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Gen(), TInt::GetInRng(), and TInt::GetMx().
{ int BValN=TInt::GetInRng(_BValN, 0, Len()-1); int EValN=TInt::GetInRng(_EValN, 0, Len()-1); int SubVals=TInt::GetMx(0, EValN-BValN+1); SubValV.Gen(SubVals, 0); for (int ValN=BValN; ValN<=EValN; ValN++){ SubValV.Add(GetVal(ValN));} }
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1 | ) | [inline, static] |
Definition at line 1762 of file ds.h.
{ TVec<TVal> V(1, 0); V.Add(Val1); return V;}
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1, |
const TVal & | Val2 | ||
) | [inline, static] |
Definition at line 1764 of file ds.h.
{ TVec<TVal> V(2, 0); V.Add(Val1); V.Add(Val2); return V;}
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1, |
const TVal & | Val2, | ||
const TVal & | Val3 | ||
) | [inline, static] |
Definition at line 1766 of file ds.h.
{ TVec<TVal> V(3, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); return V;}
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1, |
const TVal & | Val2, | ||
const TVal & | Val3, | ||
const TVal & | Val4 | ||
) | [inline, static] |
Definition at line 1768 of file ds.h.
{ TVec<TVal> V(4, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); return V;}
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1, |
const TVal & | Val2, | ||
const TVal & | Val3, | ||
const TVal & | Val4, | ||
const TVal & | Val5 | ||
) | [inline, static] |
Definition at line 1770 of file ds.h.
{ TVec<TVal> V(5, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); return V;}
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1, |
const TVal & | Val2, | ||
const TVal & | Val3, | ||
const TVal & | Val4, | ||
const TVal & | Val5, | ||
const TVal & | Val6 | ||
) | [inline, static] |
Definition at line 1772 of file ds.h.
{ TVec<TVal> V(6, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); return V;}
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1, |
const TVal & | Val2, | ||
const TVal & | Val3, | ||
const TVal & | Val4, | ||
const TVal & | Val5, | ||
const TVal & | Val6, | ||
const TVal & | Val7 | ||
) | [inline, static] |
Definition at line 1774 of file ds.h.
{ TVec<TVal> V(7, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); V.Add(Val7); return V;}
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1, |
const TVal & | Val2, | ||
const TVal & | Val3, | ||
const TVal & | Val4, | ||
const TVal & | Val5, | ||
const TVal & | Val6, | ||
const TVal & | Val7, | ||
const TVal & | Val8 | ||
) | [inline, static] |
Definition at line 1776 of file ds.h.
{ TVec<TVal> V(8, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); V.Add(Val7); V.Add(Val8); return V;}
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV | ( | const TVal & | Val1, |
const TVal & | Val2, | ||
const TVal & | Val3, | ||
const TVal & | Val4, | ||
const TVal & | Val5, | ||
const TVal & | Val6, | ||
const TVal & | Val7, | ||
const TVal & | Val8, | ||
const TVal & | Val9 | ||
) | [inline, static] |
Definition at line 1778 of file ds.h.
{ TVec<TVal> V(9, 0); V.Add(Val1); V.Add(Val2); V.Add(Val3); V.Add(Val4); V.Add(Val5); V.Add(Val6); V.Add(Val7); V.Add(Val8); V.Add(Val9); return V;}
const TVal& TGLib_OLD::TVec< TVal >::GetVal | ( | const int & | ValN | ) | const [inline] |
Definition at line 1571 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::Last().
{return operator[](ValN);}
TVal& TGLib_OLD::TVec< TVal >::GetVal | ( | const int & | ValN | ) | [inline] |
Definition at line 1572 of file ds.h.
{return operator[](ValN);}
TStr TVec< TVal >::GetXOutOfBoundsErrMsg | ( | const int & | ValN | ) | const [protected] |
Definition at line 1813 of file ds.h.
References TInt::GetStr(), and GetTypeNm().
Referenced by TGLib_OLD::TVec< ::TSize >::LastLast(), and TGLib_OLD::TVec< ::TSize >::operator[]().
{ return TStr()+ "Index:"+TInt::GetStr(ValN)+ " Vals:"+TInt::GetStr(Vals)+ " MxVals:"+TInt::GetStr(MxVals)+ " Type:"+GetTypeNm(*this); }
Definition at line 2248 of file ds.h.
{ TVec<TVal> IntrsVec; Intrs(ValV, IntrsVec); MoveFrom(IntrsVec); }
void TVec< TVal >::Intrs | ( | const TVec< TVal > & | ValV, |
TVec< TVal > & | DstValV | ||
) | const |
Definition at line 2276 of file ds.h.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), TVec< TVal, TSizeTy >::GetVal(), and TVec< TVal, TSizeTy >::Len().
{ DstValV.Clr(); int ValN1=0; int ValN2=0; while ((ValN1<Len())&&(ValN2<ValV.Len())){ const TVal& Val1=GetVal(ValN1); while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){ ValN2++;} if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){ DstValV.Add(Val1); ValN2++;} ValN1++; } }
Returns the size of the intersection (number of common elements) with vector ValV
. Method assumes both vectors are sorted in ascending order!
Definition at line 2354 of file ds.h.
References TVec< TVal, TSizeTy >::GetVal(), and TVec< TVal, TSizeTy >::Len().
{ int Cnt=0, ValN1=0; int ValN2=0; while ((ValN1<Len())&&(ValN2<ValV.Len())){ const TVal& Val1=GetVal(ValN1); while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){ ValN2++;} if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){ ValN2++; Cnt++;} ValN1++; } return Cnt; }
bool TGLib_OLD::TVec< TVal >::IsExt | ( | ) | const [inline] |
bool TGLib_OLD::TVec< TVal >::IsIn | ( | const TVal & | Val | ) | const [inline] |
Definition at line 1747 of file ds.h.
{return SearchForw(Val)!=-1;}
bool TGLib_OLD::TVec< TVal >::IsIn | ( | const TVal & | Val, |
int & | ValN | ||
) | const [inline] |
Definition at line 1748 of file ds.h.
{ ValN=SearchForw(Val); return ValN!=-1;}
bool TGLib_OLD::TVec< TVal >::IsInBin | ( | const TVal & | Val | ) | const [inline] |
void TVec< TVal >::ISort | ( | const int & | MnLValN, |
const int & | MxRValN, | ||
const bool & | Asc | ||
) |
Definition at line 2093 of file ds.h.
{ if (MnLValN<MxRValN){ for (int ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){ TVal Val=ValT[ValN1]; int ValN2=ValN1; if (Asc){ while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){ ValT[ValN2]=ValT[ValN2-1]; ValN2--;} } else { while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){ ValT[ValN2]=ValT[ValN2-1]; ValN2--;} } ValT[ValN2]=Val; } } }
static void TGLib_OLD::TVec< TVal >::ISortCmp | ( | TIter | BI, |
TIter | EI, | ||
const TCmp & | Cmp | ||
) | [inline, static] |
Definition at line 1684 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::QSortCmp().
{ if (BI + 1 < EI) { for (TIter i = BI, j; i != EI; ++i) { TVal Tmp = *i; j = i; while (j > BI && Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; } *j = Tmp; } } }
bool TGLib_OLD::TVec< TVal >::IsSortedCmp | ( | const TCmp & | Cmp | ) | const [inline] |
const TVal& TGLib_OLD::TVec< TVal >::Last | ( | ) | const [inline] |
Definition at line 1545 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::GetAddDat(), and TGLib_OLD::TVec< ::TSize >::PopHeap().
TVal& TGLib_OLD::TVec< TVal >::Last | ( | ) | [inline] |
const TVal& TGLib_OLD::TVec< TVal >::LastLast | ( | ) | const [inline] |
TVal& TGLib_OLD::TVec< TVal >::LastLast | ( | ) | [inline] |
int TGLib_OLD::TVec< TVal >::LastValN | ( | ) | const [inline] |
int TGLib_OLD::TVec< TVal >::Len | ( | ) | const [inline] |
Definition at line 1543 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::DelLast(), TGLib_OLD::TVecPool< TVal >::GetVecs(), TGLib_OLD::TVecPool< TVal >::IsVId(), TGLib_OLD::TVec< ::TSize >::Last(), TGLib_OLD::TVec< ::TSize >::LastValN(), TGLib_OLD::TVec< ::TSize >::MakeHeap(), TGLib_OLD::TVec< ::TSize >::PopHeap(), and TGLib_OLD::TVec< ::TSize >::PushHeap().
{return Vals;}
Definition at line 1829 of file ds.h.
References TSIn::Load().
Referenced by TGLib_OLD::TVec< ::TSize >::TVec().
{ if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;} SIn.Load(MxVals); SIn.Load(Vals); MxVals=Vals; if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];} for (int ValN=0; ValN<Vals; ValN++){ ValT[ValN]=TVal(SIn);} }
void TGLib_OLD::TVec< TVal >::LoadXml | ( | const PXmlTok & | XmlTok, |
const TStr & | Nm = "" |
||
) |
void TGLib_OLD::TVec< TVal >::MakeHeap | ( | ) | [inline] |
Definition at line 1604 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::MakeHeap().
{ MakeHeap(TLss<TVal>()); } // build a heap
void TGLib_OLD::TVec< TVal >::MakeHeap | ( | const TCmp & | Cmp | ) | [inline] |
Definition at line 1608 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::MakeHeap().
void TGLib_OLD::TVec< TVal >::MakeHeap | ( | const int & | First, |
const int & | Len, | ||
const TCmp & | Cmp | ||
) | [inline] |
Definition at line 2194 of file ds.h.
References Assert, TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::Sort().
{ Assert(MxVals!=-1); TVec<TVal> SortedVec(*this); SortedVec.Sort(); Clr(); for (int ValN=0; ValN<SortedVec.Len(); ValN++){ if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){ Add(SortedVec[ValN]);} } }
Definition at line 2269 of file ds.h.
{ TVec<TVal> MinusVec; Minus(ValV, MinusVec); MoveFrom(MinusVec); }
Definition at line 1944 of file ds.h.
References TVec< TVal, TSizeTy >::MxVals, TVec< TVal, TSizeTy >::Vals, and TVec< TVal, TSizeTy >::ValT.
Definition at line 2205 of file ds.h.
References Swap().
{ // start with a sorted sequence to obtain all permutations int First = 0, Last = Len(), Next = Len()-1; if (Last < 2) return false; for(; ; ) { // find rightmost element smaller than successor int Next1 = Next; if (GetVal(--Next) < GetVal(Next1)) { // swap with rightmost element that's smaller, flip suffix int Mid = Last; for (; GetVal(Next) >= GetVal(--Mid); ) { } Swap(Next, Mid); Reverse(Next1, Last); return true; } if (Next == First) { // pure descending, flip all Reverse(); return false; } } }
TVec<TVal>& TGLib_OLD::TVec< TVal >::operator+ | ( | const TVal & | Val | ) | [inline] |
Definition at line 1865 of file ds.h.
References TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::ValT.
{ if (this==&Vec){return false;} if (Len()==Vec.Len()){ for (int ValN=0; ValN<Vals; ValN++){ if (ValT[ValN]<Vec.ValT[ValN]){return true;} else if (ValT[ValN]>Vec.ValT[ValN]){return false;} else {} } return false; } else { return Len()<Vec.Len(); } }
Definition at line 1845 of file ds.h.
References TVec< TVal, TSizeTy >::Vals, and TVec< TVal, TSizeTy >::ValT.
Definition at line 1856 of file ds.h.
References TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::ValT.
{ if (this==&Vec){return true;} if (Len()!=Vec.Len()){return false;} for (int ValN=0; ValN<Vals; ValN++){ if (ValT[ValN]!=Vec.ValT[ValN]){return false;}} return true; }
const TVal& TGLib_OLD::TVec< TVal >::operator[] | ( | const int & | ValN | ) | const [inline] |
Definition at line 1508 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::GetAddDat(), TGLib_OLD::TVec< ::TSize >::GetDat(), and TGLib_OLD::TVec< ::TSize >::GetVal().
{ AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN)); return ValT[ValN];}
TVal& TGLib_OLD::TVec< TVal >::operator[] | ( | const int & | ValN | ) | [inline] |
int TVec< TVal >::Partition | ( | const int & | MnLValN, |
const int & | MxRValN, | ||
const bool & | Asc | ||
) |
Definition at line 2131 of file ds.h.
References forever, and Swap().
{ int PivotValN=GetPivotValN(MnLValN, MxRValN); Swap(PivotValN, MnLValN); TVal PivotVal=ValT[MnLValN]; int LValN=MnLValN-1; int RValN=MxRValN+1; forever { if (Asc){ do {RValN--;} while (ValT[RValN]>PivotVal); do {LValN++;} while (ValT[LValN]<PivotVal); } else { do {RValN--;} while (ValT[RValN]<PivotVal); do {LValN++;} while (ValT[LValN]>PivotVal); } if (LValN<RValN){Swap(LValN, RValN);} else {return RValN;} }; }
static TIter TGLib_OLD::TVec< TVal >::PartitionCmp | ( | TIter | BI, |
TIter | EI, | ||
const TVal | Pivot, | ||
const TCmp & | Cmp | ||
) | [inline, static] |
TVal TGLib_OLD::TVec< TVal >::PopHeap | ( | ) | [inline] |
Definition at line 1607 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::PopHeap().
{ return PopHeap(TLss<TVal>()); } // remove largest element
TVal TGLib_OLD::TVec< TVal >::PopHeap | ( | const TCmp & | Cmp | ) | [inline] |
Definition at line 2227 of file ds.h.
References Swap().
{ int First = 0, Last = Len(), Next = Len()-1; if (Last < 2) return false; for(; ; ) { // find rightmost element not smaller than successor int Next1 = Next; if (GetVal(--Next) >= GetVal(Next1)) { // swap with rightmost element that's not smaller, flip suffix int Mid = Last; for (; GetVal(Next) < GetVal(--Mid); ) { } Swap(Next, Mid); Reverse(Next1, Last); return true; } if (Next == First) { // pure descending, flip all Reverse(); return false; } } }
void TGLib_OLD::TVec< TVal >::PushHeap | ( | const TVal & | Val | ) | [inline] |
Definition at line 1605 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::AdjustHeap(), and TGLib_OLD::TVec< ::TSize >::PushHeap().
{ PushHeap(Val, TLss<TVal>()); } // add element to the heap
void TGLib_OLD::TVec< TVal >::PushHeap | ( | const TVal & | Val, |
const TCmp & | Cmp | ||
) | [inline] |
void TGLib_OLD::TVec< TVal >::PushHeap | ( | const int & | First, |
int | HoleIdx, | ||
const int & | Top, | ||
TVal | Val, | ||
const TCmp & | Cmp | ||
) | [inline] |
static void TGLib_OLD::TVec< TVal >::QSortCmp | ( | TIter | BI, |
TIter | EI, | ||
const TCmp & | Cmp | ||
) | [inline, static] |
Definition at line 1695 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::QSortCmp(), and TGLib_OLD::TVec< ::TSize >::SortCmp().
{ if (BI + 1 < EI) { if (EI - BI < 20) { ISortCmp(BI, EI, Cmp); } else { const TVal Val = *GetPivotValNCmp(BI, EI, Cmp); TIter Split = PartitionCmp(BI, EI, Val, Cmp); QSortCmp(BI, Split, Cmp); QSortCmp(Split, EI, Cmp); } } }
void TGLib_OLD::TVec< TVal >::Reserve | ( | const int & | _MxVals | ) | [inline] |
void TGLib_OLD::TVec< TVal >::Reserve | ( | const int & | _MxVals, |
const int & | _Vals | ||
) | [inline] |
int TGLib_OLD::TVec< TVal >::Reserved | ( | ) | const [inline] |
Definition at line 1785 of file ds.h.
References Assert, TStr::CStr(), FailR, TStr::Fmt(), GetTypeNm(), and IAssertR.
Referenced by TGLib_OLD::TVec< ::TSize >::Add(), and TGLib_OLD::TVec< ::TSize >::Reserve().
{ IAssertR(MxVals!=-1, TStr::Fmt("Can not resize buffer. %s. [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", GetTypeNm(*this).CStr()).CStr()); if (_MxVals==-1){ if (Vals==0){MxVals=16;} else {MxVals*=2;} } else { if (_MxVals<=MxVals){return;} else {MxVals=_MxVals;} } if (ValT==NULL){ try {ValT=new TVal[MxVals];} catch (std::exception Ex){ FailR(TStr::Fmt("TVec::Resize 1: %s, Vals:%d, MxVals:%d, _MxVals:%d, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), Vals, MxVals, _MxVals, GetTypeNm(*this).CStr()).CStr());} } else { //if (Vals > 1000000) { // printf("%s resize %d -> %d\n", GetTypeNm(*this).CStr(), Vals, MxVals); } TVal* NewValT = NULL; try { NewValT=new TVal[MxVals];} catch (std::exception Ex){ FailR(TStr::Fmt("TVec::Resize 2: %s, Vals:%d, MxVals:%d, _MxVals:%d, Type:%s [Program failed to allocate more memory. Solution: Get a bigger machine and a 64-bit compiler.]", Ex.what(), Vals, MxVals, _MxVals, GetTypeNm(*this).CStr()).CStr());} Assert(NewValT!=NULL); for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];} delete[] ValT; ValT=NewValT; } }
void TGLib_OLD::TVec< TVal >::Reverse | ( | int | First, |
int | Last | ||
) | [inline] |
void TGLib_OLD::TVec< TVal >::SaveXml | ( | TSOut & | SOut, |
const TStr & | Nm | ||
) | const |
int TVec< TVal >::SearchBack | ( | const TVal & | Val | ) | const |
Definition at line 2399 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::IsInBin().
{ int LValN=0; int RValN=Len()-1; while (RValN>=LValN){ int ValN=(LValN+RValN)/2; if (Val==ValT[ValN]){return ValN;} if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;} } return -1; }
int TVec< TVal >::SearchForw | ( | const TVal & | Val, |
const int & | BValN = 0 |
||
) | const |
Definition at line 2421 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::GetAddDat(), TGLib_OLD::TVec< ::TSize >::GetDat(), and TGLib_OLD::TVec< ::TSize >::IsIn().
int TVec< TVal >::SearchVForw | ( | const TVec< TVal > & | ValV, |
const int & | BValN = 0 |
||
) | const |
Definition at line 2435 of file ds.h.
References TVec< TVal, TSizeTy >::Len().
{ int ValVLen=ValV.Len(); for (int ValN=BValN; ValN<Vals-ValVLen+1; ValN++){ bool Found=true; for (int SubValN=0; SubValN<ValVLen; SubValN++){ if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=false; break;} } if (Found){return ValN;} } return -1; }
Definition at line 2182 of file ds.h.
References TRnd::GetUniDevInt(), and Swap().
{ for (int ValN=0; ValN<Vals-1; ValN++){ Swap(ValN, ValN+Rnd.GetUniDevInt(Vals-ValN));} }
void TGLib_OLD::TVec< TVal >::SortCmp | ( | const TCmp & | Cmp | ) | [inline] |
Definition at line 1953 of file ds.h.
References TVec< TVal, TSizeTy >::MxVals, Swap(), TVec< TVal, TSizeTy >::Vals, and TVec< TVal, TSizeTy >::ValT.
Referenced by TGLib_OLD::TVec< ::TSize >::Reverse().
void TGLib_OLD::TVec< TVal >::Swap | ( | const int & | ValN1, |
const int & | ValN2 | ||
) | [inline] |
static void TGLib_OLD::TVec< TVal >::SwapI | ( | TIter | LVal, |
TIter | RVal | ||
) | [inline, static] |
Definition at line 1584 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::BSortCmp(), and TGLib_OLD::TVec< ::TSize >::PartitionCmp().
{ TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
const TVal& TGLib_OLD::TVec< TVal >::TopHeap | ( | ) | const [inline] |
Definition at line 1906 of file ds.h.
References IAssert.
{ IAssert(MxVals!=-1); IAssert((_Vals==-1)||(_Vals>=0)); if ((_Vals!=-1)&&(_Vals>=Vals)){ return; } else if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){ if (ValT!=NULL){delete[] ValT;} MxVals=Vals=0; ValT=NULL; } else { if (_Vals==-1){ if (MxVals==Vals){return;} else {MxVals=Vals;} } else { MxVals=Vals=_Vals; } TVal* NewValT=new TVal[MxVals]; IAssert(NewValT!=NULL); for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];} delete[] ValT; ValT=NewValT; } }
Definition at line 2255 of file ds.h.
{ TVec<TVal> UnionVec; Union(ValV, UnionVec); MoveFrom(UnionVec); }
void TVec< TVal >::Union | ( | const TVec< TVal > & | ValV, |
TVec< TVal > & | DstValV | ||
) | const |
Definition at line 2290 of file ds.h.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Gen(), TInt::GetMx(), TVec< TVal, TSizeTy >::GetVal(), and TVec< TVal, TSizeTy >::Len().
{ DstValV.Gen(TInt::GetMx(Len(), ValV.Len()), 0); int ValN1=0; int ValN2=0; while ((ValN1<Len())&&(ValN2<ValV.Len())){ const TVal& Val1=GetVal(ValN1); const TVal& Val2=ValV.GetVal(ValN2); if (Val1<Val2){DstValV.Add(Val1); ValN1++;} else if (Val1>Val2){DstValV.Add(Val2); ValN2++;} else {DstValV.Add(Val1); ValN1++; ValN2++;} } for (int RestValN1=ValN1; RestValN1<Len(); RestValN1++){ DstValV.Add(GetVal(RestValN1));} for (int RestValN2=ValN2; RestValN2<ValV.Len(); RestValN2++){ DstValV.Add(ValV.GetVal(RestValN2));} }
Returns the size of the union with vector ValV
. Method assumes both vectors are sorted in ascending order!
Definition at line 2368 of file ds.h.
References TVec< TVal, TSizeTy >::GetVal(), and TVec< TVal, TSizeTy >::Len().
{ int Cnt = 0, ValN1 = 0, ValN2 = 0; while ((ValN1 < Len()) && (ValN2 < ValV.Len())) { const TVal& Val1 = GetVal(ValN1); const TVal& Val2 = ValV.GetVal(ValN2); if (Val1 < Val2) { Cnt++; ValN1++; } else if (Val1 > Val2) { Cnt++; ValN2++; } else { Cnt++; ValN1++; ValN2++; } } Cnt += (Len() - ValN1) + (ValV.Len() - ValN2); return Cnt; }
int TGLib_OLD::TVec< TVal >::MxVals [protected] |
Definition at line 1481 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::Add(), TGLib_OLD::TVec< ::TSize >::Gen(), TGLib_OLD::TVec< ::TSize >::GenExt(), TGLib_OLD::TVec< ::TSize >::GetAddDat(), TGLib_OLD::TVec< ::TSize >::GetMemUsed(), TGLib_OLD::TVec< ::TSize >::IsExt(), TGLib_OLD::TVec< ::TSize >::Reserved(), TGLib_OLD::TVec< ::TSize >::TVec(), and TGLib_OLD::TVec< ::TSize >::~TVec().
int TGLib_OLD::TVec< TVal >::Vals [protected] |
Definition at line 1482 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::Add(), TGLib_OLD::TVec< ::TSize >::Empty(), TGLib_OLD::TVec< ::TSize >::EndI(), TGLib_OLD::TVec< ::TSize >::Gen(), TGLib_OLD::TVec< ::TSize >::GenExt(), TGLib_OLD::TVec< ::TSize >::LastLast(), TGLib_OLD::TVec< ::TSize >::Len(), TGLib_OLD::TVec< ::TSize >::operator[](), TGLib_OLD::TVec< ::TSize >::Reserve(), and TGLib_OLD::TVec< ::TSize >::TVec().
TVal* TGLib_OLD::TVec< TVal >::ValT [protected] |
Definition at line 1483 of file ds.h.
Referenced by TGLib_OLD::TVec< ::TSize >::Add(), TGLib_OLD::TVec< ::TSize >::AdjustHeap(), TGLib_OLD::TVec< ::TSize >::BegI(), TGLib_OLD::TVec< ::TSize >::EndI(), TGLib_OLD::TVec< ::TSize >::Gen(), TGLib_OLD::TVec< ::TSize >::GenExt(), TGLib_OLD::TVec< ::TSize >::GetI(), TGLib_OLD::TVec< ::TSize >::LastLast(), TGLib_OLD::TVec< ::TSize >::MakeHeap(), TGLib_OLD::TVec< ::TSize >::operator[](), TGLib_OLD::TVec< ::TSize >::PopHeap(), TGLib_OLD::TVec< ::TSize >::PushHeap(), TGLib_OLD::TVec< ::TSize >::Swap(), TGLib_OLD::TVec< ::TSize >::TopHeap(), TGLib_OLD::TVec< ::TSize >::TVec(), and TGLib_OLD::TVec< ::TSize >::~TVec().