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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TGLib_OLD::TVec< TVal > Class Template Reference

#include <ds.h>

Collaboration diagram for TGLib_OLD::TVec< TVal >:

List of all members.

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

Detailed Description

template<class TVal>
class TGLib_OLD::TVec< TVal >

Definition at line 1477 of file ds.h.


Member Typedef Documentation

template<class TVal>
typedef TVal* TGLib_OLD::TVec< TVal >::TIter

Definition at line 1479 of file ds.h.


Constructor & Destructor Documentation

template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( ) [inline]

Definition at line 1487 of file ds.h.

: MxVals(0), Vals(0), ValT(NULL){}
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( const TVec< TVal > &  Vec)
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( const int &  _Vals) [inline, explicit]

Definition at line 1489 of file ds.h.

                                 {
    IAssert(0<=_Vals); MxVals=Vals=_Vals;
    if (_Vals==0){ValT=NULL;} else {ValT=new TVal[_Vals];}}
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( const int &  _MxVals,
const int &  _Vals 
) [inline]

Definition at line 1492 of file ds.h.

                                            {
    IAssert((0<=_Vals)&&(_Vals<=_MxVals)); MxVals=_MxVals; Vals=_Vals;
    if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( TVal *  _ValT,
const int &  _Vals 
) [inline, explicit]

Definition at line 1495 of file ds.h.

                                              :
    MxVals(-1), Vals(_Vals), ValT(_ValT){}
template<class TVal>
TGLib_OLD::TVec< TVal >::~TVec ( ) [inline]

Definition at line 1497 of file ds.h.

{if ((ValT!=NULL) && (MxVals!=-1)){delete[] ValT;}}
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( TSIn SIn) [inline, explicit]

Definition at line 1498 of file ds.h.

: MxVals(0), Vals(0), ValT(NULL){Load(SIn);}

Member Function Documentation

template<class TVal>
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().

           {
    Assert(MxVals!=-1); if (Vals==MxVals){Resize();} return Vals++;}

Here is the caller graph for this function:

template<class TVal>
int TGLib_OLD::TVec< TVal >::Add ( const TVal &  Val) [inline]

Definition at line 1561 of file ds.h.

                          {
    Assert(MxVals!=-1); if (Vals==MxVals){Resize();} ValT[Vals]=Val; return Vals++;}
template<class TVal>
int TGLib_OLD::TVec< TVal >::Add ( const TVal &  Val,
const int &  ResizeLen 
) [inline]

Definition at line 1563 of file ds.h.

                                                {
    Assert(MxVals!=-1); if (Vals==MxVals){Resize(MxVals+ResizeLen);} ValT[Vals]=Val; return Vals++;}
template<class TVal>
int TVec< TVal >::AddBackSorted ( const TVal &  Val,
const bool &  Asc 
)

Definition at line 1984 of file ds.h.

References Assert.

                                                             {
  Assert(MxVals!=-1);
  Add();
  int ValN=Vals-2;
  while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
    ValT[ValN+1]=ValT[ValN]; ValN--;}
  ValT[ValN+1]=Val;
  return ValN+1;
}
template<class TVal>
int TVec< TVal >::AddMerged ( const TVal &  Val)

Definition at line 1995 of file ds.h.

References Assert.

                                        {
  Assert(MxVals!=-1);
  int ValN=SearchBin(Val);
  if (ValN==-1){return AddSorted(Val);}
  else {GetVal(ValN)=Val; return -1;}
}
template<class TVal>
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;
}

Here is the call graph for this function:

template<class TVal>
int TVec< TVal >::AddUnique ( const TVal &  Val)

Definition at line 2010 of file ds.h.

References Assert.

                                        {
  Assert(MxVals!=-1);
  int ValN=SearchForw(Val);
  if (ValN==-1){return Add(Val);}
  else {GetVal(ValN)=Val; return -1;}
}
template<class TVal>
int TVec< TVal >::AddV ( const TVec< TVal > &  ValV)

Definition at line 1962 of file ds.h.

References Assert, and TVec< TVal, TSizeTy >::Vals.

                                          {
  Assert(MxVals!=-1);
  for (int ValN=0; ValN<ValV.Vals; ValN++){Add(ValV[ValN]);}
  return Len();
}
template<class TVal>
int TVec< TVal >::AddVMerged ( const TVec< TVal > &  ValV)

Definition at line 2003 of file ds.h.

