📄 andx_05.cc
字号:
index.concat(value); if (by_feature_d.containsKey(index)) { if (by_feature_d.get(index)->find(anno_a)) { by_feature_d.get(index)->remove(); } if (by_feature_d.get(index)->isEmpty()) { by_feature_d.remove(index); } } } // exit gracefully // return true; }// method: getNearestOffset//// arguments:// float offset: (input) anchor offset//// return: logical error status//// method to get the nearest used offset to the specified offset//float AnnotationIndex::getNearestOffset(float offset_a) { // declare local variables // float min_offset = 0.0; float min_delta = 1.0e10; Vector<Float> keys; // check if the hash table of anchor sets is empty // if (ancrset_by_offset_d.isEmpty()) { return min_offset; } // get the vector of keys from the hash table // ancrset_by_offset_d.keys(keys); // loop through the set of keys and find the nearest offset // if (keys.length() == 1) { return (float)keys(0); } for (int i=0; i < keys.length(); i++) { if (Integral::abs(keys(i) - offset_a) < min_delta) { min_offset = keys(i); min_delta = Integral::abs(keys(i) - offset_a); } } // return the nearest offset // return min_offset;}// method: getByOffset//// arguments:// float offset: (input) anchor offset// DoubleLinkedList<Annotation>& list: (input) list of annotations//// return: logical error status//// method that gets the annotations that overlap a particular time offset.// gets all annotations whose start anchor offset is smaller than or// equal to the given offset AND end anchor offset is greater than // or equal to the given offet//boolean AnnotationIndex::getByOffset(float offset_a, DoubleLinkedList<Annotation>& list_a) { // declare local variables // Vector<Float> end_keys; Vector<Float> start_keys; Anchor* anchor = (Anchor*)NULL; Annotation* annotation = (Annotation*)NULL; DoubleLinkedList<Annotation>* alist; // clear the input list to begin with // list_a.clear(); // check to make sure that the offset is greater than zero // if (offset_a < 0.0) { return false; } // get the vector of keys from the start and end offset hash tables // start_by_offset_d.keys(start_keys); end_by_offset_d.keys(end_keys); // loop over the start keys and gets all annotations whose start anchor // offset is smaller than or equal to the given offset // for (int i=0; i < start_keys.length(); i++) { if (start_keys(i) <= offset_a) { // check if the end offset is greater than or equal to the given offet // alist = start_by_offset_d.get(start_keys(i)); for(boolean more = alist->gotoFirst(); more; more = alist->gotoNext()) { annotation = alist->getCurr(); anchor = annotation->getEndAnchor(); if ((anchor != (Anchor*)NULL) && (anchor->getOffset() >= offset_a)) { if (!list_a.contains(annotation)) { list_a.insert(annotation); } } } } } // loop over all end keys and gets all annotations whose end anchor // offset is greater than or equal to the given offet // for (int i=0; i < end_keys.length(); i++) { if (end_keys(i) >= offset_a) { // check if the start offset is smaller than or equal to the given offset // alist = end_by_offset_d.get(end_keys(i)); for(boolean more = alist->gotoFirst(); more; more = alist->gotoNext()) { annotation = alist->getCurr(); anchor = annotation->getStartAnchor(); if ((anchor != (Anchor*)NULL) && (anchor->getOffset() <= offset_a)) { if (!list_a.contains(annotation)) { list_a.insert(annotation); } } } } } // exit gracefully // return true;}// method: getAnnotationByOffset//// arguments:// float offset: (input) anchor offset//// return: logical error status//// method get one of the annotations which overlap a particular time offset.// same as getByOffset except that getAnnotationByOffset returns only// one qualified annotation while getByOffset returns all of them//Annotation* AnnotationIndex::getAnnotationByOffset(float offset_a) { // declare local variables // Vector<Float> end_keys; Vector<Float> start_keys; Anchor* anchor = (Anchor*)NULL; Annotation* annotation = (Annotation*)NULL; DoubleLinkedList<Annotation>* alist; // check to make sure that the offset is greater than zero // if (offset_a < 0.0) { return (Annotation*)NULL; } // get the vector of keys from the start offset hash tables // start_by_offset_d.keys(start_keys); // loop over the start keys and gets all annotations whose start anchor // offset is smaller than or equal to the given offset // for (int i=0; i < start_keys.length(); i++) { if (start_keys(i) <= offset_a) { // check if the end offset is greater than or equal to the given offet // alist = start_by_offset_d.get(start_keys(i)); for(boolean more = alist->gotoFirst(); more; more = alist->gotoNext()) { annotation = alist->getCurr(); anchor = annotation->getEndAnchor(); if ((anchor != (Anchor*)NULL) && (anchor->getOffset() >= offset_a)) { return annotation; } } } } // get the vector of keys from the end offset hash tables // end_by_offset_d.keys(end_keys); // loop over all end keys and gets all annotations whose end anchor // offset is greater than or equal to the given offet // for (int i=0; i < end_keys.length(); i++) { if (end_keys(i) >= offset_a) { // check if the start offset is smaller than or equal to the given offset // alist = end_by_offset_d.get(end_keys(i)); for(boolean more = alist->gotoFirst(); more; more = alist->gotoNext()) { annotation = alist->getCurr(); anchor = annotation->getStartAnchor(); if ((anchor != (Anchor*)NULL) && (anchor->getOffset() <= offset_a)) { return annotation; } } } } // return the annotation // return (Annotation*)NULL; }// method: existsAnnotation//// arguments:// const String& id: (input) annotation id//// return: logical error status//// method to check if the specified annotation exists//boolean AnnotationIndex::existsAnnotation(const String& id_a) { // determine if the annotation exists // return anno_by_id_d.containsKey(id_a);}// method: existsAnchor//// arguments:// const String& id: (input) anchor id//// return: logical error status//// method to check if the specified anchor exists//boolean AnnotationIndex::existsAnchor(const String& id_a) { // determine if the annotation exists // return ancr_by_id_d.containsKey(id_a);}// method: addAnchor//// arguments:// Anchor* ancr: (input) anchor to be added//// return: logical error status//// method to add an anchor to the indexes//boolean AnnotationIndex::addAnchor(Anchor* ancr_a) { // declare local variables // HashKey<Anchor> hashkey; Float offset(ancr_a->getOffset()); DoubleLinkedList<Annotation>* incoming; DoubleLinkedList<Annotation>* outgoing; DoubleLinkedList<Annotation> annlist(DstrBase::USER); DoubleLinkedList<Anchor> tmplist(DstrBase::USER); tmplist.insert(ancr_a); // determine if the offset is present - if not then delete it // if (!ancrset_d.contains(ancr_a)) { ancrset_d.insert(ancr_a); ancr_by_id_d.insert(ancr_a->getId(), ancr_a); } // hash the anchor by the offset // if (ancr_a->getAnchored()) { if (ancrset_by_offset_d.containsKey(offset)) { if (!ancrset_by_offset_d.get(offset)->contains(ancr_a)) { ancrset_by_offset_d.get(offset)->insert(ancr_a); } } else { ancrset_by_offset_d.insert(offset, &tmplist); } // get the incoming and outgoing annotations to/from the anchor // hashkey.assign(ancr_a); incoming = incoming_d.get(hashkey); outgoing = outgoing_d.get(hashkey); // loop over all incoming annotations to the anchor and hash them // by the end anchor offset // if (incoming != (DoubleLinkedList<Annotation>*)NULL) { for (boolean more = incoming->gotoFirst(); more; more = incoming->gotoNext()) { if (end_by_offset_d.containsKey(offset)) { if (!end_by_offset_d.get(offset)->contains(incoming->getCurr())) { end_by_offset_d.get(offset)->insert(incoming->getCurr()); } } else { annlist.clear(); annlist.insert(incoming->getCurr()); end_by_offset_d.insert(offset, &annlist); } } } // loop over all outgoing annotations from the anchor and hash them // by the start anchor offset // if (outgoing != (DoubleLinkedList<Annotation>*)NULL) { for (boolean more = outgoing->gotoFirst(); more; more = outgoing->gotoNext()) { if (start_by_offset_d.containsKey(offset)) { if (!start_by_offset_d.get(offset)->contains(outgoing->getCurr())) { start_by_offset_d.get(offset)->insert(outgoing->getCurr()); } } else { annlist.clear(); annlist.insert(outgoing->getCurr()); start_by_offset_d.insert(offset, &annlist); } } } } // exit gracefully // return true;}// method: deleteAnchor//// arguments:// Anchor* ancr: (input) anchor to be deleted//// return: logical error status//// method to delete an anchor to the indexes//boolean AnnotationIndex::deleteAnchor(Anchor* ancr_a) { // declare local variables // Annotation* anno; HashKey<Anchor> hashkey; Float offset(ancr_a->getOffset()); DoubleLinkedList<Annotation>* incoming; DoubleLinkedList<Annotation>* outgoing; // determine if the offset is present - if not then delete it // if (ancrset_d.find(ancr_a)) { ancrset_d.remove(); ancr_by_id_d.remove(ancr_a->getId()); } // delete the anchor by the offset // if (ancr_a->getAnchored()) { ancrset_by_offset_d.remove(offset); // get the incoming and outgoing annotations to/from the anchor // hashkey.assign(ancr_a); incoming = incoming_d.get(hashkey); outgoing = outgoing_d.get(hashkey); // loop over all incoming annotations to the anchor and remove them // by the end anchor offset // if (incoming != (DoubleLinkedList<Annotation>*)NULL) { for (boolean more = incoming->gotoFirst(); more; more = incoming->gotoNext()) { if (end_by_offset_d.containsKey(offset)) { anno = incoming->getCurr(); if (end_by_offset_d.get(offset)->find(anno)) { end_by_offset_d.get(offset)->remove(); } if (end_by_offset_d.get(offset)->isEmpty()) { end_by_offset_d.remove(offset); } } } } // loop over all outgoing annotations from the anchor and remove them // by the start anchor offset // if (outgoing != (DoubleLinkedList<Annotation>*)NULL) { for (boolean more = outgoing->gotoFirst(); more; more = outgoing->gotoNext()) { if (start_by_offset_d.containsKey(offset)) { anno = outgoing->getCurr(); if (start_by_offset_d.get(offset)->find(anno)) { start_by_offset_d.get(offset)->remove(); } if (start_by_offset_d.get(offset)->isEmpty()) { start_by_offset_d.remove(offset); } } } } } // exit gracefully // return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -