/////////////////////////////////////
//  Vector Class Header
//
//  File: Vector.h
//
//  Description:
/////////////////////////////////////
#ifndef x__Vector__x
#define x__Vector__x

#undef max
#undef min

template<class T> class Vector {

  typedef T * Tref;
  // Construction/Destruction
public:
  Vector();
  Vector(const Vector<T>& x);
  ~Vector();

public:
  int length;
  int Delete;
  // For holding the data
  T * data;

public:
  void allocate(int l);
  void deallocate();
  void fastallocate(int l);
  
  inline void set(int index, T& newval);

  // for ptr setting (i.e. no copying)
  void setptr(T * vals, int len);
  void setptr(Vector<T> & v);
  void setvoidptr(void * x, int len);
  void wrap(Vector<T> & v);
  void setmany(T * vals, int len);

  void * getvoid(){return (void*)data;};
  int getbytelength(){return length*sizeof(T);};

  // Array indexing
  inline T& operator[](int index);
  inline T& get(int index);

  // Assignment
  void copy(T * newdata, int len);
  inline Vector<T>& operator=(const Vector<T>& newval);
  inline Vector<T>& operator=(T scalar);
  void append(T scalar);

  // Arithmetic
  inline Vector<T>& operator*=(const T scalar);
  inline Vector<T>& operator/=(const T scalar);
  inline Vector<T>& operator-=(const T scalar);
  inline Vector<T>& operator*=(const Vector<T>& newval);
  inline Vector<T>& operator/=(const Vector<T>& newval);
  inline Vector<T>& operator+=(const Vector<T>& newval); 
  inline Vector<T>& operator-=(const Vector<T>& newval);
  Vector<T> operator-(const Vector<T>& a);
  Vector<T> operator+(const Vector<T>& a);
  Vector<T> operator/(const T scalar);
  Vector<T> operator*(const T scalar);
  Vector<T> operator/(const Vector<T>& a);
  Vector<T> operator*(const Vector<T>& a);

  // Comparison
  int operator==(const Vector<T>& a);
  int operator!=(const Vector<T>& a);

  // Other
  T distance(const Vector<T>& a); // distance to a
  T distance2(const Vector<T>& a); // distance^2 to a
  T dot(const Vector<T>& a); // dot product
  T normalize(); // to unit length and return norm
  T normalize2(); // to unit length and return norm^2
  T norm(); // L2 norm
  T max();
  T min();
  int argmax();
  int argmin();
  int find(T x);
  void insert(T x);
  void remove(T x);

  // Memory operations
  void resize(int r); // previous values are kept
  inline void BlockCopyFrom(const Vector<T>& newval,int min,int max,int org=0);
  inline void CopyFrom(const Vector<T>& newval,int org=0);
  void Grow(int r);
  void Shrink(int r);
};

#include "vector.cpp"

#endif