References Assert, and TVec< TVal, TSizeTy >::Vals.

                                                {
  Assert(MxVals!=-1);
  for (int ValN=0; ValN<ValV.Vals; ValN++){AddMerged(ValV[ValN]);}
  return Len();
}
template<class TVal>
template<class TCmp >
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);
  }

Here is the caller graph for this function:

template<class TVal>
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;}

Here is the caller graph for this function:

template<class TVal >
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);}
      }
    }
  }
}

Here is the call graph for this function:

template<class TVal>
template<class TCmp >
static void TGLib_OLD::TVec< TVal >::BSortCmp ( TIter  BI,
TIter  EI,
const TCmp Cmp 
) [inline, static]

Definition at line 1676 of file ds.h.

                                                            {
    for (TIter i = BI; i != EI; ++i) {
      for (TIter j = EI-1; j != i; --j) {
        if (Cmp(*j, *(j-1))) SwapI(j, j-1); }
    }
  }
template<class TVal >
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;
  }
}

Here is the caller graph for this function:

template<class TVal>
int TVec< TVal >::Count ( const TVal &  Val) const

Definition at line 2391 of file ds.h.

                                           {
  int Count = 0;
  for (int i = 0; i < Len(); i++){
    if (Val == ValT[i]){Count++;}}
  return Count;
}
template<class TVal >
void TVec< TVal >::Del ( const int &  ValN)

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();
}

Here is the caller graph for this function:

template<class TVal >
void TVec< TVal >::Del ( const int &  MnValN,
const int &  MxValN 
)

Definition at line 2046 of file ds.h.

References Assert.

                                                        {
  Assert(MxVals!=-1);
  Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
  Assert(MnValN<=MxValN);
  for (int ValN=MxValN+1; ValN<Vals; ValN++){
    ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
  for (int ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
    ValT[ValN]=TVal();}
  Vals-=MxValN-MnValN+1;
}
template<class TVal>
void TVec< TVal >::DelAll ( const TVal &  Val)

Definition at line 2066 of file ds.h.

References Assert.

                                      {
  Assert(MxVals!=-1);
  int ValN;
  while ((ValN=SearchForw(Val))!=-1){
    Del(ValN);}
}
template<class TVal>
bool TVec< TVal >::DelIfIn ( const TVal &  Val)

Definition at line 2058 of file ds.h.

References Assert.

                                       {
  Assert(MxVals!=-1);
  int ValN=SearchForw(Val);
  if (ValN!=-1){Del(ValN); return true;}
  else {return false;}
}
template<class TVal>
void TGLib_OLD::TVec< TVal >::DelLast ( ) [inline]

Definition at line 1577 of file ds.h.

Referenced by TGLib_OLD::TVec< ::TSize >::PopHeap().

{Del(Len()-1);}

Here is the caller graph for this function:

template<class TVal>
void TVec< TVal >::Diff ( const TVec< TVal > &  ValV)

Definition at line 2262 of file ds.h.

                                           {
  TVec<TVal> DiffVec;
  Diff(ValV, DiffVec);
  MoveFrom(DiffVec);
}
template<class TVal>
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));}
}

Here is the call graph for this function:

template<class TVal>
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;}

Here is the caller graph for this function:

template<class TVal>
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().

{return ValT+Vals;}

Here is the caller graph for this function:

template<class TVal>
void TGLib_OLD::TVec< TVal >::Gen ( const int &  _Vals) [inline]

Definition at line 1520 of file ds.h.

Referenced by TGLib_OLD::TVecPool< TVal >::TVecPool().

                            {
    IAssert(0<=_Vals);
    if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=Vals=_Vals;
    if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}}

Here is the caller graph for this function:

template<class TVal>
void TGLib_OLD::TVec< TVal >::Gen ( const int &  _MxVals,
const int &  _Vals 
) [inline]

Definition at line 1524 of file ds.h.

                                                {
    IAssert((0<=_Vals)&&(_Vals<=_MxVals));
    if (ValT!=NULL  && MxVals!=-1){delete[] ValT;} MxVals=_MxVals; Vals=_Vals;
    if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
template<class TVal>
void TGLib_OLD::TVec< TVal >::GenExt ( TVal *  _ValT,
const int &  _Vals 
) [inline]

Definition at line 1528 of file ds.h.

                                            {
    if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
    MxVals=-1; Vals=_Vals; ValT=_ValT;}
template<class TVal>
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);}}
template<class TVal>
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);}
template<class TVal>
TIter TGLib_OLD::TVec< TVal >::GetI ( const int &  ValN) const [inline]

