📄 bigraph.h
字号:
TopoTriple triple(pair, weight, epsilon); arcs_a.insert(&triple); } } // iterate over all out going arcs from the destination vertex // for (boolean arcs = term_vertex_d->gotoFirstChild(); arcs; arcs = term_vertex_d->gotoNextChild()) { // retrieve the current arc // arc = term_vertex_d->getCurrChild(); // get the arc weight // weight = arc->getWeight(); // get the epsilon flag // epsilon = arc->getEpsilon(); // get the destination vertex // dvert = arc->getVertex(); // get the position of the source vertex // Long index(this->TERM_INDEX); src_pos = index; // get the position of the destination vertex // if (dvert == this->getStart()) { Long index(this->START_INDEX); dst_pos = index; } else if (dvert == this->getTerm()) { Long index(this->TERM_INDEX); dst_pos = index; } else { BiGVKey<TObject> dst_key(dvert); dst_pos = *(khash.get(dst_key)); } // add the parameters to the alist // Pair<Long, Long> pair(src_pos, dst_pos); Triple<Pair<Long, Long>, Float, Boolean> triple(pair, weight, epsilon); arcs_a.insert(&triple); } // exit gracefully // return true;}//---------------------------------------------------------------------------//// class-specific public methods:// insert/remove vertex methods////---------------------------------------------------------------------------// method: insertVertex//// arguments:// TObject* obj: (input) object to insert// // return: a BiGraphVertex<TObject>* containing the objected to be added//// this method inserts a new object on the graph and return the created// vertex//template<class TObject>BiGraphVertex<TObject>* BiGraph<TObject>::insertVertex(TObject* obj_a) { // perform error checking // if (obj_a == (TObject*)NULL) { Error::handle(name(), L"insertVertex", Error::ARG, __FILE__, __LINE__); return (BiGraphVertex<TObject>*)NULL; } // declare local variables and allocate a new BiGraphVertex object // TObject* new_obj = (TObject*)NULL; BiGraphVertex<TObject>* v = new BiGraphVertex<TObject>(); // when the graph is in SYSTEM mode make a copy of the object // if (getAllocationMode() == SYSTEM) { new_obj = new TObject(*obj_a); } // assign the object pointer when in USER mode // else { new_obj = obj_a; } // set the object on vertex // v->setItem(new_obj); // set the parent graph for the vertex // v->setParentGraph(this); // add vertex on the graph // DoubleLinkedList< BiGraphVertex<TObject> >::insert(v); // exit gracefully // return v;}// method: removeVertex//// arguments:// // return: a BiGraphVertex<TObject>* containing the objected to be added//// this method removes the current vertex from the graph//template<class TObject>boolean BiGraph<TObject>::removeVertex() { // declare local variables // BiGraphVertex<TObject>* vertex; // make sure the current vertex is valid // if (this->getCurr() == (BiGraphVertex<TObject>*)NULL) { return Error::handle(name(), L"removeVertex", Error::ARG, __FILE__, __LINE__); } // get the current vertex // BiGraphVertex<TObject>* this_vertex = (BiGraphVertex<TObject>*)this->getCurr(); // when in SYSTEM mode make a copy of the object data // if (getAllocationMode() == SYSTEM) { delete this_vertex->getItem(); } // save the current state so we can return to the node after we // search for other arcs. // this->setMark(); // if the start vertex points to the vertex we are about to delete // then remove the arc // BiGraphVertex<TObject>* start_vertex = this->getStart(); for (boolean morea = start_vertex->gotoFirstChild(); morea; morea = start_vertex->gotoNextChild()) { if (this_vertex == start_vertex->getCurrChild()->getVertex()) { start_vertex->removeArcChild(); } } for (boolean morea = start_vertex->gotoFirstParent(); morea; morea = start_vertex->gotoNextParent()) { if (this_vertex == start_vertex->getCurrParent()->getVertex()) { start_vertex->removeArcParent(); } } // if the term vertex points to the vertex we are about to delete // then remove the arc // BiGraphVertex<TObject>* term_vertex = this->getTerm(); for (boolean morea = term_vertex->gotoFirstChild(); morea; morea = term_vertex->gotoNextChild()) { if (this_vertex == term_vertex->getCurrChild()->getVertex()) { term_vertex->removeArcChild(); } } for (boolean morea = term_vertex->gotoFirstParent(); morea; morea = term_vertex->gotoNextParent()) { if (this_vertex == term_vertex->getCurrParent()->getVertex()) { term_vertex->removeArcParent(); } } // now search for all arcs comming into this vertex so they can be // removed. // for (boolean moren = gotoFirst(); moren; moren = gotoNext()) { // retrieve the current vertex // vertex = (BiGraphVertex<TObject>*)this->getCurr(); // iterate over all arcs in the current vertex // for (boolean morea = vertex->gotoFirstChild(); morea; morea = vertex->gotoNextChild()) { // if the destination vertex is the same as the vertex we are // about to delete then remove the arc // if (this_vertex == vertex->getCurrChild()->getVertex()) { vertex->removeArcChild(); } } // iterate over all arcs in the current vertex // for (boolean morea = vertex->gotoFirstParent(); morea; morea = vertex->gotoNextParent()) { // if the destination vertex is the same as the vertex we are // about to delete then remove the arc // if (this_vertex == vertex->getCurrParent()->getVertex()) { vertex->removeArcParent(); } } } // restore the previous state. this is the vertex we will actually // remove. // this->gotoMark(); // remove the object from the linked list // boolean status = false; BiGraphVertex<TObject>* graph_vertex; status = DoubleLinkedList< BiGraphVertex<TObject> >::remove(graph_vertex); delete graph_vertex; return status;}// method: removeVertex//// arguments:// TObject* obj: (input) object to remove// // return: a BiGraphVertex<TObject>* containing the objected to be added//// this method removes the current vertex from the graph and// outputs the objects contained in the deleted vertex//template<class TObject>boolean BiGraph<TObject>::removeVertex(TObject*& obj_a) { // make sure the current vertex is valid // if (this->getCurr() == (BiGraphVertex<TObject>*)NULL) { return Error::handle(name(), L"removeVertex", Error::ARG, __FILE__, __LINE__); } // make sure memory is allocated if we are SYSTEM-allocated // if ((alloc_d == SYSTEM) && (obj_a == (TObject*)NULL)) { return (Error::handle(name(), L"removeVertex", Error::NULL_ARG, __FILE__, __LINE__)); } // get the current vertex // BiGraphVertex<TObject>* this_vertex = (BiGraphVertex<TObject>*)this->getCurr(); // when in SYSTEM mode make a copy of the object data // if (getAllocationMode() == SYSTEM) { obj_a->assign(*this_vertex->getItem()); delete this_vertex->getItem(); } // when in USER mode assign the object pointer // else { obj_a = this_vertex->getItem(); } // remove all outgoing arcs from the vertex // this_vertex->removeAllArcsChild(); // save the current state so we can return to the node after we // search for other arcs. // this->setMark(); // if the start vertex points to the vertex we are about to delete // then remove the arc // BiGraphVertex<TObject>* start_vertex = this->getStart(); for (boolean morea = start_vertex->gotoFirstChild(); morea; morea = start_vertex->gotoNextChild()) { if (this_vertex == start_vertex->getCurrChild()->getVertex()) { start_vertex->removeArcChild(); } } for (boolean morea = start_vertex->gotoFirstParent(); morea; morea = start_vertex->gotoNextParent()) { if (this_vertex == start_vertex->getCurrParent()->getVertex()) { start_vertex->removeArcParent(); } } // if the term vertex points to the vertex we are about to delete // then remove the arc // BiGraphVertex<TObject>* term_vertex = this->getTerm(); for (boolean morea = term_vertex->gotoFirstChild(); morea; morea = term_vertex->gotoNextChild()) { if (this_vertex == term_vertex->getCurrChild()->getVertex()) { term_vertex->removeArcChild(); } } for (boolean morea = term_vertex->gotoFirstParent(); morea; morea = term_vertex->gotoNextParent()) { if (this_vertex == term_vertex->getCurrParent()->getVertex()) { term_vertex->removeArcParent(); } } // now search for all arcs comming into this vertex so they can be // removed. // for (boolean moren = gotoFirst(); moren; moren = gotoNext()) { // retrieve the current vertex // BiGraphVertex<TObject>* vertex = (BiGraphVertex<TObject>*)this->getCurr(); // iterate over all arcs in the current vertex // for (boolean morea = vertex->gotoFirstChild(); morea; morea = vertex->gotoNextChild()) { // if the destination vertex is the same as the vertex we are // about to delete then remove the arc // if (this_vertex == vertex->getCurrChild()->getVertex()) { vertex->removeArcChild(); } } // iterate over all arcs in the current vertex // for (boolean morea = vertex->gotoFirstParent(); morea; morea = vertex->gotoNextParent()) { // if the destination vertex is the same as the vertex we are // about to delete then remove the arc // if (this_vertex == vertex->getCurrParent()->getVertex()) { vertex->removeArcParent(); } } } // restore the previous state. this is the vertex we will actually // remove. // this->gotoMark(); // remove the object from the linked list // boolean status = false; BiGraphVertex<TObject>* graph_vertex; status = DoubleLinkedList< BiGraphVertex<TObject> >::remove(graph_vertex); delete graph_vertex; return status;}// method: contains//// arguments:// TObject* obj: (input) the object to be found//// return: a boolean value indicating status//// this method determines if the input object is in the list of vertices//template<class TObject>boolean BiGraph<TObject>::contains(const TObject* obj_a) const { // check if the input object is NULL // if (obj_a == (TObject*)NULL) { return Error::handle(name(), L"contains", Error::NULL_ARG, __FILE__, __LINE__); } // save the current position // const_cast<BiGraph<TObject>* >(this)->setMark(); // temporary variables // boolean obj_found = false; boolean more_nodes = const_cast<BiGraph<TObject>* >(this)->gotoFirst(); // search from the beginning for the item // while (!obj_found && more_nodes) { // get the current vertex // BiGraphVertex<TObject>* this_vertex = (BiGraphVertex<TObject>*) const_cast<BiGraph<TObject>* >(this)->getCurr(); // get the object contained in the vertex // TObject* this_obj = this_vertex->getItem(); // compare the objects for equality // obj_found = obj_a->eq(*this_obj); if (!obj_found) { more_nodes = const_cast<BiGraph<TObject>* >(this)->gotoNext(); } } // restore the previous position // const_cast<BiGraph<TObject>* >(this)->gotoMark(); // return whether or not the object was found // return obj_found; }// method: contains//// arguments:// BiGraphVertex<TObject>* vertex: (input) the vertex to be found//// return: a boolean value indicating status//// this method determines if the input vertex is in the list of// vertices. note that we can't just call list contains since we only// want to compare pointers, not values.//template<class TObject>booleanBiGraph<TObject>::contains(const BiGraphVertex<TObject>* vertex_a) const { // check if the input object is NULL // if (vertex_a == (BiGraphVertex<TObject>*)NULL) { return Error::handle(name(), L"contains", Error::NULL_ARG, __FILE__, __LINE__); } // save the current position // const_cast<BiGraph<TObject>* >(this)->setMark(); // temporary variables // boolean vertex_found = false; boolean more_nodes = const_cast<BiGraph<TObject>* >(this)->gotoFirst(); // search from the beginning for the item // while (!vertex_found && more_nodes) { // get the current vertex // BiGraphVertex<TObject>* this_vertex = (BiGraphVertex<TObject>*) const_cast<BiGraph<TObject>* >(this)->getCurr(); // compare the pointers for equality // if (this_vertex == vertex_a) { vertex_found = true; } if (!vertex_found) { more_nodes = const_cast<BiGraph<TObject>* >(this)->gotoNext(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -