⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tvvector.h

📁 TV-tree的c实现源码
💻 H
字号:
/*                    COPYRIGHT NOTICE This material was developed by Christos Faloutsos and King-Ip Linat the University of Maryland, College Park, Department of Computer Science.Permission is granted to copy this software, to redistribute iton a nonprofit basis, and to use it for any purpose, subject tothe following restrictions and understandings. 1. Any copy made of this software must include this copyright noticein full. 2. All materials developed as a consequence of the use of thissoftware shall duly acknowledge such use, in accordance with the usualstandards of acknowledging credit in academic research. 3. The authors have made no warranty or representation that theoperation of this software will be error-free or suitable for anyapplication, and they are under under no obligation to provide anyservices, by way of maintenance, update, or otherwise.  The softwareis an experimental prototype offered on an as-is basis. 4. Redistribution for profit requires the express, written permissionof the authors. */// Author : $Author$// Date : $Date$// Id : $Id$// $Id: vector.h,v 1.3 1996/04/18 21:50:24 kilin Exp kilin $ #include <iostream.h>#include <fstream.h>class TVector {    friend ostream& operator<< (ostream&, const TVector&);    friend ostream& operator<< (ostream&, const TVector*&);    friend ofstream& operator< (ofstream&, const TVector&);    friend ofstream& operator< (ofstream&, const TVector*&);    friend istream& operator>> (istream&, TVector&);     friend istream& operator>> (istream&, TVector*&);    friend ifstream& operator> (ifstream&, TVector&);     friend ifstream& operator> (ifstream&, TVector*&); //    friend ifstream& operator>> (ifstream&, TVector&); //    friend ifstream& operator>> (ifstream&, TVector*&);public :    TVector();          // Initialize a vector to be of no dimension    TVector(int dim);          // Initialize a vector of dimension dim     TVector(const TVector&);    ~TVector();    VCOM_TYPE& operator[](int dim) const;      // get component    TVector&    operator=(const TVector&);   // assignment     TVector     operator+(const TVector&) const;   // addition of vector                                                 // v1 = (x1, ...  xn)                                                 // v2 = (y1, ... ym)                                                 // v1 + v2 =                                                 // (v1+y1, ... xm+ym, .. xn)    TVector     operator+(const VCOM_TYPE) const; // add constant to each component    TVector&    operator+=(const TVector&);            TVector&    operator+=(const VCOM_TYPE);          TVector     operator-(const TVector&) const;   // subtraction of vector                                                 // v1 = (x1, ...  xn)                                                 // v2 = (y1, ... ym)                                                 // v1 - v2 =                                                 // (v1-y1, ... xm-ym, .. xn)    TVector     operator-(const VCOM_TYPE) const; // sub constant to each component    TVector&    operator-=(const TVector&);            TVector&    operator-=(const VCOM_TYPE);          TVector     operator-() const;   // uniary minus        TVector     operator*(const VCOM_TYPE) const; // add constant to each component    TVector&    operator*=(const VCOM_TYPE);          TVector     operator*(const int) const; // add constant to each component    TVector&    operator*=(const int);              TVector     operator/(const VCOM_TYPE) const; // add constant to each component    TVector&    operator/=(const VCOM_TYPE);          TVector     operator/(const int) const; // add constant to each component    TVector&    operator/=(const int);          TVector     operator<<(const TVector&) const; // concatate vectors, put new one at the end    TVector&    operator<<=(const TVector&); // concatate vector, put new one at the end     TVector     operator>>(const TVector&) const; // concatate vectors, put new one at the front    TVector&    operator>>=(const TVector&); // concatate vectors, put new one at the front     // relational operators, lexicographical order    int        operator>(const TVector&) const;    int        operator>=(const TVector&) const;    int        operator<(const TVector&) const;    int        operator<=(const TVector&) const;    int        operator==(const TVector&) const;    int        operator!=(const TVector&) const;    int Size() const;                      // Return size of a vector    int ExpectedSize(int dim) const;	   // Return size of a vector of size dim    int GetDim() const;	      // Return the dimension    void Assign(int dim,  VCOM_TYPE val);     // Assign a value    void SetAllCompo(VCOM_TYPE val);	 // Reset to all zeroes;    TVector ProjectFront(int dim) const;    TVector ProjectBack(int dim)  const;    TVector ProjectMid(int start, int dim) const;    TVector* ProjectFrontP(int dim) const;    TVector* ProjectBackP(int dim)  const;    TVector* ProjectMidP(int start, int dim) const;    TVector MinCompo(const TVector&) const;  // return vector containing min compont    TVector MaxCompo(const TVector&) const;  // return vector containing max compont    VCOM_TYPE  Distance(const TVector&) const;   // Hamming distance    VCOM_TYPE  Signed_Distance(const TVector&) const;   // Hamming distance without the absolute value, that is, sum the component wise difference     int  Inrange(const TVector& v, VCOM_TYPE d) const; // return whether vector is within v +- d, component-wise     int  Inrange(const TVector& v, const TVector& v2) const; // return whether vector is within v +- d, component-wise     // Return the position of the first dimesnison that is different    // Return -1 if they are the same (for all their common dimensions)    int  FirstDiffDim(const TVector &v) const;    VCOM_TYPE  SumComponent() const;    VCOM_TYPE  MaxComponent() const;    VCOM_TYPE  MinComponent() const;    TVector& SetNull();    TVector& Abs();private :      int  total_dim;           // dimension of the vector    VCOM_TYPE    *compo;	      // array for the dimensions};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -