TRF Language Model
wb::Array< T > Class Template Reference

Dynamic array. More...

#include <wb-vector.h>

Inheritance diagram for wb::Array< T >:
wb::Vector< T >

Public Member Functions

 Array (int size=DEFAULE_VECTOR_SIZE)
 constructor More...
 
 Array (Array &array)
 constructor More...
 
 Array (T *pbuf, int n)
 constructor More...
 
 ~Array ()
 destructor More...
 
T & operator[] (int i)
 get the value at position i More...
 
void SetNum (int n)
 Set Array number, to melloc enough memory. More...
 
int GetNum () const
 Get Array number. More...
 
void Add (T t)
 Add a value to the tail of array. More...
 
T & Add ()
 Add a value to the tail of array, example 'a.Add() = t'. More...
 
void Add (Array< T > &a)
 Add a array to the tail of current array. More...
 
int Find (T t)
 Find a value and return the position. More...
 
T & End ()
 Get the value at the tail of array. More...
 
void Clean ()
 Clean the array. Just set the top of array to -1 and donot release the memory. More...
 
void Copy (const Array< T > &array)
 Copy the array to current array. More...
 
void Copy (const T *pbuf, int n)
 Copy the array to current array. More...
 
void MemCopy (Array< T > &array)
 using memcpy to copy a array. More...
 
void operator= (const Array< T > &array)
 overload operator = More...
 
 operator T* ()
 overload transite operator More...
 
void Output (ostream &os)
 output the array More...
 
void Input (istream &is)
 input the array More...
 
void Insert (T t)
 insert a value. Avoid repeating More...
 
Sum ()
 summate all the values in the array More...
 
Max (int &idx)
 Get the maximum value. More...
 
Min (int &idx)
 Get the minine value. More...
 
- Public Member Functions inherited from wb::Vector< T >
 Vector (int size=DEFAULE_VECTOR_SIZE)
 constructor, do not init the memeory to zero. More...
 
 ~Vector ()
 desturctor More...
 
int Size () const
 get the memory size More...
 
T * GetBuffer (int i=0) const
 get the buffer pointer More...
 
T & Get (int i)
 get the value at position i More...
 
int Size2Bits (int size)
 Transform the size to bit. More...
 
void Fill (T m)
 set all the values to m More...
 
void Zero ()
 Fill all the memory to ZERO. call 'memset'. More...
 
void Copy (const Vector< T > &vector)
 Copy a vector to another, using '=' to set values. More...
 
void MemCopy (Vector< T > &vector)
 Copy a vector to another, using 'memcpy' to set values. More...
 
void BufferOutside (T *&p_pt)
 Set the buffer pointer to p_pt, and re-init the vector. More...
 

Public Attributes

int m_nTop
 Record the top of the array. More...
 

Additional Inherited Members

- Protected Attributes inherited from wb::Vector< T >
T * m_pBuffer
 buffer pointer More...
 
int m_nBits
 bit number of memory size More...
 

Detailed Description

template<typename T>
class wb::Array< T >

Dynamic array.

Date
2016-04-28
Author
WangBin
Note
Set a[i] = a[j] is not safe as the memory is allocated dynamicly. Please use: temp = a[j]; a[i] = temp;

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

Constructor & Destructor Documentation

§ Array() [1/3]

template<typename T>
wb::Array< T >::Array ( int  size = DEFAULE_VECTOR_SIZE)
inline

constructor

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

§ Array() [2/3]

template<typename T>
wb::Array< T >::Array ( Array< T > &  array)
inline

constructor

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

§ Array() [3/3]

template<typename T>
wb::Array< T >::Array ( T *  pbuf,
int  n 
)
inline

constructor

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

§ ~Array()

template<typename T>
wb::Array< T >::~Array ( )
inline

destructor

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

Member Function Documentation

§ Add() [1/3]

template<typename T>
void wb::Array< T >::Add ( t)
inline

Add a value to the tail of array.

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

§ Add() [2/3]

template<typename T>
T& wb::Array< T >::Add ( )
inline

Add a value to the tail of array, example 'a.Add() = t'.

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

§ Add() [3/3]

template<typename T>
void wb::Array< T >::Add ( Array< T > &  a)
inline

Add a array to the tail of current array.

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

§ Clean()

template<typename T>
void wb::Array< T >::Clean ( )
inline

Clean the array. Just set the top of array to -1 and donot release the memory.

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

§ Copy() [1/2]

template<typename T>
void wb::Array< T >::Copy ( const Array< T > &  array)
inline

Copy the array to current array.

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

§ Copy() [2/2]

template<typename T>
void wb::Array< T >::Copy ( const T *  pbuf,
int  n 
)
inline

Copy the array to current array.

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

§ End()

template<typename T>
T& wb::Array< T >::End ( )
inline

Get the value at the tail of array.

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

§ Find()

template<typename T>
int wb::Array< T >::Find ( t)
inline

Find a value and return the position.

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

§ GetNum()

template<typename T>
int wb::Array< T >::GetNum ( ) const
inline

Get Array number.

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

§ Input()

template<typename T>
void wb::Array< T >::Input ( istream &  is)
inline

input the array

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

§ Insert()

template<typename T>
void wb::Array< T >::Insert ( t)
inline

insert a value. Avoid repeating

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

§ Max()

template<typename T>
T wb::Array< T >::Max ( int &  idx)
inline

Get the maximum value.

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

§ MemCopy()

template<typename T>
void wb::Array< T >::MemCopy ( Array< T > &  array)
inline

using memcpy to copy a array.

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

§ Min()

template<typename T>
T wb::Array< T >::Min ( int &  idx)
inline

Get the minine value.

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

§ operator T*()

template<typename T>
wb::Array< T >::operator T* ( )
inline

overload transite operator

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

§ operator=()

template<typename T>
void wb::Array< T >::operator= ( const Array< T > &  array)
inline

overload operator =

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

§ operator[]()

template<typename T>
T& wb::Array< T >::operator[] ( int  i)
inline

get the value at position i

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

§ Output()

template<typename T>
void wb::Array< T >::Output ( ostream &  os)
inline

output the array

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

§ SetNum()

template<typename T>
void wb::Array< T >::SetNum ( int  n)
inline

Set Array number, to melloc enough memory.

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

§ Sum()

template<typename T>
T wb::Array< T >::Sum ( )
inline

summate all the values in the array

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

Member Data Documentation

§ m_nTop

template<typename T>
int wb::Array< T >::m_nTop

Record the top of the array.

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


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