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

📄 bigraph.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
📖 第 1 页 / 共 5 页
字号:
// file: $isip/class/dstr/BiGraph/BiGraph.h// version: $Id: BiGraph.h,v 1.12 2003/04/20 22:57:55 parihar Exp $//// make sure definitions are only made once//#ifndef ISIP_BI_GRAPH#define ISIP_BI_GRAPH// isip include files//#ifndef ISIP_DOUBLE_LINKED_LIST#include <DoubleLinkedList.h>#endif#ifndef ISIP_BI_COLOR_HASH#include <BiColorHash.h>#endif#ifndef ISIP_BOOLEAN#include <Boolean.h>#endif#ifndef ISIP_TRIPLE#include <Triple.h>#endif#ifndef ISIP_PAIR#include <Pair.h>#endif#ifndef ISIP_LONG#include <Long.h>#endif#ifndef ISIP_BIGRAPH_VERTEX#include <BiGraphVertex.h>#endif// forward class definitions://  we must define the BiGraphVertex class here first because the header files//  might be short-circuited by the ifndef.//template<class TObject> class DiGraph;template<class TObject> class GraphVertex;template<class TObject> class GraphArc;template<class TObject> class BiColorHash;template<class TObject> class BiGraphVertex;// BiGraph: a generic directed-graph template class. it is implemented//  with something close to an adjacency list, with data held on the//  vertices. each vertex holds both a TObject* and a list of all//  emanating arcs. a graph can be in either USER or SYSTEM allocated//  mode, for a USER-allocated list the TObject data is never copied.//template<class TObject>class BiGraph : private DoubleLinkedList< BiGraphVertex<TObject> > {  //---------------------------------------------------------------------------  //  // public constants  //  //---------------------------------------------------------------------------public:    // define the class name  //  static const String CLASS_NAME;    //----------------------------------------  //  // i/o related constants  //  //----------------------------------------      static const String DEF_PARAM;  static const String PARAM_VERTICES;  static const String PARAM_ARCS;  static const String PARAM_WEIGHTED;  static const String START_NAME;  static const String TERM_NAME;    //----------------------------------------  //  // dummy objects for start and end vertices  //  //----------------------------------------    static const TObject START_OBJ;  static const TObject TERM_OBJ;  //----------------------------------------  //  // indeces for start and end vertices  //  //----------------------------------------  static const long START_INDEX = -1;  static const long TERM_INDEX = -2;      //----------------------------------------  //  // default values and arguments  //  //----------------------------------------  // default values  //  static const boolean DEF_IS_WEIGHTED = true;  // default arguments to methods  //    //----------------------------------------  //  // error codes  //  //----------------------------------------      static const long ERR = 41200;  static const long ERR_EPSCYC = 41201;  static const long ERR_MULPAR = 41202;    //---------------------------------------------------------------------------  //  // protected data  //  //---------------------------------------------------------------------------protected:  // define the object used to hold graph topology in read and write  //  typedef Triple< Pair<Long, Long>, Float, Boolean> TopoTriple;  typedef HashTable< String, BiGraphVertex<TObject> > ReadHash;    // each graph has a dummy start vertex  //  BiGraphVertex<TObject>* start_vertex_d;  // each graph has a dummy terminal vertex  //  BiGraphVertex<TObject>* term_vertex_d;  // each graph has a hash table that associates a color with the  // graph vertices that tell us if the vertex has been  // visited. unless explicitely allocated via the makeBiColorHash  // method this will be a null pointer and all color methods will  // fail.  //  BiColorHash<TObject>* chash_d;    // is the graph weighted?  //  Boolean is_weighted_d;  // the allocation mode  //  DstrBase::ALLOCATION alloc_d;      // debugging parameters  //  static Integral::DEBUG debug_level_d;    // define the memory manager  //  static MemoryManager mgr_d;    //---------------------------------------------------------------------------  //  // required public methods  //  //---------------------------------------------------------------------------public:  // static methods  //  diagnose method is moved outside the class header file and  //  defined in the BiGraphDiagnose.h in order to avoid issues  //  related to preprocessing of the diagnose code.  //  static const String& name();  // method: setDebug  //  static boolean setDebug(Integral::DEBUG debug_level) {    debug_level_d = debug_level;    return true;  }  // other debug methods  //  boolean debug(const unichar* message) const;  // destructor  //  ~BiGraph();  // default constructor  //  BiGraph(DstrBase::ALLOCATION alloc = DEF_ALLOCATION);  // copy constructor  //  BiGraph(const BiGraph<TObject>& copy_graph);    // assign methods:  //  having the same vertex appear in two different graphs is not allowed.  //  thus, memory is created for copied vertices even if the graph is in  //  user-allocating mode!  //  boolean assign(const BiGraph<TObject>& copy_graph);  boolean assign(const DiGraph<TObject>& copy_graph);    boolean assign(DoubleLinkedList<TObject>& data,		 DoubleLinkedList<TopoTriple>& arcs);    // method: operator=  //  BiGraph<TObject>& operator=(const BiGraph<TObject>& arg) {    assign(arg);    return *this;  }  // equality method  //  boolean eq(const BiGraph<TObject>& compare_graph) const;    // i/o methods  //  long sofSize() const;    // method: read  //  boolean read(Sof& sof, long tag) {    return read(sof, tag, name());  }  boolean read(Sof& sof, long tag, const String& name);  // method: write  //  boolean write(Sof& sof, long tag) const {    return write(sof, tag, name());  }  boolean write(Sof& sof, long tag, const String& name) const;  boolean readData(Sof& sof, const String& pname = DEF_PARAM,		   long size = SofParser::FULL_OBJECT, boolean param = true,                   boolean nested = false);  boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;  boolean readDataText(Sof& sof, const String& pname = DEF_PARAM,		       long size = SofParser::FULL_OBJECT,		       boolean param = true,		       boolean nested = false);  boolean readDataBinary(Sof& sof);    boolean writeDataText(Sof& sof, const String& pname,			DoubleLinkedList<TObject>& dlist,			DoubleLinkedList<TopoTriple>& alist) const;  boolean writeDataBinary(Sof& sof, const String& pname,			  DoubleLinkedList<TObject>& dlist,			  DoubleLinkedList<TopoTriple>& alist) const;         // method: new  //  void* operator new(size_t size) {    return mgr_d.get();  }  // method: new[]  //   void* operator new[](size_t size) {    return mgr_d.getBlock(size);  }  // method: delete  //    void operator delete(void* ptr) {    mgr_d.release(ptr);  }  // method: delete[]  //    void operator delete[](void* ptr) {    mgr_d.releaseBlock(ptr);  }  // method: setGrowSize  //    static boolean setGrowSize(long grow_size) {    return mgr_d.setGrow(grow_size);  }  // other memory management methods  //    boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  graph manipulation methods  //  //---------------------------------------------------------------------------  // method: insertArc  //  boolean insertArc(long start_index, long end_index,		    boolean is_epsilon = BiGraphArc<TObject>::DEF_EPSILON,		    float weight = BiGraphArc<TObject>::DEF_WEIGHT) {    return insertArc(getPosition(start_index), getPosition(end_vertex),		     is_epsilon, weight);  }  // other arc insertion methods  //  boolean insertArc(BiGraphVertex<TObject>* start_vertex,		    BiGraphVertex<TObject>* end_vertex,		    boolean is_epsilon = BiGraphArc<TObject>::DEF_EPSILON,		    float weight = BiGraphArc<TObject>::DEF_WEIGHT);    // method: removeArc  //  boolean removeArc(long start_index, long end_index) {    return removeArc(getPosition(start_index), getPosition(end_vertex));  }  // other arc removal methods  //    boolean removeArc(BiGraphVertex<TObject>* start_vertex,		    BiGraphVertex<TObject>* end_vertex);  // insert vertex methods  //  BiGraphVertex<TObject>* insertVertex(TObject* arg);  // remove vertex methods  //  boolean removeVertex();    boolean removeVertex(TObject*& arg);    // item containment methods:  //  boolean find(const TObject* obj);  boolean find(const BiGraphVertex<TObject>* vertex);  boolean contains(const TObject* obj) const;  boolean contains(const BiGraphVertex<TObject>* vertex) const;      //---------------------------------------------------------------------------  //  // class-specific public methods:  //  graph property methods  //  //---------------------------------------------------------------------------      // method: getStart  //  BiGraphVertex<TObject>* getStart() const {    return start_vertex_d;  }  // method: getTerm  //  BiGraphVertex<TObject>* getTerm() const {    return term_vertex_d;  }  // this method extracts the structure of the graph and places them  // in two lists. the first list contains the vertices and the second  // list contains the arcs between the vertices.  //  boolean get(DoubleLinkedList<TObject>& data,	      DoubleLinkedList<TopoTriple>& arcs) const;    // method: isWeighted  //  boolean isWeighted() const {    return is_weighted_d;  }  // method: setWeighted  //  boolean setWeighted(boolean is_weighted = true) {    is_weighted_d = is_weighted;    return true;  }    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  graph ordering methods  //  //---------------------------------------------------------------------------    // topological sort methods  //  boolean topologicalSort(DoubleLinkedList<TObject>& sorted_data,			  boolean partial = false);  // method: getColor  //  Integral::COLOR getColor(const BiGraphVertex<TObject>* v) const {    return chash_d->get(v);  }  // method: setColor  //  boolean setColor(const BiGraphVertex<TObject>* v, Integral::COLOR col) {    return chash_d->set(v, col);  }    // method: releaseColorHash  //  boolean releaseColorHash() {    chash_d->clear(Integral::RESET);        if (chash_d != (BiColorHash<TObject>*)NULL) {      delete chash_d;      chash_d = (BiColorHash<TObject>*)NULL;    }    return true;  }    // other color methods  //  boolean invertColor();  boolean makeColorHash(Integral::COLOR col = Integral::DEF_COLOR);  boolean setColor(Integral::COLOR col);  boolean isColor(Integral::COLOR col);  boolean replaceColor(Integral::COLOR old_col,		       Integral::COLOR new_col);  // methods to do simple depth first search  //  boolean dfsVisit(BiGraphVertex<TObject>& vertex);  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  graph allocation mode methods  //  //---------------------------------------------------------------------------    // method: getAllocationMode  //  DstrBase::ALLOCATION getAllocationMode() const {    return alloc_d;  }  // method: setAllocationMode  //  boolean setAllocationMode(DstrBase::ALLOCATION alloc) {    alloc_d = alloc;    return true;  }    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  double linked list methods  //  //---------------------------------------------------------------------------  // the BiGraph class derives the DoubleLinkedList bases class which  // is used as the primary underlying container class. to prevent the  // user from circumventing the BiGraph's interface and interacting  // directly with the DoubleLinkedList we use private inheritance.  // we define here the methods of the DoubleLinkedList interface that  // the user is permitted access to.  //  using DoubleLinkedList< BiGraphVertex<TObject> >::length;  using DoubleLinkedList< BiGraphVertex<TObject> >::gotoFirst;  using DoubleLinkedList< BiGraphVertex<TObject> >::gotoNext;  using DoubleLinkedList< BiGraphVertex<TObject> >::gotoPrev;  using DoubleLinkedList< BiGraphVertex<TObject> >::getCurr;  using DoubleLinkedList< BiGraphVertex<TObject> >::getFirst;  using DoubleLinkedList< BiGraphVertex<TObject> >::getLast;  using DoubleLinkedList< BiGraphVertex<TObject> >::gotoMark;  using DoubleLinkedList< BiGraphVertex<TObject> >::setMark;  using DoubleLinkedList< BiGraphVertex<TObject> >::gotoPosition;  using DoubleLinkedList< BiGraphVertex<TObject> >::getPosition;    //---------------------------------------------------------------------------  //  // private methods  //  //---------------------------------------------------------------------------private:  // methods to split writeData:  //  the readData needed to be broken up  //  boolean readVertexDataText(Sof& sof_a, SofParser& parser,			     ReadHash& hash) const;  boolean readArcDataText(Sof& sof_a, SofParser& parser,			  ReadHash& hash) const;    // methods to split writeData:  //  the writeData needed to be broken up  //  boolean writeVertexDataText(Sof& sof,			      DoubleLinkedList<TObject>& dlist) const;  boolean writeArcDataText(Sof& sof, 			   DoubleLinkedList<TopoTriple>& alist) const;

⌨️ 快捷键说明

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