SNAP Library 2.3, User Reference  2014-06-16 11:58:46
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGLib_OLD::TVec< TVal > Class Template Reference

#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! More...
 
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! More...
 
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 1481 of file ds.h.

Member Typedef Documentation

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

Definition at line 1483 of file ds.h.

Constructor & Destructor Documentation

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

Definition at line 1491 of file ds.h.

1491 : MxVals(0), Vals(0), ValT(NULL){}
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( const TVec< TVal > &  Vec)
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( const int &  _Vals)
inlineexplicit

Definition at line 1493 of file ds.h.

1493  {
1494  IAssert(0<=_Vals); MxVals=Vals=_Vals;
1495  if (_Vals==0){ValT=NULL;} else {ValT=new TVal[_Vals];}}
#define IAssert(Cond)
Definition: bd.h:262
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( const int &  _MxVals,
const int &  _Vals 
)
inline

Definition at line 1496 of file ds.h.

1496  {
1497  IAssert((0<=_Vals)&&(_Vals<=_MxVals)); MxVals=_MxVals; Vals=_Vals;
1498  if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
#define IAssert(Cond)
Definition: bd.h:262
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( TVal *  _ValT,
const int &  _Vals 
)
inlineexplicit

Definition at line 1499 of file ds.h.

1499  :
1500  MxVals(-1), Vals(_Vals), ValT(_ValT){}
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
TGLib_OLD::TVec< TVal >::~TVec ( )
inline

Definition at line 1501 of file ds.h.

1501 {if ((ValT!=NULL) && (MxVals!=-1)){delete[] ValT;}}
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
template<class TVal>
TGLib_OLD::TVec< TVal >::TVec ( TSIn SIn)
inlineexplicit

Definition at line 1502 of file ds.h.

1502 : MxVals(0), Vals(0), ValT(NULL){Load(SIn);}
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
void Load(TSIn &SIn)
Definition: ds.h:1837

Member Function Documentation

template<class TVal>
int TGLib_OLD::TVec< TVal >::Add ( )
inline

Definition at line 1563 of file ds.h.

1563  {
1564  Assert(MxVals!=-1); if (Vals==MxVals){Resize();} return Vals++;}
int MxVals
Definition: ds.h:1485
int Vals
Definition: ds.h:1486
#define Assert(Cond)
Definition: bd.h:251
void Resize(const int &_MxVals=-1)
Definition: ds.h:1789
template<class TVal>
int TGLib_OLD::TVec< TVal >::Add ( const TVal &  Val)
inline

Definition at line 1565 of file ds.h.

1565  {
1566  Assert(MxVals!=-1); if (Vals==MxVals){Resize();} ValT[Vals]=Val; return Vals++;}
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define Assert(Cond)
Definition: bd.h:251
void Resize(const int &_MxVals=-1)
Definition: ds.h:1789
template<class TVal>
int TGLib_OLD::TVec< TVal >::Add ( const TVal &  Val,
const int &  ResizeLen 
)
inline

Definition at line 1567 of file ds.h.

1567  {
1568  Assert(MxVals!=-1); if (Vals==MxVals){Resize(MxVals+ResizeLen);} ValT[Vals]=Val; return Vals++;}
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define Assert(Cond)
Definition: bd.h:251
void Resize(const int &_MxVals=-1)
Definition: ds.h:1789
template<class TVal>
int TVec< TVal >::AddBackSorted ( const TVal &  Val,
const bool &  Asc 
)

Definition at line 1992 of file ds.h.

1992  {
1993  Assert(MxVals!=-1);
1994  Add();
1995  int ValN=Vals-2;
1996  while ((ValN>=0)&&((Asc&&(Val<ValT[ValN]))||(!Asc&&(Val>ValT[ValN])))){
1997  ValT[ValN+1]=ValT[ValN]; ValN--;}
1998  ValT[ValN+1]=Val;
1999  return ValN+1;
2000 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define Assert(Cond)
Definition: bd.h:251
int Add()
Definition: ds.h:1563
template<class TVal>
int TVec< TVal >::AddMerged ( const TVal &  Val)

Definition at line 2003 of file ds.h.

2003  {
2004  Assert(MxVals!=-1);
2005  int ValN=SearchBin(Val);
2006  if (ValN==-1){return AddSorted(Val);}
2007  else {GetVal(ValN)=Val; return -1;}
2008 }
int MxVals
Definition: ds.h:1485
int AddSorted(const TVal &Val, const bool &Asc=true, const int &_MxVals=-1)
Definition: ds.h:1977
#define Assert(Cond)
Definition: bd.h:251
int SearchBin(const TVal &Val) const
Definition: ds.h:2407
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
template<class TVal>
int TVec< TVal >::AddSorted ( const TVal &  Val,
const bool &  Asc = true,
const int &  _MxVals = -1 
)

Definition at line 1977 of file ds.h.

1977  {
1978  Assert(MxVals!=-1);
1979  int ValN=Add(Val);
1980  if (Asc){
1981  while ((ValN>0)&&(ValT[ValN]<ValT[ValN-1])){
1982  Swap(ValN, ValN-1); ValN--;}
1983  } else {
1984  while ((ValN>0)&&(ValT[ValN]>ValT[ValN-1])){
1985  Swap(ValN, ValN-1); ValN--;}
1986  }
1987  if ((_MxVals!=-1)&&(Len()>_MxVals)){Del(_MxVals, Len()-1);}
1988  return ValN;
1989 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
void Del(const int &ValN)
Definition: ds.h:2045
#define Assert(Cond)
Definition: bd.h:251
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
int Len() const
Definition: ds.h:1547
int Add()
Definition: ds.h:1563
template<class TVal>
int TVec< TVal >::AddUnique ( const TVal &  Val)

Definition at line 2018 of file ds.h.

2018  {
2019  Assert(MxVals!=-1);
2020  int ValN=SearchForw(Val);
2021  if (ValN==-1){return Add(Val);}
2022  else {GetVal(ValN)=Val; return -1;}
2023 }
int MxVals
Definition: ds.h:1485
int SearchForw(const TVal &Val, const int &BValN=0) const
Definition: ds.h:2429
#define Assert(Cond)
Definition: bd.h:251
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Add()
Definition: ds.h:1563
template<class TVal>
int TVec< TVal >::AddV ( const TVec< TVal > &  ValV)

Definition at line 1970 of file ds.h.

1970  {
1971  Assert(MxVals!=-1);
1972  for (int ValN=0; ValN<ValV.Vals; ValN++){Add(ValV[ValN]);}
1973  return Len();
1974 }
int MxVals
Definition: ds.h:1485
#define Assert(Cond)
Definition: bd.h:251
TSizeTy Vals
Vector length. Length is the number of elements stored in the vector.
Definition: ds.h:425
int Len() const
Definition: ds.h:1547
int Add()
Definition: ds.h:1563
template<class TVal>
int TVec< TVal >::AddVMerged ( const TVec< TVal > &  ValV)

Definition at line 2011 of file ds.h.

2011  {
2012  Assert(MxVals!=-1);
2013  for (int ValN=0; ValN<ValV.Vals; ValN++){AddMerged(ValV[ValN]);}
2014  return Len();
2015 }
int AddMerged(const TVal &Val)
Definition: ds.h:2003
int MxVals
Definition: ds.h:1485
#define Assert(Cond)
Definition: bd.h:251
TSizeTy Vals
Vector length. Length is the number of elements stored in the vector.
Definition: ds.h:425
int Len() const
Definition: ds.h:1547
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 1626 of file ds.h.

1626  {
1627  const int Top = HoleIdx;
1628  int Right = 2*HoleIdx+2;
1629  while (Right < Len) {
1630  if (Cmp(ValT[First+Right], ValT[First+Right-1])) { Right--; }
1631  ValT[First+HoleIdx] = ValT[First+Right];
1632  HoleIdx = Right; Right = 2*(Right+1); }
1633  if (Right == Len) {
1634  ValT[First+HoleIdx] = ValT[First+Right-1];
1635  HoleIdx = Right-1; }
1636  PushHeap(First, HoleIdx, Top, Val, Cmp);
1637  }
TVal * ValT
Definition: ds.h:1487
void PushHeap(const TVal &Val)
Definition: ds.h:1609
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
Definition: bd.h:426
int Len() const
Definition: ds.h:1547
template<class TVal>
TIter TGLib_OLD::TVec< TVal >::BegI ( ) const
inline

Definition at line 1559 of file ds.h.

1559 {return ValT;}
TVal * ValT
Definition: ds.h:1487
template<class TVal >
void TVec< TVal >::BSort ( const int &  MnLValN,
const int &  MxRValN,
const bool &  Asc 
)

Definition at line 2087 of file ds.h.

2088  {
2089  for (int ValN1=MnLValN; ValN1<=MxRValN; ValN1++){
2090  for (int ValN2=MxRValN; ValN2>ValN1; ValN2--){
2091  if (Asc){
2092  if (ValT[ValN2]<ValT[ValN2-1]){Swap(ValN2, ValN2-1);}
2093  } else {
2094  if (ValT[ValN2]>ValT[ValN2-1]){Swap(ValN2, ValN2-1);}
2095  }
2096  }
2097  }
2098 }
TVal * ValT
Definition: ds.h:1487
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
template<class TVal>
template<class TCmp >
static void TGLib_OLD::TVec< TVal >::BSortCmp ( TIter  BI,
TIter  EI,
const TCmp Cmp 
)
inlinestatic

Definition at line 1680 of file ds.h.

1680  {
1681  for (TIter i = BI; i != EI; ++i) {
1682  for (TIter j = EI-1; j != i; --j) {
1683  if (Cmp(*j, *(j-1))) SwapI(j, j-1); }
1684  }
1685  }
static void SwapI(TIter LVal, TIter RVal)
Definition: ds.h:1588
TVal * TIter
Definition: ds.h:1483
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
Definition: bd.h:426
template<class TVal >
void TVec< TVal >::Clr ( const bool &  DoDel = true,
const int &  NoDelLim = -1 
)

Definition at line 1904 of file ds.h.

1904  {
1905  if ((DoDel)||((!DoDel)&&(NoDelLim!=-1)&&(MxVals>NoDelLim))){
1906  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
1907  MxVals=Vals=0; ValT=NULL;
1908  } else {
1909  IAssert(MxVals!=-1); Vals=0;
1910  }
1911 }
#define IAssert(Cond)
Definition: bd.h:262
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
int TVec< TVal >::Count ( const TVal &  Val) const

Definition at line 2399 of file ds.h.

2399  {
2400  int Count = 0;
2401  for (int i = 0; i < Len(); i++){
2402  if (Val == ValT[i]){Count++;}}
2403  return Count;
2404 }
TVal * ValT
Definition: ds.h:1487
int Len() const
Definition: ds.h:1547
int Count(const TVal &Val) const
Definition: ds.h:2399
template<class TVal >
void TVec< TVal >::Del ( const int &  ValN)

Definition at line 2045 of file ds.h.

2045  {
2046  Assert(MxVals!=-1);
2047  Assert((0<=ValN)&&(ValN<Vals));
2048  for (int MValN=ValN+1; MValN<Vals; MValN++){
2049  ValT[MValN-1]=ValT[MValN];}
2050  ValT[--Vals]=TVal();
2051 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define Assert(Cond)
Definition: bd.h:251
template<class TVal >
void TVec< TVal >::Del ( const int &  MnValN,
const int &  MxValN 
)

Definition at line 2054 of file ds.h.

2054  {
2055  Assert(MxVals!=-1);
2056  Assert((0<=MnValN)&&(MnValN<Vals)&&(0<=MxValN)&&(MxValN<Vals));
2057  Assert(MnValN<=MxValN);
2058  for (int ValN=MxValN+1; ValN<Vals; ValN++){
2059  ValT[MnValN+ValN-MxValN-1]=ValT[ValN];}
2060  for (int ValN=Vals-MxValN+MnValN-1; ValN<Vals; ValN++){
2061  ValT[ValN]=TVal();}
2062  Vals-=MxValN-MnValN+1;
2063 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define Assert(Cond)
Definition: bd.h:251
template<class TVal>
void TVec< TVal >::DelAll ( const TVal &  Val)

Definition at line 2074 of file ds.h.

2074  {
2075  Assert(MxVals!=-1);
2076  int ValN;
2077  while ((ValN=SearchForw(Val))!=-1){
2078  Del(ValN);}
2079 }
int MxVals
Definition: ds.h:1485
int SearchForw(const TVal &Val, const int &BValN=0) const
Definition: ds.h:2429
void Del(const int &ValN)
Definition: ds.h:2045
#define Assert(Cond)
Definition: bd.h:251
template<class TVal>
bool TVec< TVal >::DelIfIn ( const TVal &  Val)

Definition at line 2066 of file ds.h.

2066  {
2067  Assert(MxVals!=-1);
2068  int ValN=SearchForw(Val);
2069  if (ValN!=-1){Del(ValN); return true;}
2070  else {return false;}
2071 }
int MxVals
Definition: ds.h:1485
int SearchForw(const TVal &Val, const int &BValN=0) const
Definition: ds.h:2429
void Del(const int &ValN)
Definition: ds.h:2045
#define Assert(Cond)
Definition: bd.h:251
template<class TVal>
void TGLib_OLD::TVec< TVal >::DelLast ( )
inline

Definition at line 1581 of file ds.h.

1581 {Del(Len()-1);}
void Del(const int &ValN)
Definition: ds.h:2045
int Len() const
Definition: ds.h:1547
template<class TVal>
void TVec< TVal >::Diff ( const TVec< TVal > &  ValV)

Definition at line 2270 of file ds.h.

2270  {
2271  TVec<TVal> DiffVec;
2272  Diff(ValV, DiffVec);
2273  MoveFrom(DiffVec);
2274 }
void Diff(const TVec< TVal > &ValV)
Definition: ds.h:2270
void MoveFrom(TVec< TVal > &Vec)
Definition: ds.h:1952
template<class TVal>
void TVec< TVal >::Diff ( const TVec< TVal > &  ValV,
TVec< TVal > &  DstValV 
) const

Definition at line 2346 of file ds.h.

2346  {
2347  DstValV.Clr();
2348  int ValN1=0; int ValN2=0;
2349  while (ValN1<Len() && ValN2<ValV.Len()) {
2350  const TVal& Val1 = GetVal(ValN1);
2351  while (ValN2<ValV.Len() && Val1>ValV.GetVal(ValN2)) ValN2++;
2352  if (ValN2<ValV.Len()) {
2353  if (Val1!=ValV.GetVal(ValN2)) { DstValV.Add(Val1); }
2354  ValN1++;
2355  }
2356  }
2357  for (int RestValN1=ValN1; RestValN1<Len(); RestValN1++){
2358  DstValV.Add(GetVal(RestValN1));}
2359 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:595
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
template<class TVal>
bool TGLib_OLD::TVec< TVal >::Empty ( ) const
inline

Definition at line 1546 of file ds.h.

1546 {return Vals==0;}
int Vals
Definition: ds.h:1486
template<class TVal>
TIter TGLib_OLD::TVec< TVal >::EndI ( ) const
inline

Definition at line 1560 of file ds.h.

1560 {return ValT+Vals;}
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
void TGLib_OLD::TVec< TVal >::Gen ( const int &  _Vals)
inline

Definition at line 1524 of file ds.h.

1524  {
1525  IAssert(0<=_Vals);
1526  if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=Vals=_Vals;
1527  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}}
#define IAssert(Cond)
Definition: bd.h:262
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
void TGLib_OLD::TVec< TVal >::Gen ( const int &  _MxVals,
const int &  _Vals 
)
inline

Definition at line 1528 of file ds.h.

1528  {
1529  IAssert((0<=_Vals)&&(_Vals<=_MxVals));
1530  if (ValT!=NULL && MxVals!=-1){delete[] ValT;} MxVals=_MxVals; Vals=_Vals;
1531  if (_MxVals==0){ValT=NULL;} else {ValT=new TVal[_MxVals];}}
#define IAssert(Cond)
Definition: bd.h:262
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
void TGLib_OLD::TVec< TVal >::GenExt ( TVal *  _ValT,
const int &  _Vals 
)
inline

Definition at line 1532 of file ds.h.

1532  {
1533  if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
1534  MxVals=-1; Vals=_Vals; ValT=_ValT;}
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::GetAddDat ( const TVal &  Val)
inline

Definition at line 1759 of file ds.h.

1759  {
1760  Assert(MxVals!=-1);
1761  int ValN=SearchForw(Val);
1762  if (ValN==-1){Add(Val); return Last();}
1763  else {return operator[](ValN);}}
int MxVals
Definition: ds.h:1485
int SearchForw(const TVal &Val, const int &BValN=0) const
Definition: ds.h:2429
#define Assert(Cond)
Definition: bd.h:251
const TVal & operator[](const int &ValN) const
Definition: ds.h:1512
const TVal & Last() const
Definition: ds.h:1549
int Add()
Definition: ds.h:1563
template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::GetDat ( const TVal &  Val) const
inline

Definition at line 1756 of file ds.h.

1756  {
1757  int ValN=SearchForw(Val);
1758  return operator[](ValN);}
int SearchForw(const TVal &Val, const int &BValN=0) const
Definition: ds.h:2429
const TVal & operator[](const int &ValN) const
Definition: ds.h:1512
template<class TVal>
TIter TGLib_OLD::TVec< TVal >::GetI ( const int &  ValN) const
inline

Definition at line 1561 of file ds.h.

1561 {return ValT+ValN;}
TVal * ValT
Definition: ds.h:1487
template<class TVal>
int TGLib_OLD::TVec< TVal >::GetMemUsed ( ) const
inline

Definition at line 1518 of file ds.h.

1518  {
1519  return int(2*sizeof(int)+sizeof(TVal*)+MxVals*sizeof(TVal));}
int MxVals
Definition: ds.h:1485
template<class TVal >
int TVec< TVal >::GetMxValN ( ) const

Definition at line 2456 of file ds.h.

2456  {
2457  if (Vals==0){return -1;}
2458  int MxValN=0;
2459  for (int ValN=1; ValN<Vals; ValN++){
2460  if (ValT[ValN]>ValT[MxValN]){MxValN=ValN;}
2461  }
2462  return MxValN;
2463 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal >
int TVec< TVal >::GetPivotValN ( const int &  LValN,
const int &  RValN 
) const

Definition at line 2119 of file ds.h.

2119  {
2120  int SubVals=RValN-LValN+1;
2121  int ValN1=LValN+TInt::GetRnd(SubVals);
2122  int ValN2=LValN+TInt::GetRnd(SubVals);
2123  int ValN3=LValN+TInt::GetRnd(SubVals);
2124  const TVal& Val1=ValT[ValN1];
2125  const TVal& Val2=ValT[ValN2];
2126  const TVal& Val3=ValT[ValN3];
2127  if (Val1<Val2){
2128  if (Val2<Val3){return ValN2;}
2129  else if (Val3<Val1){return ValN1;}
2130  else {return ValN3;}
2131  } else {
2132  if (Val1<Val3){return ValN1;}
2133  else if (Val3<Val2){return ValN2;}
2134  else {return ValN3;}
2135  }
2136 }
TVal * ValT
Definition: ds.h:1487
static int GetRnd(const int &Range=0)
Definition: dt.h:1082
template<class TVal>
template<class TCmp >
static TIter TGLib_OLD::TVec< TVal >::GetPivotValNCmp ( const TIter BI,
const TIter EI,
const TCmp Cmp 
)
inlinestatic

Definition at line 1648 of file ds.h.

1648  {
1649  const int SubVals=int(EI-BI);
1650  const int ValN1=TInt::GetRnd(SubVals);
1651  const int ValN2=TInt::GetRnd(SubVals);
1652  const int ValN3=TInt::GetRnd(SubVals);
1653  const TVal& Val1 = *(BI+ValN1);
1654  const TVal& Val2 = *(BI+ValN2);
1655  const TVal& Val3 = *(BI+ValN3);
1656  if (Cmp(Val1, Val2)) {
1657  if (Cmp(Val2, Val3)) return BI+ValN2;
1658  else if (Cmp(Val3, Val1)) return BI+ValN1;
1659  else return BI+ValN3;
1660  } else {
1661  if (Cmp(Val1, Val3)) return BI+ValN1;
1662  else if (Cmp(Val3, Val2)) return BI+ValN2;
1663  else return BI+ValN3;
1664  }
1665  }
static int GetRnd(const int &Range=0)
Definition: dt.h:1082
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
Definition: bd.h:426
template<class TVal >
int TVec< TVal >::GetPrimHashCd ( ) const

Definition at line 1888 of file ds.h.

1888  {
1889  int HashCd=0;
1890  for (int ValN=0; ValN<Vals; ValN++){
1891  HashCd+=ValT[ValN].GetPrimHashCd();}
1892  return abs(HashCd);
1893 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal >
int TVec< TVal >::GetSecHashCd ( ) const

Definition at line 1896 of file ds.h.

1896  {
1897  int HashCd=0;
1898  for (int ValN=0; ValN<Vals; ValN++){
1899  HashCd+=ValT[ValN].GetSecHashCd();}
1900  return abs(HashCd);
1901 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
void TVec< TVal >::GetSubValV ( const int &  BValN,
const int &  EValN,
TVec< TVal > &  ValV 
) const

Definition at line 2026 of file ds.h.

2027  {
2028  int BValN=TInt::GetInRng(_BValN, 0, Len()-1);
2029  int EValN=TInt::GetInRng(_EValN, 0, Len()-1);
2030  int SubVals=TInt::GetMx(0, EValN-BValN+1);
2031  SubValV.Gen(SubVals, 0);
2032  for (int ValN=BValN; ValN<=EValN; ValN++){
2033  SubValV.Add(GetVal(ValN));}
2034 }
static int GetInRng(const int &Val, const int &Mn, const int &Mx)
Definition: dt.h:1101
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1089
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
template<class TVal>
static TVec<TVal> TGLib_OLD::TVec< TVal >::GetV ( const TVal &  Val1)
inlinestatic

Definition at line 1766 of file ds.h.

1766  {
1767  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 
)
inlinestatic

Definition at line 1768 of file ds.h.

1768  {
1769  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 
)
inlinestatic

Definition at line 1770 of file ds.h.

1770  {
1771  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 
)
inlinestatic

Definition at line 1772 of file ds.h.

1772  {
1773  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 
)
inlinestatic

Definition at line 1774 of file ds.h.

1774  {
1775  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 
)
inlinestatic

Definition at line 1776 of file ds.h.

1776  {
1777  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 
)
inlinestatic

Definition at line 1778 of file ds.h.

1778  {
1779  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 
)
inlinestatic

Definition at line 1780 of file ds.h.

1780  {
1781  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 
)
inlinestatic

Definition at line 1782 of file ds.h.

1782  {
1783  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 1575 of file ds.h.

1575 {return operator[](ValN);}
const TVal & operator[](const int &ValN) const
Definition: ds.h:1512
template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::GetVal ( const int &  ValN)
inline

Definition at line 1576 of file ds.h.

1576 {return operator[](ValN);}
const TVal & operator[](const int &ValN) const
Definition: ds.h:1512
template<class TVal >
TStr TVec< TVal >::GetXOutOfBoundsErrMsg ( const int &  ValN) const
protected

Definition at line 1821 of file ds.h.

1821  {
1822  return TStr()+
1823  "Index:"+TInt::GetStr(ValN)+
1824  " Vals:"+TInt::GetStr(Vals)+
1825  " MxVals:"+TInt::GetStr(MxVals)+
1826  " Type:"+GetTypeNm(*this);
1827 }
int MxVals
Definition: ds.h:1485
TStr GetTypeNm(const Type &Var)
Definition: ut.h:16
TStr GetStr() const
Definition: dt.h:1104
int Vals
Definition: ds.h:1486
Definition: dt.h:412
template<class TVal>
void TVec< TVal >::Ins ( const int &  ValN,
const TVal &  Val 
)

Definition at line 2037 of file ds.h.

2037  {
2038  Assert(MxVals!=-1);
2039  Add(); Assert((0<=ValN)&&(ValN<Vals));
2040  for (int MValN=Vals-2; MValN>=ValN; MValN--){ValT[MValN+1]=ValT[MValN];}
2041  ValT[ValN]=Val;
2042 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define Assert(Cond)
Definition: bd.h:251
int Add()
Definition: ds.h:1563
template<class TVal>
void TVec< TVal >::Intrs ( const TVec< TVal > &  ValV)

Definition at line 2256 of file ds.h.

2256  {
2257  TVec<TVal> IntrsVec;
2258  Intrs(ValV, IntrsVec);
2259  MoveFrom(IntrsVec);
2260 }
void MoveFrom(TVec< TVal > &Vec)
Definition: ds.h:1952
void Intrs(const TVec< TVal > &ValV)
Definition: ds.h:2256
template<class TVal>
void TVec< TVal >::Intrs ( const TVec< TVal > &  ValV,
TVec< TVal > &  DstValV 
) const

Definition at line 2284 of file ds.h.

2284  {
2285  DstValV.Clr();
2286  int ValN1=0; int ValN2=0;
2287  while ((ValN1<Len())&&(ValN2<ValV.Len())){
2288  const TVal& Val1=GetVal(ValN1);
2289  while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){
2290  ValN2++;}
2291  if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){
2292  DstValV.Add(Val1); ValN2++;}
2293  ValN1++;
2294  }
2295 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:595
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
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 2362 of file ds.h.

2362  {
2363  int Cnt=0, ValN1=0; int ValN2=0;
2364  while ((ValN1<Len())&&(ValN2<ValV.Len())){
2365  const TVal& Val1=GetVal(ValN1);
2366  while ((ValN2<ValV.Len())&&(Val1>ValV.GetVal(ValN2))){
2367  ValN2++;}
2368  if ((ValN2<ValV.Len())&&(Val1==ValV.GetVal(ValN2))){
2369  ValN2++; Cnt++;}
2370  ValN1++;
2371  }
2372  return Cnt;
2373 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:595
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
template<class TVal>
bool TGLib_OLD::TVec< TVal >::IsExt ( ) const
inline

Definition at line 1535 of file ds.h.

1535 {return MxVals==-1;}
int MxVals
Definition: ds.h:1485
template<class TVal>
bool TGLib_OLD::TVec< TVal >::IsIn ( const TVal &  Val) const
inline

Definition at line 1751 of file ds.h.

1751 {return SearchForw(Val)!=-1;}
int SearchForw(const TVal &Val, const int &BValN=0) const
Definition: ds.h:2429
template<class TVal>
bool TGLib_OLD::TVec< TVal >::IsIn ( const TVal &  Val,
int &  ValN 
) const
inline

Definition at line 1752 of file ds.h.

1752  {
1753  ValN=SearchForw(Val); return ValN!=-1;}
int SearchForw(const TVal &Val, const int &BValN=0) const
Definition: ds.h:2429
template<class TVal>
bool TGLib_OLD::TVec< TVal >::IsInBin ( const TVal &  Val) const
inline

Definition at line 1754 of file ds.h.

1754 {return SearchBin(Val)!=-1;}
int SearchBin(const TVal &Val) const
Definition: ds.h:2407
template<class TVal >
void TVec< TVal >::ISort ( const int &  MnLValN,
const int &  MxRValN,
const bool &  Asc 
)

Definition at line 2101 of file ds.h.

2102  {
2103  if (MnLValN<MxRValN){
2104  for (int ValN1=MnLValN+1; ValN1<=MxRValN; ValN1++){
2105  TVal Val=ValT[ValN1]; int ValN2=ValN1;
2106  if (Asc){
2107  while ((ValN2>MnLValN)&&(ValT[ValN2-1]>Val)){
2108  ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
2109  } else {
2110  while ((ValN2>MnLValN)&&(ValT[ValN2-1]<Val)){
2111  ValT[ValN2]=ValT[ValN2-1]; ValN2--;}
2112  }
2113  ValT[ValN2]=Val;
2114  }
2115  }
2116 }
TVal * ValT
Definition: ds.h:1487
template<class TVal>
template<class TCmp >
static void TGLib_OLD::TVec< TVal >::ISortCmp ( TIter  BI,
TIter  EI,
const TCmp Cmp 
)
inlinestatic

Definition at line 1688 of file ds.h.

1688  {
1689  if (BI + 1 < EI) {
1690  for (TIter i = BI, j; i != EI; ++i) {
1691  TVal Tmp = *i; j = i;
1692  while (j > BI && Cmp(Tmp, *(j-1))) { *j = *(j-1); --j; }
1693  *j = Tmp;
1694  }
1695  }
1696  }
TVal * TIter
Definition: ds.h:1483
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
Definition: bd.h:426
template<class TVal >
bool TVec< TVal >::IsSorted ( const bool &  Asc = true) const

Definition at line 2178 of file ds.h.

2178  {
2179  if (Asc){
2180  for (int ValN=0; ValN<Vals-1; ValN++){
2181  if (ValT[ValN]>ValT[ValN+1]){return false;}}
2182  } else {
2183  for (int ValN=0; ValN<Vals-1; ValN++){
2184  if (ValT[ValN]<ValT[ValN+1]){return false;}}
2185  }
2186  return true;
2187 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
template<class TCmp >
bool TGLib_OLD::TVec< TVal >::IsSortedCmp ( const TCmp Cmp) const
inline

Definition at line 1725 of file ds.h.

1725  {
1726  if (EndI() == BegI()) return true;
1727  for (TIter i = BegI(); i != EndI()-1; ++i) {
1728  if (Cmp(*(i+1), *i)){return false;}}
1729  return true;
1730  }
TIter EndI() const
Definition: ds.h:1560
TVal * TIter
Definition: ds.h:1483
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
Definition: bd.h:426
TIter BegI() const
Definition: ds.h:1559
template<class TVal>
const TVal& TGLib_OLD::TVec< TVal >::Last ( ) const
inline

Definition at line 1549 of file ds.h.

1549 {return GetVal(Len()-1);}
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::Last ( )
inline

Definition at line 1550 of file ds.h.

1550 {return GetVal(Len()-1);}
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
template<class TVal>
const TVal& TGLib_OLD::TVec< TVal >::LastLast ( ) const
inline

Definition at line 1552 of file ds.h.

1552  {
1554  return ValT[Vals-2];}
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define AssertR(Cond, Reason)
Definition: bd.h:258
TStr GetXOutOfBoundsErrMsg(const int &ValN) const
Definition: ds.h:1821
template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::LastLast ( )
inline

Definition at line 1555 of file ds.h.

1555  {
1557  return ValT[Vals-2];}
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define AssertR(Cond, Reason)
Definition: bd.h:258
TStr GetXOutOfBoundsErrMsg(const int &ValN) const
Definition: ds.h:1821
template<class TVal>
int TGLib_OLD::TVec< TVal >::LastValN ( ) const
inline

Definition at line 1551 of file ds.h.

1551 {return Len()-1;}
int Len() const
Definition: ds.h:1547
template<class TVal>
int TGLib_OLD::TVec< TVal >::Len ( ) const
inline

Definition at line 1547 of file ds.h.

1547 {return Vals;}
int Vals
Definition: ds.h:1486
template<class TVal >
void TVec< TVal >::Load ( TSIn SIn)

Definition at line 1837 of file ds.h.

1837  {
1838  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
1839  SIn.Load(MxVals); SIn.Load(Vals); MxVals=Vals;
1840  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
1841  for (int ValN=0; ValN<Vals; ValN++){
1842  ValT[ValN]=TVal(SIn);}
1843 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
void Load(bool &Bool)
Definition: fl.h:84
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 1608 of file ds.h.

1608 { MakeHeap(TLss<TVal>()); } // build a heap
void MakeHeap()
Definition: ds.h:1608
Definition: bd.h:368
template<class TVal>
template<class TCmp >
void TGLib_OLD::TVec< TVal >::MakeHeap ( const TCmp Cmp)
inline

Definition at line 1612 of file ds.h.

1612 { MakeHeap(0, Len(), Cmp); }
void MakeHeap()
Definition: ds.h:1608
int Len() const
Definition: ds.h:1547
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 1639 of file ds.h.

1639  {
1640  if (Len < 2) { return; }
1641  int Parent = (Len-2)/2;
1642  while (true) {
1643  AdjustHeap(First, Parent, Len, ValT[First+Parent], Cmp);
1644  if (Parent == 0) { return; } Parent--; }
1645  }
TVal * ValT
Definition: ds.h:1487
void AdjustHeap(const int &First, int HoleIdx, const int &Len, TVal Val, const TCmp &Cmp)
Definition: ds.h:1626
int Len() const
Definition: ds.h:1547
template<class TVal >
void TVec< TVal >::Merge ( )

Definition at line 2202 of file ds.h.

2202  {
2203  Assert(MxVals!=-1);
2204  TVec<TVal> SortedVec(*this); SortedVec.Sort();
2205  Clr();
2206  for (int ValN=0; ValN<SortedVec.Len(); ValN++){
2207  if ((ValN==0)||(SortedVec[ValN-1]!=SortedVec[ValN])){
2208  Add(SortedVec[ValN]);}
2209  }
2210 }
int MxVals
Definition: ds.h:1485
#define Assert(Cond)
Definition: bd.h:251
void Clr(const bool &DoDel=true, const int &NoDelLim=-1)
Definition: ds.h:1904
int Add()
Definition: ds.h:1563
template<class TVal>
void TVec< TVal >::Minus ( const TVec< TVal > &  ValV)

Definition at line 2277 of file ds.h.

2277  {
2278  TVec<TVal> MinusVec;
2279  Minus(ValV, MinusVec);
2280  MoveFrom(MinusVec);
2281 }
void MoveFrom(TVec< TVal > &Vec)
Definition: ds.h:1952
void Minus(const TVec< TVal > &ValV)
Definition: ds.h:2277
template<class TVal>
void TVec< TVal >::Minus ( const TVec< TVal > &  ValV,
TVec< TVal > &  DstValV 
) const

Definition at line 2394 of file ds.h.

2394  {
2395  Diff(ValV, DstValV);
2396 }
void Diff(const TVec< TVal > &ValV)
Definition: ds.h:2270
template<class TVal>
void TVec< TVal >::MoveFrom ( TVec< TVal > &  Vec)

Definition at line 1952 of file ds.h.

1952  {
1953  if (this!=&Vec){
1954  if (ValT!=NULL && MxVals!=-1){delete[] ValT;}
1955  MxVals=Vec.MxVals; Vals=Vec.Vals; ValT=Vec.ValT;
1956  Vec.MxVals=0; Vec.Vals=0; Vec.ValT=NULL;
1957  }
1958 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
TSizeTy MxVals
Vector capacity. Capacity is the size of allocated storage. If MxVals==-1, then ValT is not owned by ...
Definition: ds.h:424
TSizeTy Vals
Vector length. Length is the number of elements stored in the vector.
Definition: ds.h:425
TVal * ValT
Definition: ds.h:426
template<class TVal >
bool TVec< TVal >::NextPerm ( )

Definition at line 2213 of file ds.h.

2213  {
2214  // start with a sorted sequence to obtain all permutations
2215  int First = 0, Last = Len(), Next = Len()-1;
2216  if (Last < 2) return false;
2217  for(; ; ) {
2218  // find rightmost element smaller than successor
2219  int Next1 = Next;
2220  if (GetVal(--Next) < GetVal(Next1)) { // swap with rightmost element that's smaller, flip suffix
2221  int Mid = Last;
2222  for (; GetVal(Next) >= GetVal(--Mid); ) { }
2223  Swap(Next, Mid);
2224  Reverse(Next1, Last);
2225  return true;
2226  }
2227  if (Next == First) { // pure descending, flip all
2228  Reverse();
2229  return false;
2230  }
2231  }
2232 }
void Reverse()
Definition: ds.h:2196
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
const TVal & Last() const
Definition: ds.h:1549
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
template<class TVal>
TVec<TVal>& TGLib_OLD::TVec< TVal >::operator+ ( const TVal &  Val)
inline

Definition at line 1509 of file ds.h.

1509 {Add(Val); return *this;}
int Add()
Definition: ds.h:1563
template<class TVal>
bool TVec< TVal >::operator< ( const TVec< TVal > &  Vec) const

Definition at line 1873 of file ds.h.

1873  {
1874  if (this==&Vec){return false;}
1875  if (Len()==Vec.Len()){
1876  for (int ValN=0; ValN<Vals; ValN++){
1877  if (ValT[ValN]<Vec.ValT[ValN]){return true;}
1878  else if (ValT[ValN]>Vec.ValT[ValN]){return false;}
1879  else {}
1880  }
1881  return false;
1882  } else {
1883  return Len()<Vec.Len();
1884  }
1885 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
int Len() const
Definition: ds.h:1547
TVal * ValT
Definition: ds.h:426
template<class TVal>
TVec< TVal > & TVec< TVal >::operator= ( const TVec< TVal > &  Vec)

Definition at line 1853 of file ds.h.

1853  {
1854  if (this!=&Vec){
1855  if ((ValT!=NULL)&&(MxVals!=-1)){delete[] ValT;}
1856  MxVals=Vals=Vec.Vals;
1857  if (MxVals==0){ValT=NULL;} else {ValT=new TVal[MxVals];}
1858  for (int ValN=0; ValN<Vec.Vals; ValN++){ValT[ValN]=Vec.ValT[ValN];}
1859  }
1860  return *this;
1861 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
TSizeTy Vals
Vector length. Length is the number of elements stored in the vector.
Definition: ds.h:425
TVal * ValT
Definition: ds.h:426
template<class TVal>
bool TVec< TVal >::operator== ( const TVec< TVal > &  Vec) const

Definition at line 1864 of file ds.h.

1864  {
1865  if (this==&Vec){return true;}
1866  if (Len()!=Vec.Len()){return false;}
1867  for (int ValN=0; ValN<Vals; ValN++){
1868  if (ValT[ValN]!=Vec.ValT[ValN]){return false;}}
1869  return true;
1870 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
int Len() const
Definition: ds.h:1547
TVal * ValT
Definition: ds.h:426
template<class TVal>
const TVal& TGLib_OLD::TVec< TVal >::operator[] ( const int &  ValN) const
inline

Definition at line 1512 of file ds.h.

1512  {
1513  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
1514  return ValT[ValN];}
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define AssertR(Cond, Reason)
Definition: bd.h:258
TStr GetXOutOfBoundsErrMsg(const int &ValN) const
Definition: ds.h:1821
template<class TVal>
TVal& TGLib_OLD::TVec< TVal >::operator[] ( const int &  ValN)
inline

Definition at line 1515 of file ds.h.

1515  {
1516  AssertR((0<=ValN)&&(ValN<Vals), GetXOutOfBoundsErrMsg(ValN));
1517  return ValT[ValN];}
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
#define AssertR(Cond, Reason)
Definition: bd.h:258
TStr GetXOutOfBoundsErrMsg(const int &ValN) const
Definition: ds.h:1821
template<class TVal >
void TVec< TVal >::Pack ( )

Definition at line 1937 of file ds.h.

1937  {
1938  IAssert(MxVals!=-1);
1939  if (Vals==0){
1940  if (ValT!=NULL){delete[] ValT;} ValT=NULL;
1941  } else
1942  if (Vals<MxVals){
1943  MxVals=Vals;
1944  TVal* NewValT=new TVal[MxVals];
1945  IAssert(NewValT!=NULL);
1946  for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1947  delete[] ValT; ValT=NewValT;
1948  }
1949 }
#define IAssert(Cond)
Definition: bd.h:262
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal >
int TVec< TVal >::Partition ( const int &  MnLValN,
const int &  MxRValN,
const bool &  Asc 
)

Definition at line 2139 of file ds.h.

2140  {
2141  int PivotValN=GetPivotValN(MnLValN, MxRValN);
2142  Swap(PivotValN, MnLValN);
2143  TVal PivotVal=ValT[MnLValN];
2144  int LValN=MnLValN-1; int RValN=MxRValN+1;
2145  forever {
2146  if (Asc){
2147  do {RValN--;} while (ValT[RValN]>PivotVal);
2148  do {LValN++;} while (ValT[LValN]<PivotVal);
2149  } else {
2150  do {RValN--;} while (ValT[RValN]<PivotVal);
2151  do {LValN++;} while (ValT[LValN]>PivotVal);
2152  }
2153  if (LValN<RValN){Swap(LValN, RValN);}
2154  else {return RValN;}
2155  };
2156 }
#define forever
Definition: bd.h:6
TVal * ValT
Definition: ds.h:1487
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
int GetPivotValN(const int &LValN, const int &RValN) const
Definition: ds.h:2119
template<class TVal>
template<class TCmp >
static TIter TGLib_OLD::TVec< TVal >::PartitionCmp ( TIter  BI,
TIter  EI,
const TVal  Pivot,
const TCmp Cmp 
)
inlinestatic

Definition at line 1668 of file ds.h.

1668  {
1669  forever {
1670  while (Cmp(*BI, Pivot)) ++BI;
1671  --EI;
1672  while (Cmp(Pivot, *EI)) --EI;
1673  if (!(BI < EI)) return BI;
1674  SwapI(BI, EI);
1675  ++BI;
1676  }
1677  }
static void SwapI(TIter LVal, TIter RVal)
Definition: ds.h:1588
#define forever
Definition: bd.h:6
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
Definition: bd.h:426
template<class TVal>
TVal TGLib_OLD::TVec< TVal >::PopHeap ( )
inline

Definition at line 1611 of file ds.h.

1611 { return PopHeap(TLss<TVal>()); } // remove largest element
Definition: bd.h:368
TVal PopHeap()
Definition: ds.h:1611
template<class TVal>
template<class TCmp >
TVal TGLib_OLD::TVec< TVal >::PopHeap ( const TCmp Cmp)
inline

Definition at line 1614 of file ds.h.

1614  { IAssert(! Empty()); const TVal Top=ValT[0];
1615  ValT[0]=Last(); DelLast(); if (! Empty()) { AdjustHeap(0, 0, Len(), ValT[0], Cmp); } return Top; }
#define IAssert(Cond)
Definition: bd.h:262
TVal * ValT
Definition: ds.h:1487
void AdjustHeap(const int &First, int HoleIdx, const int &Len, TVal Val, const TCmp &Cmp)
Definition: ds.h:1626
void DelLast()
Definition: ds.h:1581
bool Empty() const
Definition: ds.h:1546
const TVal & Last() const
Definition: ds.h:1549
int Len() const
Definition: ds.h:1547
template<class TVal >
bool TVec< TVal >::PrevPerm ( )

Definition at line 2235 of file ds.h.

2235  {
2236  int First = 0, Last = Len(), Next = Len()-1;
2237  if (Last < 2) return false;
2238  for(; ; ) {
2239  // find rightmost element not smaller than successor
2240  int Next1 = Next;
2241  if (GetVal(--Next) >= GetVal(Next1)) { // swap with rightmost element that's not smaller, flip suffix
2242  int Mid = Last;
2243  for (; GetVal(Next) < GetVal(--Mid); ) { }
2244  Swap(Next, Mid);
2245  Reverse(Next1, Last);
2246  return true;
2247  }
2248  if (Next == First) { // pure descending, flip all
2249  Reverse();
2250  return false;
2251  }
2252  }
2253 }
void Reverse()
Definition: ds.h:2196
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
const TVal & Last() const
Definition: ds.h:1549
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
template<class TVal>
void TGLib_OLD::TVec< TVal >::PushHeap ( const TVal &  Val)
inline

Definition at line 1609 of file ds.h.

1609 { PushHeap(Val, TLss<TVal>()); } // add element to the heap
Definition: bd.h:368
void PushHeap(const TVal &Val)
Definition: ds.h:1609
template<class TVal>
template<class TCmp >
void TGLib_OLD::TVec< TVal >::PushHeap ( const TVal &  Val,
const TCmp Cmp 
)
inline

Definition at line 1613 of file ds.h.

1613 { Add(Val); PushHeap(0, Len()-1, 0, Val, Cmp); }
void PushHeap(const TVal &Val)
Definition: ds.h:1609
int Len() const
Definition: ds.h:1547
int Add()
Definition: ds.h:1563
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 1618 of file ds.h.

1618  {
1619  int Parent = (HoleIdx-1)/2;
1620  while (HoleIdx > Top && Cmp(ValT[First+Parent], Val)) {
1621  ValT[First+HoleIdx] = ValT[First+Parent];
1622  HoleIdx = Parent; Parent = (HoleIdx-1)/2; }
1623  ValT[First+HoleIdx] = Val;
1624  }
TVal * ValT
Definition: ds.h:1487
bool Cmp(const int &RelOp, const TRec &Rec1, const TRec &Rec2)
Definition: bd.h:426
template<class TVal>
void TVec< TVal >::PutAll ( const TVal &  Val)

Definition at line 2082 of file ds.h.

2082  {
2083  for (int ValN=0; ValN<Vals; ValN++){ValT[ValN]=Val;}
2084 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal >
void TVec< TVal >::QSort ( const int &  MnLValN,
const int &  MxRValN,
const bool &  Asc 
)

Definition at line 2159 of file ds.h.

2160  {
2161  if (MnLValN<MxRValN){
2162  if (MxRValN-MnLValN<20){
2163  ISort(MnLValN, MxRValN, Asc);
2164  } else {
2165  int SplitValN=Partition(MnLValN, MxRValN, Asc);
2166  QSort(MnLValN, SplitValN, Asc);
2167  QSort(SplitValN+1, MxRValN, Asc);
2168  }
2169  }
2170 }
void ISort(const int &MnLValN, const int &MxRValN, const bool &Asc)
Definition: ds.h:2101
void QSort(const int &MnLValN, const int &MxRValN, const bool &Asc)
Definition: ds.h:2159
int Partition(const int &MnLValN, const int &MxRValN, const bool &Asc)
Definition: ds.h:2139
template<class TVal>
template<class TCmp >
static void TGLib_OLD::TVec< TVal >::QSortCmp ( TIter  BI,
TIter  EI,
const TCmp Cmp 
)
inlinestatic

Definition at line 1699 of file ds.h.

1699  {
1700  if (BI + 1 < EI) {
1701  if (EI - BI < 20) {
1702  ISortCmp(BI, EI, Cmp); }
1703  else {
1704  const TVal Val = *GetPivotValNCmp(BI, EI, Cmp);
1705  TIter Split = PartitionCmp(BI, EI, Val, Cmp);
1706  QSortCmp(BI, Split, Cmp);
1707  QSortCmp(Split, EI, Cmp);
1708  }
1709  }
1710  }
static TIter PartitionCmp(TIter BI, TIter EI, const TVal Pivot, const TCmp &Cmp)
Definition: ds.h:1668
TVal * TIter
Definition: ds.h:1483
static TIter GetPivotValNCmp(const TIter &BI, const TIter &EI, const TCmp &Cmp)
Definition: ds.h:1648
static void QSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Definition: ds.h:1699
static void ISortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Definition: ds.h:1688
template<class TVal>
void TGLib_OLD::TVec< TVal >::Reserve ( const int &  _MxVals)
inline

Definition at line 1536 of file ds.h.

1536 {Resize(_MxVals);}
void Resize(const int &_MxVals=-1)
Definition: ds.h:1789
template<class TVal>
void TGLib_OLD::TVec< TVal >::Reserve ( const int &  _MxVals,
const int &  _Vals 
)
inline

Definition at line 1537 of file ds.h.

1537  {
1538  IAssert((0<=_Vals)&&(_Vals<=_MxVals));
1539  Resize(_MxVals); Vals=_Vals;}
#define IAssert(Cond)
Definition: bd.h:262
int Vals
Definition: ds.h:1486
void Resize(const int &_MxVals=-1)
Definition: ds.h:1789
template<class TVal>
int TGLib_OLD::TVec< TVal >::Reserved ( ) const
inline

Definition at line 1548 of file ds.h.

1548 {return MxVals;}
int MxVals
Definition: ds.h:1485
template<class TVal >
void TVec< TVal >::Resize ( const int &  _MxVals = -1)
protected

Definition at line 1789 of file ds.h.

1789  {
1790  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());
1791  IAssertR(MxVals!=(TInt::Mx-1024), TStr::Fmt("Buffer size at maximum. %s. [Program refuses to allocate more memory. Solution-2: Send your test case to developers.]", GetTypeNm(*this).CStr()).CStr());
1792  if (_MxVals==-1){
1793  if (Vals==0){MxVals=16;} else {MxVals*=2;}
1794  } else {
1795  if (_MxVals<=MxVals){return;} else {MxVals=_MxVals;}
1796  }
1797  if (MxVals < 0) {
1798  MxVals = TInt::Mx-1024;
1799  }
1800  if (ValT==NULL){
1801  try {ValT=new TVal[MxVals];}
1802  catch (std::exception Ex){
1803  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.]",
1804  Ex.what(), Vals, MxVals, _MxVals, GetTypeNm(*this).CStr()).CStr());}
1805  } else {
1806  //if (Vals > 1000000) {
1807  // printf("%s resize %d -> %d\n", GetTypeNm(*this).CStr(), Vals, MxVals); }
1808  TVal* NewValT = NULL;
1809  try {
1810  NewValT=new TVal[MxVals];}
1811  catch (std::exception Ex){
1812  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.]",
1813  Ex.what(), Vals, MxVals, _MxVals, GetTypeNm(*this).CStr()).CStr());}
1814  Assert(NewValT!=NULL);
1815  for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1816  delete[] ValT; ValT=NewValT;
1817  }
1818 }
int MxVals
Definition: ds.h:1485
TStr GetTypeNm(const Type &Var)
Definition: ut.h:16
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TVal * ValT
Definition: ds.h:1487
static const int Mx
Definition: dt.h:1046
int Vals
Definition: ds.h:1486
#define Assert(Cond)
Definition: bd.h:251
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
template<class TVal >
void TVec< TVal >::Reverse ( )

Definition at line 2196 of file ds.h.

2196  {
2197  for (int ValN=0; ValN<Vals/2; ValN++){
2198  Swap(ValN, Vals-ValN-1);}
2199 }
int Vals
Definition: ds.h:1486
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
template<class TVal>
void TGLib_OLD::TVec< TVal >::Reverse ( int  First,
int  Last 
)
inline

Definition at line 1600 of file ds.h.

1600  {
1601  Last--; while (First < Last){Swap(First++, Last--);}}
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
const TVal & Last() const
Definition: ds.h:1549
template<class TVal >
void TVec< TVal >::Save ( TSOut SOut) const

Definition at line 1846 of file ds.h.

1846  {
1847  if (MxVals!=-1){SOut.Save(MxVals);} else {SOut.Save(Vals);}
1848  SOut.Save(Vals);
1849  for (int ValN=0; ValN<Vals; ValN++){ValT[ValN].Save(SOut);}
1850 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
void Save(const bool &Bool)
Definition: fl.h:173
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 2436 of file ds.h.

2436  {
2437  for (int ValN=Vals-1; ValN>=0; ValN--){
2438  if (Val==ValT[ValN]){return ValN;}}
2439  return -1;
2440 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
int TVec< TVal >::SearchBin ( const TVal &  Val) const

Definition at line 2407 of file ds.h.

2407  {
2408  int LValN=0; int RValN=Len()-1;
2409  while (RValN>=LValN){
2410  int ValN=(LValN+RValN)/2;
2411  if (Val==ValT[ValN]){return ValN;}
2412  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
2413  }
2414  return -1;
2415 }
TVal * ValT
Definition: ds.h:1487
int Len() const
Definition: ds.h:1547
template<class TVal>
int TVec< TVal >::SearchBin ( const TVal &  Val,
int &  InsValN 
) const

Definition at line 2418 of file ds.h.

2418  {
2419  int LValN=0; int RValN=Len()-1;
2420  while (RValN>=LValN){
2421  int ValN=(LValN+RValN)/2;
2422  if (Val==ValT[ValN]){InsValN=ValN; return ValN;}
2423  if (Val<ValT[ValN]){RValN=ValN-1;} else {LValN=ValN+1;}
2424  }
2425  InsValN=LValN; return -1;
2426 }
TVal * ValT
Definition: ds.h:1487
int Len() const
Definition: ds.h:1547
template<class TVal>
int TVec< TVal >::SearchForw ( const TVal &  Val,
const int &  BValN = 0 
) const

Definition at line 2429 of file ds.h.

2429  {
2430  for (int ValN=BValN; ValN<Vals; ValN++){
2431  if (Val==ValT[ValN]){return ValN;}}
2432  return -1;
2433 }
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
int TVec< TVal >::SearchVForw ( const TVec< TVal > &  ValV,
const int &  BValN = 0 
) const

Definition at line 2443 of file ds.h.

2443  {
2444  int ValVLen=ValV.Len();
2445  for (int ValN=BValN; ValN<Vals-ValVLen+1; ValN++){
2446  bool Found=true;
2447  for (int SubValN=0; SubValN<ValVLen; SubValN++){
2448  if (ValV[SubValN]!=GetVal(ValN+SubValN)){Found=false; break;}
2449  }
2450  if (Found){return ValN;}
2451  }
2452  return -1;
2453 }
int Vals
Definition: ds.h:1486
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
template<class TVal >
void TVec< TVal >::Shuffle ( TRnd Rnd)

Definition at line 2190 of file ds.h.

2190  {
2191  for (int ValN=0; ValN<Vals-1; ValN++){
2192  Swap(ValN, ValN+Rnd.GetUniDevInt(Vals-ValN));}
2193 }
int Vals
Definition: ds.h:1486
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
template<class TVal >
void TVec< TVal >::Sort ( const bool &  Asc = true)

Definition at line 2173 of file ds.h.

2173  {
2174  QSort(0, Len()-1, Asc);
2175 }
void QSort(const int &MnLValN, const int &MxRValN, const bool &Asc)
Definition: ds.h:2159
int Len() const
Definition: ds.h:1547
template<class TVal>
template<class TCmp >
void TGLib_OLD::TVec< TVal >::SortCmp ( const TCmp Cmp)
inline

Definition at line 1717 of file ds.h.

1717  {
1718  QSortCmp(BegI(), EndI(), Cmp);}
TIter EndI() const
Definition: ds.h:1560
TIter BegI() const
Definition: ds.h:1559
static void QSortCmp(TIter BI, TIter EI, const TCmp &Cmp)
Definition: ds.h:1699
template<class TVal>
void TVec< TVal >::Swap ( TVec< TVal > &  Vec)

Definition at line 1961 of file ds.h.

1961  {
1962  if (this!=&Vec){
1963  ::Swap(MxVals, Vec.MxVals);
1964  ::Swap(Vals, Vec.Vals);
1965  ::Swap(ValT, Vec.ValT);
1966  }
1967 }
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
TSizeTy MxVals
Vector capacity. Capacity is the size of allocated storage. If MxVals==-1, then ValT is not owned by ...
Definition: ds.h:424
void Swap(TVec< TVal > &Vec)
Definition: ds.h:1961
TSizeTy Vals
Vector length. Length is the number of elements stored in the vector.
Definition: ds.h:425
TVal * ValT
Definition: ds.h:426
template<class TVal>
void TGLib_OLD::TVec< TVal >::Swap ( const int &  ValN1,
const int &  ValN2 
)
inline

Definition at line 1586 of file ds.h.

1586  {
1587  TVal Val=ValT[ValN1]; ValT[ValN1]=ValT[ValN2]; ValT[ValN2]=Val;}
TVal * ValT
Definition: ds.h:1487
template<class TVal>
static void TGLib_OLD::TVec< TVal >::SwapI ( TIter  LVal,
TIter  RVal 
)
inlinestatic

Definition at line 1588 of file ds.h.

1588  {
1589  TVal Val=*LVal; *LVal=*RVal; *RVal=Val;}
template<class TVal>
const TVal& TGLib_OLD::TVec< TVal >::TopHeap ( ) const
inline

Definition at line 1610 of file ds.h.

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

Definition at line 1914 of file ds.h.

1914  {
1915  IAssert(MxVals!=-1);
1916  IAssert((_Vals==-1)||(_Vals>=0));
1917  if ((_Vals!=-1)&&(_Vals>=Vals)){
1918  return;
1919  } else
1920  if (((_Vals==-1)&&(Vals==0))||(_Vals==0)){
1921  if (ValT!=NULL){delete[] ValT;}
1922  MxVals=Vals=0; ValT=NULL;
1923  } else {
1924  if (_Vals==-1){
1925  if (MxVals==Vals){return;} else {MxVals=Vals;}
1926  } else {
1927  MxVals=Vals=_Vals;
1928  }
1929  TVal* NewValT=new TVal[MxVals];
1930  IAssert(NewValT!=NULL);
1931  for (int ValN=0; ValN<Vals; ValN++){NewValT[ValN]=ValT[ValN];}
1932  delete[] ValT; ValT=NewValT;
1933  }
1934 }
#define IAssert(Cond)
Definition: bd.h:262
int MxVals
Definition: ds.h:1485
TVal * ValT
Definition: ds.h:1487
int Vals
Definition: ds.h:1486
template<class TVal>
void TVec< TVal >::Union ( const TVec< TVal > &  ValV)

Definition at line 2263 of file ds.h.

2263  {
2264  TVec<TVal> UnionVec;
2265  Union(ValV, UnionVec);
2266  MoveFrom(UnionVec);
2267 }
void MoveFrom(TVec< TVal > &Vec)
Definition: ds.h:1952
void Union(const TVec< TVal > &ValV)
Definition: ds.h:2263
template<class TVal>
void TVec< TVal >::Union ( const TVec< TVal > &  ValV,
TVec< TVal > &  DstValV 
) const

Definition at line 2298 of file ds.h.

2298  {
2299  DstValV.Gen(TInt::GetMx(Len(), ValV.Len()), 0);
2300  int ValN1=0; int ValN2=0;
2301  while ((ValN1<Len())&&(ValN2<ValV.Len())){
2302  const TVal& Val1=GetVal(ValN1);
2303  const TVal& Val2=ValV.GetVal(ValN2);
2304  if (Val1<Val2){DstValV.Add(Val1); ValN1++;}
2305  else if (Val1>Val2){DstValV.Add(Val2); ValN2++;}
2306  else {DstValV.Add(Val1); ValN1++; ValN2++;}
2307  }
2308  for (int RestValN1=ValN1; RestValN1<Len(); RestValN1++){
2309  DstValV.Add(GetVal(RestValN1));}
2310  for (int RestValN2=ValN2; RestValN2<ValV.Len(); RestValN2++){
2311  DstValV.Add(ValV.GetVal(RestValN2));}
2312 }
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1089
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:595
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
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 2376 of file ds.h.

2376  {
2377  int Cnt = 0, ValN1 = 0, ValN2 = 0;
2378  while ((ValN1 < Len()) && (ValN2 < ValV.Len())) {
2379  const TVal& Val1 = GetVal(ValN1);
2380  const TVal& Val2 = ValV.GetVal(ValN2);
2381  if (Val1 < Val2) {
2382  Cnt++; ValN1++;
2383  } else if (Val1 > Val2) {
2384  Cnt++; ValN2++;
2385  } else {
2386  Cnt++; ValN1++; ValN2++;
2387  }
2388  }
2389  Cnt += (Len() - ValN1) + (ValV.Len() - ValN2);
2390  return Cnt;
2391 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:595
const TVal & GetVal(const int &ValN) const
Definition: ds.h:1575
int Len() const
Definition: ds.h:1547

Member Data Documentation

template<class TVal>
int TGLib_OLD::TVec< TVal >::MxVals
protected

Definition at line 1485 of file ds.h.

template<class TVal>
int TGLib_OLD::TVec< TVal >::Vals
protected

Definition at line 1486 of file ds.h.

template<class TVal>
TVal* TGLib_OLD::TVec< TVal >::ValT
protected

Definition at line 1487 of file ds.h.


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