|
SNAP Library 2.1, User 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] |
| 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 |
||
| ) |
| 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.
{
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] |
| static void TGLib_OLD::TVec< TVal >::BSortCmp | ( | TIter | BI, |
| TIter | EI, | ||
| const TCmp & | Cmp | ||
| ) | [inline, static] |
| void TGLib_OLD::TVec< TVal >::DelLast | ( | ) | [inline] |
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.
{
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] |
| TIter TGLib_OLD::TVec< TVal >::EndI | ( | ) | const [inline] |
| 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.
{
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.
{
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.
{
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.
{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.
{
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 |
Returns the size of the intersection (number of common elements) with vector ValV. Method assumes both vectors are sorted in ascending order!
| 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] |
| bool TGLib_OLD::TVec< TVal >::IsSortedCmp | ( | const TCmp & | Cmp | ) | const [inline] |
| const TVal& TGLib_OLD::TVec< TVal >::Last | ( | ) | const [inline] |
| 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] |
| 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.
{ MakeHeap(TLss<TVal>()); } // build a heap
| void TGLib_OLD::TVec< TVal >::MakeHeap | ( | const TCmp & | Cmp | ) | [inline] |
| void TGLib_OLD::TVec< TVal >::MakeHeap | ( | const int & | First, |
| const int & | Len, | ||
| const TCmp & | Cmp | ||
| ) | [inline] |
Definition at line 2269 of file ds.h.
{
TVec<TVal> MinusVec;
Minus(ValV, MinusVec);
MoveFrom(MinusVec);
}
Definition at line 2205 of file ds.h.
{
// 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] |
| const TVal& TGLib_OLD::TVec< TVal >::operator[] | ( | const int & | ValN | ) | const [inline] |
| 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.
{
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.
{ 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.
{
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.
{ 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.
{
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.
{
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 |
| int TVec< TVal >::SearchForw | ( | const TVal & | Val, |
| const int & | BValN = 0 |
||
| ) | const |
| int TVec< TVal >::SearchVForw | ( | const TVec< TVal > & | ValV, |
| const int & | BValN = 0 |
||
| ) | const |
Definition at line 2182 of file ds.h.
{
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] |
| 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] |
| const TVal& TGLib_OLD::TVec< TVal >::TopHeap | ( | ) | const [inline] |
Definition at line 1906 of file ds.h.
{
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.
{
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.
{
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] |
int TGLib_OLD::TVec< TVal >::Vals [protected] |
TVal* TGLib_OLD::TVec< TVal >::ValT [protected] |