Definition at line 1557 of file ds.h.

{return ValT+ValN;}
template<class TVal>
int TGLib_OLD::TVec< TVal >::GetMemUsed ( ) const [inline]

Definition at line 1514 of file ds.h.

                         {
    return int(2*sizeof(int)+sizeof(TVal*)+MxVals*sizeof(TVal));}
template<class TVal >
int TVec< TVal >::GetMxValN ( ) const

Definition at line 2448 of file ds.h.

                                {
  if (Vals==0){return -1;}
  int MxValN=0;
  for (int ValN=1; ValN<Vals; ValN++){
    if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
  }
  return MxValN;
}
template<class TVal >
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;}
  }
}

Here is the call graph for this function:

template<class TVal>
template<class TCmp >
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;
    }
  }

Here is the caller graph for this function:

template<class TVal >
int TVec< TVal >::GetPrimHashCd ( ) const

Definition at line 1880 of file ds.h.

                                    {
  int HashCd=0;
  for (int ValN=0; ValN<Vals; ValN++){
    HashCd+=ValT[ValN].GetPrimHashCd();}
  return abs(HashCd);
}
template<class TVal >
int TVec< TVal >::GetSecHashCd ( ) const

Definition at line 1888 of file ds.h.

                                   {
  int HashCd=0;
  for (int ValN=0; ValN<Vals; ValN++){
    HashCd+=ValT[ValN].GetSecHashCd();}
  return abs(HashCd);
}
template<class TVal>
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));}
}

Here is the call graph for this function:

template<class TVal>
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;}
template<class TVal>
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;}
template<class TVal>
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;}
template<class TVal>
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;}
template<class TVal>
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;}
template<class TVal>
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;}
template<class TVal>
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;}
template<class TVal>
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;}
template<class TVal>
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;}
template<class TVal>
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);}

Here is the caller graph for this function:

template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::GetVal ( const int &  ValN) [inline]

Definition at line 1572 of file ds.h.

{return operator[](ValN);}
template<class TVal >
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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal>
void TVec< TVal >::Ins ( const int &  ValN,
const TVal &  Val 
)

Definition at line 2029 of file ds.h.

References Assert.

                                                    {
  Assert(MxVals!=-1);
  Add(); Assert((0<=ValN)&&(ValN<Vals));
  for (int MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
  ValT[ValN]=Val;
}
template<class TVal>
void TVec< TVal >::Intrs ( const TVec< TVal > &  ValV)

Definition at line 2248 of file ds.h.

                                            {
  TVec<TVal> IntrsVec;
  Intrs(ValV, IntrsVec);
  MoveFrom(IntrsVec);
}
template<class TVal>
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++;
  }
}

Here is the call graph for this function:

template<class TVal>
int TVec< TVal >::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!

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;
}

Here is the call graph for this function:

template<class TVal>
bool TGLib_OLD::TVec< TVal >::IsExt ( ) const [inline]

Definition at line 1531 of file ds.h.

{return MxVals==-1;}
template<class TVal>
bool TGLib_OLD::TVec< TVal >::IsIn ( const TVal &  Val) const [inline]

Definition at line 1747 of file ds.h.

{return SearchForw(Val)!=-1;}
template<class TVal>
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;}
template<class TVal>
bool TGLib_OLD::TVec< TVal >::IsInBin ( const TVal &  Val) const [inline]

Definition at line 1750 of file ds.h.

{return SearchBin(Val)!=-1;}
template<class TVal >
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;
    }
  }
}
template<class TVal>
template<class TCmp >
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;
      }
    }
  }

Here is the caller graph for this function:

template<class TVal >
bool TVec< TVal >::IsSorted ( const bool &  Asc = true) const

Definition at line 2170 of file ds.h.

                                               {
  if (Asc){
    for (int ValN=0; ValN<Vals-1; ValN++){
      if (ValT[ValN]>ValT[ValN+1]){return false;}}
  } else {
    for (int ValN=0; ValN<Vals-1; ValN++){
      if (ValT[ValN]<ValT[ValN+1]){return false;}}
  }
  return true;
}
template<class TVal>
template<class TCmp >
bool TGLib_OLD::TVec< TVal >::IsSortedCmp ( const TCmp Cmp) const [inline]

