TRF Language Model
wb-vector.h File Reference

Defination of simple dynamic array/stack/queue and so on. More...

#include <iostream>
#include <cmath>
#include <cstring>
#include <stdlib.h>

Go to the source code of this file.

Classes

class  wb::Vector< T >
 this is the basic class of Array/Stack/Queue. Realize the dynamic memory management More...
 
class  wb::Array< T >
 Dynamic array. More...
 
class  wb::DArray< T >
 2-dimension array. More...
 
class  wb::Stack< T >
 A dynamic stack. More...
 
class  wb::Queue< T >
 A queue based the dynamic memory mangement. More...
 
class  wb::CirQueue< T >
 Circular queue. More...
 

Namespaces

 wb
 define all the code written by Bin Wang.
 

Macros

#define DEFAULE_VECTOR_SIZE   16
 defualt vector size More...
 
#define VECTOR_bits2Size(n)   (1<<n)
 transform the bit to memory size More...
 
#define POINT_TEST(p)   { if ((p)==NULL) {cout<<#p<<"[New Memory Error]"<<endl; exit(0);} }
 memory allocation More...
 
#define SAFE_NEW(p, Type)   {p = new Type; POINT_TEST(p)}
 
#define SAFE_DNEW(PType, p, Type)   { PType p = new Type; POINT_TEST(p) }
 
#define SAFE_NEW_ARRAY(p, Type, n)   { p = new Type[n]; POINT_TEST(p) }
 
#define SAFE_NEW_DARRAY(p, Type, n, m)   { p=new Type*[n]; for(int i=0; i<n; i++){p[i]=new Type[m];}; POINT_TEST(p) }
 
#define SAFE_DELETE(p)   {if (p) delete (p); (p)=NULL;}
 memory release More...
 
#define SAFE_DELETE_ARRAY(p)   {if(p) delete [](p); (p)=NULL;}
 
#define SAFE_DELETE_DARRAY(p, n)   { if(p){ for(int i=0; i<n; i++){delete [](p)[i];} delete [](p); (p)=NULL; } }
 
#define SAFE_DEL_POINTER_ARRAY(a)   for (int i=0; i<a.GetNum(); i++) { SAFE_DELETE(a[i]); } a.Clean();
 

Functions

template<typename T >
double wb::VecNorm (T *pVec, int len)
 [Vec-function] sqrt(v*v^T); More...
 
template<typename T >
double wb::VecDot (T *pVec1, T *pVec2, int len)
 [Vec-function] v1*v2^T More...
 
template<typename T >
double wb::VecDiff (T *pVec1, T *pVec2, int len)
 [Vec-function] |v1-v2| More...
 
template<typename T >
double wb::VecAngle (T *pVec1, T *pVec2, int len)
 [Vec-function] the cos of the angle of v1 and v2 More...
 
template<typename T >
void wb::VecUnfold (const char *pStr, Array< T > &a)
 [Vec-function] transform the matlab-style vector to a array, such as [1,3:1:7,9] => 1,3,4,5,6,7,9 More...
 
template<typename T >
int wb::Compar_Inc (const T &a, const T &b)
 comparing function for increase sort. More...
 
template<typename T >
int wb::Compar_Dec (const T &a, const T &b)
 comparing function for decrease sort More...
 
template<typename T >
void wb::Qsort (T *p, int low, int high, int(*compar)(const T &, const T &)=Compar_Inc)
 Quick sork. More...
 
template<typename T >
void wb::Qsort (Array< T > &a, int(*compar)(const T &, const T &)=Compar_Inc)
 Quick sork, redefine for class Array. More...
 

Detailed Description

Defination of simple dynamic array/stack/queue and so on.

Author
WangBin
Date
2013-9-2

Definition in file wb-vector.h.

Macro Definition Documentation

§ DEFAULE_VECTOR_SIZE

#define DEFAULE_VECTOR_SIZE   16

defualt vector size

Definition at line 58 of file wb-vector.h.

§ POINT_TEST

#define POINT_TEST (   p)    { if ((p)==NULL) {cout<<#p<<"[New Memory Error]"<<endl; exit(0);} }

memory allocation

Definition at line 40 of file wb-vector.h.

§ SAFE_DEL_POINTER_ARRAY

#define SAFE_DEL_POINTER_ARRAY (   a)    for (int i=0; i<a.GetNum(); i++) { SAFE_DELETE(a[i]); } a.Clean();

Definition at line 52 of file wb-vector.h.

§ SAFE_DELETE

#define SAFE_DELETE (   p)    {if (p) delete (p); (p)=NULL;}

memory release

Definition at line 49 of file wb-vector.h.

§ SAFE_DELETE_ARRAY

#define SAFE_DELETE_ARRAY (   p)    {if(p) delete [](p); (p)=NULL;}

Definition at line 50 of file wb-vector.h.

§ SAFE_DELETE_DARRAY

#define SAFE_DELETE_DARRAY (   p,
 
)    { if(p){ for(int i=0; i<n; i++){delete [](p)[i];} delete [](p); (p)=NULL; } }

Definition at line 51 of file wb-vector.h.

§ SAFE_DNEW

#define SAFE_DNEW (   PType,
  p,
  Type 
)    { PType p = new Type; POINT_TEST(p) }

Definition at line 42 of file wb-vector.h.

§ SAFE_NEW

#define SAFE_NEW (   p,
  Type 
)    {p = new Type; POINT_TEST(p)}

Definition at line 41 of file wb-vector.h.

§ SAFE_NEW_ARRAY

#define SAFE_NEW_ARRAY (   p,
  Type,
 
)    { p = new Type[n]; POINT_TEST(p) }

Definition at line 43 of file wb-vector.h.

§ SAFE_NEW_DARRAY

#define SAFE_NEW_DARRAY (   p,
  Type,
  n,
  m 
)    { p=new Type*[n]; for(int i=0; i<n; i++){p[i]=new Type[m];}; POINT_TEST(p) }

Definition at line 44 of file wb-vector.h.

§ VECTOR_bits2Size

#define VECTOR_bits2Size (   n)    (1<<n)

transform the bit to memory size

Definition at line 60 of file wb-vector.h.