int QtXmlWrapper::getpar(const std::string &name, int defaultpar, int min, int max) const { QDomElement tmp = findElement( d->m_node, "par", "name", name.c_str() ); if( tmp.isNull() || !tmp.hasAttribute( "value" ) ) { return defaultpar; } int val = tmp.attribute( "value" ).toInt(); if(val < min) val = min; else if(val > max) val = max; return val; }
int main() { int data, ch; while (1) { printf("*****MENU*****\n"); printf("1. Insertion in Binary Search Tree\n"); printf("2. Deletion in Binary Search Tree\n"); printf("3. Search Element in Binary Search Tree\n"); printf("4. Inorder traversal\n5. Exit\n"); printf("\n\nEnter your choice:"); scanf("%d", &ch); switch (ch) { case 1: while (1) { printf("Enter your data:"); scanf("%d", &data); insertion(&root, data); printf("Continue Insertion?(0/1):"); scanf("%d", &ch); if (!ch) break; } break; case 2: printf("Enter your data:"); scanf("%d", &data); deletion(&root, NULL, data); break; case 3: printf("Enter value for data:"); scanf("%d", &data); findElement(root, data); break; case 4: printf("Inorder Traversal:\n"); traverse(root); printf("\n"); break; case 5: exit(0); default: printf("You have entered wrong option\n"); break; } } return 0; }
//removes elt from the set and returns if the set has changed //O(n) bool removeElement(SET *sp, char *elt){ assert(sp != NULL && elt != NULL); int index; //use findELement to obatin index of elt index = findElement(sp, elt); if(index == -1) return false; //delete elt and rplace it with the last element in the set free(sp->elts[index]); sp->elts[index] = sp->elts[sp->count - 1]; sp->count--; return true; }
double frameFieldBackgroundMesh2D::angle(double u, double v) { MElement *e = const_cast<MElement*>(findElement(u, v)); if (!e) return -1000.0; std::vector<double> val = get_nodal_values(e,angles); std::vector<double> element_uvw = get_element_uvw_from_xyz(e,u,v,0.); std::vector<double> cosvalues(e->getNumVertices()), sinvalues(e->getNumVertices()); for (int i=0; i<e->getNumVertices(); i++) { cosvalues[i]=cos(4*val[i]); sinvalues[i]=sin(4*val[i]); } double cos4 = e->interpolate(&cosvalues[0], element_uvw[0], element_uvw[1], element_uvw[2], 1, order); double sin4 = e->interpolate(&sinvalues[0], element_uvw[0], element_uvw[1], element_uvw[2], 1, order); double a = atan2(sin4,cos4)/4.0; normalizeAngle (a); return a; }
//Big O runtime 0(n) Remove an element from set *sp using linear search bool removeElement(SET *sp, char *elt) { assert(sp!=NULL); bool found; //Find the element to delete int temp = findElement(sp, elt, &found); //If the element is not found if (temp == -1) return false; //Replacing the element to be deleted with the last element of the array sp->elts[temp] = sp->elts[sp->count-1]; sp->count--; return true; }
//Removes the element and decreases count //Best O(1) Worst O(n) bool removeElement(SET *sp, char *elt) { bool found; assert(sp!=NULL && elt!=NULL); int pos = findElement(sp, elt, &found); //Only remove elements that are actually in the set if(found) { free(sp->elts[pos]); sp->flags[pos]=DELETED; sp->count--; return true; } else return false; }
//Assuming the element is not present and there is room, adds the element. //Best O(1) Worst O(n) bool addElement(SET *sp, char *elt) { assert(sp!=NULL && elt!=NULL); bool found; int pos = findElement(sp, elt, &found); //only adds if the element isn't present if(found||(sp->count>=sp->length)||pos==-1) return false; else { sp->elts[pos]=strdup(elt); sp->flags[pos]=FILLED; sp->count++; return true; } }
static Element * getFunctionElement (FileDescriptor fileDescriptor, const FunctionMethods *methods, int create) { Queue *functions = getFunctionQueue(create); if (functions) { { FunctionKey key = { .fileDescriptor = fileDescriptor, .methods = methods }; { Element *element = findElement(functions, testFunctionEntry, &key); if (element) return element; } } if (create) { FunctionEntry *function; if ((function = malloc(sizeof(*function)))) { function->fileDescriptor = fileDescriptor; function->methods = methods; if ((function->operations = newQueue(deallocateOperationEntry, NULL))) { { static AsyncQueueMethods methods = { .cancelRequest = cancelOperation }; setQueueData(function->operations, &methods); } if (methods->beginFunction) methods->beginFunction(function); { Element *element = enqueueItem(functions, function); if (element) return element; } deallocateQueue(function->operations); } free(function); } else {
/* addElement uses findElement to get the locn of the nearest empty * spot to the home locn O(n) at worst case, * expect however is O(1). */ bool addElement(SET *sp, char *elt) { bool found; int locn; assert(sp != NULL); assert(elt != NULL); locn = findElement(sp, elt, &found); /* if elt already exist in array, * we do not want to put another one in*/ if(found) return false; sp->flags[locn] = FILLED; sp->elts[locn] = strdup(elt); sp->count++; return true; }
/* removeElement uses findElement to locate the postion of the * desired elt, and removes it from the array O(n) at worst case, expect however is O(1). */ bool removeElement(SET *sp, char *elt) { bool found; int locn; assert(sp != NULL); assert(elt != NULL); locn = findElement(sp, elt, &found); if(!found)// if elt is not found, the it can not be deleted return false; sp->flags[locn] = DELETED; free(sp->elts[locn]); sp->count--; return true; }
// -------------------------------------------------------------------- SceneElement* SceneGraph::findElement ( const MDagPath& dagPath ) { static bool output = false; for ( SceneElementsList::iterator it = mExportNodesTree.begin(); it != mExportNodesTree.end(); ++it ) { SceneElement* sceneElement = *it; if ( sceneElement->getPath() == dagPath ) return ( sceneElement ); // Recursive call for all the child elements for ( uint i=0; i<sceneElement->getChildCount(); ++i ) { SceneElement* childElement = sceneElement->getChild ( i ); if ( ( childElement = findElement ( dagPath, childElement ) ) != NULL) return childElement; } } return NULL; }
void GUICanvas::_getMeshInfo(UINT32 renderElementIdx, UINT32& numVertices, UINT32& numIndices, GUIMeshType& type) const { Vector2 offset((float)mLayoutData.area.x, (float)mLayoutData.area.y); Rect2I clipRect = mLayoutData.getLocalClipRect(); buildAllTriangleElementsIfDirty(offset, clipRect); const CanvasElement& element = findElement(renderElementIdx); renderElementIdx -= element.renderElemStart; switch (element.type) { case CanvasElementType::Image: { UINT32 numQuads = element.imageSprite->getNumQuads(renderElementIdx); numVertices = numQuads * 4; numIndices = numQuads * 6; type = GUIMeshType::Triangle; break; } case CanvasElementType::Text: { UINT32 numQuads = element.textSprite->getNumQuads(renderElementIdx); numVertices = numQuads * 4; numIndices = numQuads * 6; type = GUIMeshType::Triangle; break; } case CanvasElementType::Line: numVertices = element.clippedNumVertices; numIndices = element.clippedNumVertices; type = GUIMeshType::Line; break; case CanvasElementType::Triangle: numVertices = element.clippedNumVertices; numIndices = element.clippedNumVertices; type = GUIMeshType::Triangle; break; default: numVertices = 0; numIndices = 0; type = GUIMeshType::Triangle; break; } }
void Nequeo::Collections::Pool::hashmap<Key, T, Compare, Hash>::insert(const value_type& x) { int bucket; // Try to find the element. typename ListType::iterator it = findElement(x.first, bucket); if (it != (*mElems)[bucket].end()) { // The element already exists. return; } else { // We didn’t find the element, so insert a new one. mSize++; (*mElems)[bucket].insert((*mElems)[bucket].end(), x); } }
/* * Function: addElement * * Complexity: O(1) best case. O(n) worst case. * * Description: Add elt to the set pointed to by SP, and return whether the * set changed. A new element is inserted in its proper hash position * found via findElement. If the number of elements in the set is Max_Unique, * the array is alreafy full and addElement does not make changes. * * */ bool addElement(SET *sp, char *elt) { bool found; int locn = findElement(sp, elt, &found); if (sp->count == Max_Unique) return false; if (found) return false; if(!found){ sp->elts[locn] = strdup(elt); } sp->flags[locn] = FILLED; sp->count++; return true; }
void PriorityQueue::removeElement(int id) { int location = -1; vector<Thread * > * point = findInQueue(id , location); if (location == -1) { location = findElement(id , _Blocked); if (location != -1) { point = &_Blocked; } } if (location != -1) { point->erase(point->begin() + location); decreaseSize(); } return; }
void RowAggregator::mergeElement(const void * otherElement) { unsigned hash = elementHasher->hash(otherElement); void * match = findElement(hash, otherElement); if (match) { AggregateRowBuilder *rowBuilder = static_cast<AggregateRowBuilder *>(match); totalSize -= rowBuilder->querySize(); size32_t sz = helper.mergeAggregate(*rowBuilder, otherElement); rowBuilder->setSize(sz); totalSize += sz; } else { Owned<AggregateRowBuilder> rowBuilder = new AggregateRowBuilder(rowAllocator, hash); rowBuilder->setSize(cloneRow(*rowBuilder, otherElement, rowAllocator->queryOutputMeta())); addNew(rowBuilder.getClear(), hash); } }
int bipartGraphInsertEdge(bpGraph_t* pGraph, int srcVertId, int tarVertId, int srcPartite) { int numVertsSrc, numVertsTar; char *vertExistsSrc, *vertExistsTar; binTreeNode_t *adjTree; linkedList_t *neighbours; if (srcPartite == 1) { numVertsSrc = pGraph->numVertsP1; numVertsTar = pGraph->numVertsP2; vertExistsSrc = pGraph->vertExistsP1; vertExistsTar = pGraph->vertExistsP2; adjTree = pGraph->adjTreeP1; } else if (srcPartite == 2) { numVertsSrc = pGraph->numVertsP2; numVertsTar = pGraph->numVertsP1; vertExistsSrc = pGraph->vertExistsP2; vertExistsTar = pGraph->vertExistsP1; adjTree = pGraph->adjTreeP2; } else { return ERROR_VALUE; } if (srcVertId >= numVertsSrc || tarVertId >= numVertsTar || !vertExistsSrc[srcVertId] || !vertExistsTar[tarVertId] || (neighbours = getValue(adjTree, srcVertId)) == NULL) { return ERROR_VALUE; } if (findElement(neighbours, tarVertId)) { return EXISTING_EDGE; } addNode(neighbours, tarVertId); return NEW_EDGE; } /* end of bipartGraphInsertEdge() */
const SpriteMaterialInfo& GUICanvas::_getMaterial(UINT32 renderElementIdx) const { static const SpriteMaterialInfo defaultMatInfo; const CanvasElement& element = findElement(renderElementIdx); switch (element.type) { case CanvasElementType::Line: return mTriangleElementData[element.dataId].matInfo; case CanvasElementType::Image: return element.imageSprite->getMaterialInfo(renderElementIdx); case CanvasElementType::Text: return element.textSprite->getMaterialInfo(renderElementIdx); case CanvasElementType::Triangle: return mTriangleElementData[element.dataId].matInfo; default: return defaultMatInfo; } }
int bipartGraphFindEdge(bpGraph_t* graph, int srcVertId, int tarVertId, int srcPartite) { int numVertsSrc, numVertsTar; char *vertExistsSrc, *vertExistsTar; binTreeNode_t *adjTree; linkedList_t *neighbours; if (srcPartite == 1) { numVertsSrc = graph->numVertsP1; numVertsTar = graph->numVertsP2; vertExistsSrc = graph->vertExistsP1; vertExistsTar = graph->vertExistsP2; adjTree = graph->adjTreeP1; } else if (srcPartite == 2) { numVertsSrc = graph->numVertsP2; numVertsTar = graph->numVertsP1; vertExistsSrc = graph->vertExistsP2; vertExistsTar = graph->vertExistsP1; adjTree = graph->adjTreeP2; } else { return ERROR_VALUE; } if (srcVertId >= numVertsSrc || tarVertId >= numVertsTar || !vertExistsSrc[srcVertId] || !vertExistsTar[tarVertId]) { return NOT_FOUND; } neighbours = getValue(adjTree, srcVertId); if (neighbours == NULL) { return ERROR_VALUE; } return findElement(neighbours, tarVertId); } /* end of bipartGraphFindEdge() */
void ClickToFlash::load() { findElement(); if (element_.isNull()) { qWarning("Click2Flash: Cannot find Flash object."); } else { acceptedUrl = url_; acceptedArgNames = argumentNames_; acceptedArgValues = argumentValues_; QString js = "var c2f_clone=this.cloneNode(true);var c2f_parentNode=this.parentNode;" "var c2f_substituteElement=document.createElement(this.tagName);" "c2f_substituteElement.width=this.width;c2f_substituteElement.height=this.height;" "c2f_substituteElement.type=\"application/futuresplash\";" "this.parentNode.replaceChild(c2f_substituteElement,this);setTimeout(function(){" "c2f_parentNode.replaceChild(c2f_clone,c2f_substituteElement);},250);"; element_.evaluateJavaScript(js); } }
void setPred(t_basic_block *block, t_basic_block *pred) { /* preconditions */ if (block == NULL) { cflow_errorcode = CFLOW_BBLOCK_UNDEFINED; return; } if (pred == NULL) { cflow_errorcode = CFLOW_INVALID_BBLOCK; return; } /* test if the block is already inserted in the list of predecessors */ if (findElement(block->pred, pred) == NULL) { block->pred = addElement(block->pred, pred, -1); pred->succ = addElement(pred->succ, block, -1); } }
bool AXmlElement::emitXmlFromPath( const AString& xpath, AOutputBuffer& target, int indent //= -1 ) const { const AXmlElement *pNode = findElement(xpath); if (pNode) { AXmlElement::CONTAINER::const_iterator cit = pNode->m_Content.begin(); while (cit != pNode->m_Content.end()) { (*cit)->emit(target, indent); ++cit; } return true; } else return false; }
// If element is not found, add element bool addElement(SET *sp, char *elt){ bool found; // find index by calling findElement assert(sp != NULL || sp->words != 0); int index = findElement(sp, elt, &found); // if element exists return false if (found == true) return false; else { // assign value for elt elt = strdup(elt); // set index to elt sp->words[index] = elt; // Set value to filled sp->status[index] = 'F'; // increment count sp->count++; return true; } };
static void enqueueElement (Element *element) { Queue *queue = element->queue; if (queue->head) { Element *reference; int newHead = 0; if (queue->compareItems) { FindReferenceElementData fre = { .queue = queue, .item = element->item }; if (!(reference = findElement(queue, findReferenceElement, &fre))) { reference = queue->head; } else if (reference == queue->head) { newHead = 1; } } else {
/* * DeclareElement - see genx.h for details */ genxElement genxDeclareElement(genxWriter w, genxNamespace ns, constUtf8 type, genxStatus * statusP) { genxElement old; genxElement el; if ((w->status = checkNCName(w, type)) != GENX_SUCCESS) { *statusP = w->status; return NULL; } /* already declared? */ old = findElement(&w->elements, (ns == NULL) ? NULL : ns->name, type); if (old) return old; if ((el = (genxElement) allocate(w, sizeof(struct genxElement_rec))) == NULL) { w->status = *statusP = GENX_ALLOC_FAILED; return NULL; } el->writer = w; el->ns = ns; if ((el->type = copy(w, type)) == NULL) { w->status = *statusP = GENX_ALLOC_FAILED; return NULL; } if ((w->status = listAppend(&w->elements, el)) != GENX_SUCCESS) { *statusP = w->status; return NULL; } *statusP = GENX_SUCCESS; return el; }
// add element in correct ordered location bool addElement (SET *sp, char *elt) { // checks if empty set assert (sp->len != 0 || sp != NULL); // determine max number of elements if (sp -> count == sp -> len) { return false; } bool f; // pass f by reference int index = findElement (sp, elt, &f); if (f == true) { return false; } elt = strdup(elt); // allocate memory for string from buffer paramater // shift elements beyond added element right one index for (int i = (sp->count-1); i >= index; i--) sp->words[i+1]= sp->words[i]; sp -> words[index] = elt; // insert element into set sp -> count++; // increment counter return true; }
//Removes the element and decreases count //O(n) bool removeElement(SET *sp, char *elt) { assert(sp!=NULL && elt!=NULL); //Don't remove from an empty set if(sp->count==0) return false; bool found; int pos = findElement(sp, elt, &found); int i; if(found) { //Removes specified element by shifting all greater elements to the left free(sp->elts[pos]); for(i = pos; i < sp->count-1; i++) sp->elts[i]=sp->elts[i+1]; sp->count--; return true; } else return false; }
std::string QtXmlWrapper::getparstr(const std::string &name, const std::string &defaultpar) const { QDomNode tmp = findElement( d->m_node, "string", "name", name.c_str() ); if( tmp.isNull() || !tmp.hasChildNodes() ) { return defaultpar; } tmp = tmp.firstChild(); if( tmp.nodeType() == QDomNode::ElementNode && !tmp.toElement().tagName().isEmpty() ) { return tmp.toElement().tagName().toUtf8().constData(); } if( tmp.nodeType() == QDomNode::TextNode && !tmp.toText().data().isEmpty() ) { return tmp.toText().data().toUtf8().constData(); } return defaultpar; }
void QtXmlWrapper::getparstr(const std::string &name, char *par, int maxstrlen) const { ZERO(par, maxstrlen); QDomNode tmp = findElement( d->m_node, "string", "name", name.c_str() ); if( tmp.isNull() || !tmp.hasChildNodes() ) { return; } tmp = tmp.firstChild(); if( tmp.nodeType() == QDomNode::ElementNode ) { snprintf(par, maxstrlen, "%s", tmp.toElement().tagName().toUtf8().constData() ); return; } if( tmp.nodeType() == QDomNode::TextNode ) { snprintf(par, maxstrlen, "%s", tmp.toText().data().toUtf8().constData() ); return; } }
/* *Calls findElement to check if element exsists in the array. *If the element exsists in the array its position in the array is returned. *The element is deleted then replaced by the element that was initialy in the final spot of the array. *O(n) */ bool removeElement(SET *sp, char *elt) { assert(sp!=NULL && elt!=NULL); bool found = false; if (sp->count == sp->length) { return found; } int i = (findElement(sp, elt)); if (i != -1) { free(sp->elts[i]); sp->elts[i] = sp->elts[sp->count-1]; sp->count--; found = true; } return found; }