Definition at line 1721 of file ds.h.

                                          {
    if (EndI() == BegI()) return true;
    for (TIter i = BegI(); i != EndI()-1; ++i) {
      if (Cmp(*(i+1), *i)){return false;}}
    return true;
  }
template<class TVal>
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().

{return GetVal(Len()-1);}

Here is the caller graph for this function:

template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::Last ( ) [inline]

Definition at line 1546 of file ds.h.

{return GetVal(Len()-1);}
template<class TVal>
const TVal& TGLib_OLD::TVec< TVal >::LastLast ( ) const [inline]

Definition at line 1548 of file ds.h.

template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::LastLast ( ) [inline]

Definition at line 1551 of file ds.h.

template<class TVal>
int TGLib_OLD::TVec< TVal >::LastValN ( ) const [inline]

Definition at line 1547 of file ds.h.

{return Len()-1;}
template<class TVal >
void TVec< TVal >::Load ( TSIn SIn)

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);}
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal>
void TGLib_OLD::TVec< TVal >::LoadXml ( const PXmlTok XmlTok,
const TStr Nm = "" 
)
template<class TVal>
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

Here is the caller graph for this function:

template<class TVal>
template<class TCmp >
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().

{ MakeHeap(0, Len(), Cmp); }

Here is the caller graph for this function:

template<class TVal>
template<class TCmp >
void TGLib_OLD::TVec< TVal >::MakeHeap ( const int &  First,
const int &  Len,
const TCmp Cmp 
) [inline]

Definition at line 1635 of file ds.h.

                                                                   {
    if (Len < 2) { return; }
    int Parent = (Len-2)/2;
    while (true) {
      AdjustHeap(First, Parent, Len, ValT[First+Parent], Cmp);
      if (Parent == 0) { return; }  Parent--; }
  }
template<class TVal >
void TVec< TVal >::Merge ( )

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]);}
  }
}

Here is the call graph for this function:

template<class TVal>
void TVec< TVal >::Minus ( const TVec< TVal > &  ValV)

Definition at line 2269 of file ds.h.

                                            {
  TVec<TVal> MinusVec;
  Minus(ValV, MinusVec);
  MoveFrom(MinusVec);
}
template<class TVal>
void TVec< TVal >::Minus ( const TVec< TVal > &  ValV,
TVec< TVal > &  DstValV 
) const

Definition at line 2386 of file ds.h.

                                                                        {
  Diff(ValV, DstValV);
}
template<class TVal>
void TVec< TVal >::MoveFrom ( TVec< TVal > &  Vec)

Definition at line 1944 of file ds.h.

References TVec< TVal, TSizeTy >::MxVals, TVec< TVal, TSizeTy >::Vals, and TVec< TVal, TSizeTy >::ValT.

                                        {
  if (this!=&Vec){
    if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
    MxVals=Vec.MxVals; Vals=Vec.Vals; ValT=Vec.ValT;
    Vec.MxVals=0; Vec.Vals=0; Vec.ValT=NULL;
  }
}
template<class TVal >
bool TVec< TVal >::NextPerm ( )

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;
    }
  }
}

Here is the call graph for this function:

template<class TVal>
TVec<TVal>& TGLib_OLD::TVec< TVal >::operator+ ( const TVal &  Val) [inline]

Definition at line 1505 of file ds.h.

{Add(Val); return *this;}
template<class TVal>
bool TVec< TVal >::operator< ( const TVec< TVal > &  Vec) const

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();
  }
}

Here is the call graph for this function:

template<class TVal>
TVec< TVal > & TVec< TVal >::operator= ( const TVec< TVal > &  Vec)

Definition at line 1845 of file ds.h.

References TVec< TVal, TSizeTy >::Vals, and TVec< TVal, TSizeTy >::ValT.

                                                      {
  if (this!=&Vec){
    if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
    MxVals=Vals=Vec.Vals;
    if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
    for (int ValN=0; ValN<Vec.Vals; ValN++){ValT[ValN]=Vec.ValT[ValN];}
  }
  return *this;
}
template<class TVal>
bool TVec< TVal >::operator== ( const TVec< TVal > &  Vec) const

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;
}

Here is the call graph for this function:

template<class TVal>
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];}

Here is the caller graph for this function:

template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::operator[] ( const int &  ValN) [inline]

Definition at line 1511 of file ds.h.

                                   {
    AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
    return ValT[ValN];}
template<class TVal >
void TVec< TVal >::Pack ( )

Definition at line 1929 of file ds.h.

References IAssert.

                     {
  IAssert(MxVals!=-1);
  if (Vals==0){
    if (ValT!=NULL){delete[] ValT;} ValT=NULL;
  } else
  if (Vals<MxVals){
    MxVals=Vals;
    TVal* NewValT=new TVal[MxVals];
    IAssert(NewValT!=NULL);
    for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
    delete[] ValT; ValT=NewValT;
  }
}
template<class TVal >
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;}
  };
}

Here is the call graph for this function:

template<class TVal>
template<class TCmp >
static TIter TGLib_OLD::TVec< TVal >::PartitionCmp ( TIter  BI,
TIter  EI,
const TVal  Pivot,
const TCmp Cmp 
) [inline, static]

Definition at line 1664 of file ds.h.

Referenced by TGLib_OLD::TVec< ::TSize >::QSortCmp().

                                                                                   {
    forever {
      while (Cmp(*BI, Pivot)) ++BI;
      --EI;
      while (Cmp(Pivot, *EI)) --EI;
      if (!(BI < EI)) return BI;
      SwapI(BI, EI);
      ++BI;
    }
  }

Here is the caller graph for this function:

template<class TVal>
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

Here is the caller graph for this function:

template<class TVal>
template<class TCmp >
TVal TGLib_OLD::TVec< TVal >::PopHeap ( const TCmp Cmp) [inline]

Definition at line 1610 of file ds.h.

                                                      { IAssert(! Empty()); const TVal Top=ValT[0];
    ValT[0]=Last(); DelLast(); if (! Empty()) { AdjustHeap(0, 0, Len(), ValT[0], Cmp); } return Top; }
template<class TVal >
bool TVec< TVal >::PrevPerm ( )

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;
    }
  }
}

Here is the call graph for this function:

template<class TVal>
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

Here is the caller graph for this function:

template<class TVal>
template<class TCmp >
void TGLib_OLD::TVec< TVal >::PushHeap ( const TVal &  Val,
const TCmp Cmp 
) [inline]

Definition at line 1609 of file ds.h.

Referenced by TGLib_OLD::TVec< ::TSize >::PushHeap().

{ Add(Val); PushHeap(0, Len()-1, 0, Val, Cmp); }

Here is the caller graph for this function:

template<class TVal>
template<class TCmp >
void TGLib_OLD::TVec< TVal >::PushHeap ( const int &  First,
int  HoleIdx,
const int &  Top,
TVal  Val,
const TCmp Cmp 
) [inline]

Definition at line 1614 of file ds.h.

                                                                                          {
    int Parent = (HoleIdx-1)/2;
    while (HoleIdx > Top && Cmp(ValT[First+Parent], Val)) {
      ValT[First+HoleIdx] = ValT[First+Parent];
      HoleIdx = Parent;  Parent = (HoleIdx-1)/2; }
    ValT[First+HoleIdx] = Val;
  }
template<class TVal>
void TVec< TVal >::PutAll ( const TVal &  Val)

Definition at line 2074 of file ds.h.

                                      {
  for (int ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
}
template<class TVal >
void TVec< TVal >::QSort ( const int &  MnLValN,
const int &  MxRValN,
const bool &  Asc 
)

Definition at line 2151 of file ds.h.

                                                         {
  if (MnLValN<MxRValN){
    if (MxRValN-MnLValN<20){
      ISort(MnLValN, MxRValN, Asc);
    } else {
      int SplitValN=Partition(MnLValN, MxRValN, Asc);
      QSort(MnLValN, SplitValN, Asc);
      QSort(SplitValN+1, MxRValN, Asc);
    }
  }
}
template<class TVal>
template<class TCmp >
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);
      }
    }
  }

Here is the caller graph for this function:

template<class TVal>
void TGLib_OLD::TVec< TVal >::Reserve ( const int &  _MxVals) [inline]

Definition at line 1532 of file ds.h.

{Resize(_MxVals);}
template<class TVal>
void TGLib_OLD::TVec< TVal >::Reserve ( const int &  _MxVals,
const int &  _Vals 
) [inline]

Definition at line 1533 of file ds.h.

                                                    {
    IAssert((0<=_Vals)&&(_Vals<=_MxVals));
    Resize(_MxVals); Vals=_Vals;}
template<class TVal>
int TGLib_OLD::TVec< TVal >::Reserved ( ) const [inline]

Definition at line 1544 of file ds.h.

{return MxVals;}
template<class TVal >
void TVec< TVal >::Resize ( const int &  _MxVals = -1) [protected]

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;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal >
void TVec< TVal >::Reverse ( )

Definition at line 2188 of file ds.h.

References Swap().

                        {
  for (int ValN=0; ValN<Vals/2; ValN++){
    Swap(ValN, Vals-ValN-1);}
}

Here is the call graph for this function:

template<class TVal>
void TGLib_OLD::TVec< TVal >::Reverse ( int  First,
int  Last 
) [inline]

Definition at line 1596 of file ds.h.

                                   {
    Last--; while (First < Last){Swap(First++, Last--);}}
template<class TVal >
void TVec< TVal >::Save ( TSOut SOut) const

Definition at line 1838 of file ds.h.

References TSOut::Save().

                                       {
  if (MxVals!=-1){SOut.Save(MxVals);} else {SOut.Save(Vals);}
  SOut.Save(Vals);
  for (int ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
}

Here is the call graph for this function:

template<class TVal>
void TGLib_OLD::TVec< TVal >::SaveXml ( TSOut SOut,
const TStr Nm 
) const
template<class TVal>
int TVec< TVal >::SearchBack ( const TVal &  Val) const

Definition at line 2428 of file ds.h.

                                                {
  for (int ValN=Vals-1; ValN>=0; ValN--){
    if (Val==ValT[ValN]){return ValN;}}
  return -1;
}
template<class TVal>
int TVec< TVal >::SearchBin ( 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;
}

Here is the caller graph for this function:

template<class TVal>
int TVec< TVal >::SearchBin ( const TVal &  Val,
int &  InsValN 
) const

Definition at line 2410 of file ds.h.

                                                             {
  int LValN=0; int RValN=Len()-1;
  while (RValN>=LValN){
    int ValN=(LValN+RValN)/2;
    if (Val==ValT[ValN]){InsValN=ValN; return ValN;}
    if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
  }
  InsValN=LValN; return -1;
}
template<class TVal>
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().

                                                                  {
  for (int ValN=BValN; ValN<Vals; ValN++){
    if (Val==ValT[ValN]){return ValN;}}
  return -1;
}

Here is the caller graph for this function:

template<class TVal>
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;
}

Here is the call graph for this function:

template<class TVal >
void TVec< TVal >::Shuffle ( TRnd Rnd)

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));}
}

Here is the call graph for this function:

template<class TVal >
void TVec< TVal >::Sort ( const bool &  Asc = true)

Definition at line 2165 of file ds.h.

                                    {
  QSort(0, Len()-1, Asc);
}
template<class TVal>
template<class TCmp >
void TGLib_OLD::TVec< TVal >::SortCmp ( const TCmp Cmp) [inline]

Definition at line 1713 of file ds.h.

                               {
    QSortCmp(BegI(), EndI(), Cmp);}
template<class TVal>
void TVec< TVal >::Swap ( TVec< TVal > &  Vec)

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().

                                    {
  if (this!=&Vec){
    ::Swap(MxVals, Vec.MxVals);
    ::Swap(Vals, Vec.Vals);
    ::Swap(ValT, Vec.ValT);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal>
void TGLib_OLD::TVec< TVal >::Swap ( const int &  ValN1,
const int &  ValN2 
) [inline]

Definition at line 1582 of file ds.h.

                                               {
    TVal Val=ValT[ValN1]; ValT[ValN1]=ValT[ValN2]; ValT[ValN2]=Val;}
template<class TVal>
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;}

Here is the caller graph for this function:

template<class TVal>
const TVal& TGLib_OLD::TVec< TVal >::TopHeap ( ) const [inline]

Definition at line 1606 of file ds.h.

{ return ValT[0]; }                 // get largest element
template<class TVal >
void TVec< TVal >::Trunc ( const int &  _Vals = -1)

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;
  }
}
template<class TVal>
void TVec< TVal >::Union ( const TVec< TVal > &  ValV)

Definition at line 2255 of file ds.h.

                                            {
  TVec<TVal> UnionVec;
  Union(ValV, UnionVec);
  MoveFrom(UnionVec);
}
template<class TVal>
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));}
}

Here is the call graph for this function:

template<class TVal>
int TVec< TVal >::UnionLen ( const TVec< TVal > &  ValV) const

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;
}

Here is the call graph for this function:


Member Data Documentation


The documentation for this class was generated from the following file: