bool ChartElemNavaids::addIntersection(const Intersection& intersection, QDomElement& element, 
                                       QDomDocument& dom_doc, QString& err_msg)
{
    QString leaf_id = getLeafID(intersection);

    // check for double entries
    if (containsLeaf(leaf_id)) 
    {
        err_msg = QString("Double Intersection entry detected: (%1)").arg(intersection.getId());
        return false;
    }
    
    // process the INTERSECTION

    ChartElemIntersection* chart_elem_intersection = 
        new ChartElemIntersection(this, m_chart_model, intersection);
    MYASSERT(chart_elem_intersection);
    
    if (!chart_elem_intersection->loadFromDomElement(element, dom_doc, err_msg)) 
    {
        delete chart_elem_intersection;
        return false;
    }

    addLeaf(leaf_id, chart_elem_intersection);
    return true;
}
Example #2
0
File: p6.c Project: itsmarky10/ucd
Tree * addLeaf(Tree * t, pid_t pid, int proc)
{
    if (NULL == t) {
        t = treealloc();
        t->pid = pid;
        t->proc = proc;
        t->left = NULL;
        t->right = NULL;
    } else if (proc < t->proc) {
        t->left = addLeaf(t->left, pid, proc);
    } else if (proc > t->proc) {
        t->right = addLeaf(t->right, pid, proc);
    }

    return t;
}
bool ChartElemNavaids::addAirport(const Airport& airport,
                                  QDomElement& element, 
                                  QDomDocument& dom_doc,
                                  QString& err_msg)
{
    QString leaf_id = getLeafID(airport);

    // check for double entries
    if (containsLeaf(leaf_id)) 
    {
        err_msg = QString("Double Aiport entry detected: (%1)").arg(airport.getId());
        return false;
    }

    // process the AIRPORT

    ChartElemAirport* chart_elem_airport = new ChartElemAirport(this, m_chart_model, airport);
    MYASSERT(chart_elem_airport);

    if (!chart_elem_airport->loadFromDomElement(element, dom_doc, err_msg)) 
    {
        delete chart_elem_airport;
        return false;
    }

    addLeaf(leaf_id, chart_elem_airport);
    return true;
}
bool ChartElemNavaids::addNdb(const Ndb& ndb,
                              QDomElement& element, 
                              QDomDocument& dom_doc,
                              QString& err_msg)
{
    QString leaf_id = getLeafID(ndb);

    // check for double entries
    if (containsLeaf(leaf_id)) 
    {
        err_msg = QString("Double NDB entry detected: (%1)").arg(ndb.getId());
        return false;
    }
    
    // process the NDB

    ChartElemNdb* chart_elem_ndb = new ChartElemNdb(this, m_chart_model, ndb);
    MYASSERT(chart_elem_ndb != 0);

    if (!chart_elem_ndb->loadFromDomElement(element, dom_doc, err_msg)) 
    {
        delete chart_elem_ndb;
        return false;
    }

    addLeaf(leaf_id, chart_elem_ndb);
    return true;
}
bool ChartElemNavaids::addVor(const Vor& vor, 
                              QDomElement& element, 
                              QDomDocument& dom_doc,
                              QString& err_msg)
{
    QString leaf_id = getLeafID(vor);

    // check for double entries
    if (containsLeaf(leaf_id)) 
    {
        err_msg = QString("Double VOR entry detected: (%1)").arg(vor.getId());
        return false;
    }
 
    // process the VOR

    ChartElemVor *chart_elem_vor = new ChartElemVor(this, m_chart_model, vor);
    MYASSERT(chart_elem_vor != 0);

    if (!chart_elem_vor->loadFromDomElement(element, dom_doc, err_msg)) 
    {
        delete chart_elem_vor;
        return false;
    }

    addLeaf(leaf_id, chart_elem_vor);
    return true;
}
Example #6
0
void KTREE::insert (TNode* node,int ch)
	{
		TNode* tmp;
														//insert to tree
		point=top;
		if (top==0)
		{ 
			top=new TNode();
			top->setElement(node->getElement());
			top->setParent(0);
			for (int i=0;i<MAX;i++)
				top->setChild(node->getChild(i),i);
			point=top;
		}
		else
		{
			while (point!=0)
			{
			tmp=point;
			point=point->getChild(ch);
			}
			
			point=tmp;
			addLeaf(node,ch);
		
		}
	}
Example #7
0
heap* getData(char *file){
	FILE* input_file = fopen(file,"r");
	if(input_file == NULL){
		printf("Error opening input file %s\n",file);
		exit(1);
	}
	float inputx = 0.0;
	float inputy = 0.0;	
	heap *newheap = createHeap();
	int i = 0;
	while(fscanf(input_file, "%f", &inputx) != EOF){
		fscanf(input_file, "%f", &inputy);
		data *d= createData(inputx,inputy);
		d->distance = calculateDistance(d->valx,d->valy);
		if(i>9){
			if(d->distance < newheap->root->d->distance){
				leaf *removeleaf = removeRoot(newheap);
#if DEBUG
				printf("deleted : %f and inserted : %f -- \n",removeleaf->d->distance,d->distance);
#endif
				popBack(newheap->q->ll);
				free(removeleaf->d);
				free(removeleaf);
				addLeaf(newheap,d);
			} else {
#if DEBUG			
				printf("Skipped : %f => ",d->distance);
				printf("deleting ...... \n");
#endif
				free(d);
			}
		}
		else { 	
#if DEBUG		
			printf("inserted : %f -- \n",d->distance);
#endif
			addLeaf(newheap,d);
		}
		i++;
	}
	
	fclose(input_file);
	return newheap;
}
Example #8
0
void addLeaf(Node &node, Leafs &leafs)
{
    if (node.childs.empty())
    {
        leafs.push_back(&node);
        return;
    }
    for (auto &ch: node.childs)
        addLeaf(*ch, leafs);
}
Example #9
0
File: p6.c Project: itsmarky10/ucd
Tree * mkTree(int depth, pid_t parent)
{
    int i = 2, count = 1 << depth;
    Tree * t = addLeaf(NULL, parent, 1);

    for (; i < count; ++i) {
        if (getpid() == parent) {
            pid_t child = fork();
            if (0 == child) {
                continue;
            } else if (-1 == child) {
                _Exit(printChildError());
            } else {
                t = addLeaf(t, child, i);
            }
        }
    }

    return t;
}
Example #10
0
void addLeaf(Sprig* thisSprig, int key, int caliper){
	Leaf* thisLeaf = thisSprig->firstLeaf;
	
	if (thisLeaf == NULL) {
		thisLeaf = (Leaf*)malloc(sizeof(Leaf));
		createLeaf(thisLeaf, key, NULL, NULL, thisSprig);
		thisSprig->firstLeaf = thisLeaf;
		return;
	}
	
	int count = caliper;
	while(thisLeaf->key < key) {
		if (thisLeaf->nextLeaf != NULL) {
			thisLeaf = thisLeaf->nextLeaf;
		} else if (count == 2) {
			//reached end of sprig, keys still smaller.
			if (thisLeaf->childSprig == NULL) {
				//split and promote, because no far right sprig available
				splitPromote(thisLeaf, thisSprig, key, caliper);
				
			}
			//add this key to far right sprig because it exists
			addLeaf(thisLeaf->childSprig, key, caliper);
		} else {
			//there is room in this sprig for a new leaf
			Leaf* newLeaf = (Leaf*)malloc(sizeof(Leaf));
			createLeaf(newLeaf, key, thisLeaf, NULL, thisSprig);
			thisLeaf->nextLeaf = newLeaf;
			return;
		}
		count--;
	}
	//ran into a key too big
	//try to fit in same sprig
	if (numLeaves(thisSprig) < caliper - 1) {
		int tempKey = thisLeaf->key;
		thisLeaf->key = key;
		Leaf* newLeaf = (Leaf*)malloc(sizeof(Leaf));
		createLeaf(newLeaf, tempKey, thisLeaf, NULL, thisSprig);
		if (thisLeaf->nextLeaf != NULL) {
			thisLeaf->nextLeaf->prevLeaf = newLeaf;
			newLeaf->nextLeaf = thisLeaf->nextLeaf;
		}
		thisLeaf->nextLeaf = newLeaf;
	}
	//sprig is too full,
	else {
		splitPromote(thisLeaf, thisSprig, key, caliper);
	}
	return;
}
Example #11
0
void printHeap(heap *h){
	data **listCor = (data**)malloc(sizeof(data*)*10);
	int i = 0;
	while(h->root){
		if(i>9){
			popBack(h->q->ll);
			break;
		}
		leaf *rootleaf = removeRoot(h);
		
#if DEBUG		
		printf("removing data %f at %d \n",rootleaf->d->distance,i);
#endif
		
		listCor[i] = createData(rootleaf->d->valx,rootleaf->d->valy);
		listCor[i]->distance = calculateDistance(listCor[i]->valx,listCor[i]->valy);
		
		if(h->root == rootleaf){
			free(h->root->d);
			free(h->root);
			h->root = NULL;
		} else {
			free(rootleaf->d);
			free(rootleaf);
		}

		popBack(h->q->ll);
		i++;	
	}
	
	for(i = 9;i>=0;i--){
		printf(" %.2f %.2f %.2f \n",listCor[i]->distance,listCor[i]->valx,listCor[i]->valy);
		data *d = createData(listCor[i]->valx,listCor[i]->valy);
		d->distance = calculateDistance(d->valx,d->valy);
		addLeaf(h,d);
		free(listCor[i]);
	}
	
	free(listCor);
}
Example #12
0
//file reading from zyante 9.5
Sprig* fileRead(char filename[]) {
	FILE* inFile = fopen(filename, "r");
	if( inFile == NULL ) {
		return NULL; //file read error
	}

	int caliper; //the order of the b-tree
	int key;
	fscanf(inFile, "%d", &caliper);
	
	//initialize the topmost Sprig
	Sprig* topSprig = (Sprig*)malloc(sizeof(Sprig));
	createSprig(topSprig, NULL);
	
	fscanf(inFile, "%d", &key);
	while (!feof(inFile)) {
		addLeaf(topSprig, key, caliper);
		fscanf(inFile, "%d", &key);
	}
	
	fclose(inFile);
	return topSprig; //file read worked
}
/**
 * AddSysVar
 *
 * @param           
 * @return          S_OK; 
 * @exception       -
*/
HRESULT
    CSysVarPool::AddSysVar(CSysVar *pVar)
{
    HRESULT hr;
    if (pVar == NULL) {
        return E_POINTER;
    }
    CSysVar *pVarTest = NULL;
    CString strName = pVar->getName();
    strName.MakeLower();
    if (m_sysVarMap.Lookup(strName, pVarTest)) {
        // already in map, refuse!
        return S_FALSE;
    }
    addLeaf(pVar);
    hr = pVar->Reread();
    if (FAILED(hr)) {
        removeLeaf(pVar);
        return hr;
    }
    pVar->addRef();
    m_sysVarMap.SetAt(strName, pVar);
    return S_OK;
}
Example #14
0
void splitPromote(Leaf* thisLeaf, Sprig* thisSprig, int key, int caliper) {
	//new sprig
	Sprig* newRightSprig = (Sprig*)malloc(sizeof(Sprig));
	if (thisSprig->parentSprig == NULL) {
		//need to make new sprig on top
		Sprig* newTopSprig = (Sprig*)malloc(sizeof(Sprig));
		newRightSprig->parentSprig = newTopSprig;
		thisSprig->parentSprig = newTopSprig;
	} else {
		//need to incorporate with existing upper sprig
		newRightSprig->parentSprig = thisSprig->parentSprig;
	}
	Leaf* newLeaf = (Leaf*)malloc(sizeof(Leaf));
	if (thisLeaf->nextLeaf == NULL) {
		//add leaf to end
		createLeaf(newLeaf, key, thisLeaf, NULL, newRightSprig);
		thisLeaf->nextLeaf = newLeaf;
	} else {
		createLeaf(newLeaf, key, thisLeaf->prevLeaf, thisLeaf, newRightSprig);
		thisLeaf->prevLeaf->nextLeaf = newLeaf;
		thisLeaf->prevLeaf = newLeaf;
	}
	//start at the rightmost Leaf
	while (thisLeaf->nextLeaf != NULL) {
		thisLeaf = thisLeaf->nextLeaf;
	}
	
	//then move back to split
	int count = caliper/2;
	while (count > 0) {
		//every leaf on this side of the split needs to reassociate
		thisLeaf->currSprig = newRightSprig;
		//newRightSprig needs to find its first leaf
		newRightSprig->firstLeaf = thisLeaf;
		thisLeaf = thisLeaf->prevLeaf;
		count--;
	}
	//now thisLeaf is the median
	thisLeaf->childSprig = newRightSprig;
	
	//separate from the right leaves
	if (thisLeaf->nextLeaf != NULL) {
		thisLeaf->nextLeaf->prevLeaf = NULL;
		thisLeaf->nextLeaf = NULL;
	}
	
	//bring this leaf up to the parentSprig
	addLeaf(thisSprig->parentSprig, thisLeaf->key, caliper);
	//find the leaf just before the one we just added up there
	Leaf* currLeaf = thisSprig->parentSprig->firstLeaf;
	while (currLeaf->key < thisLeaf->key) {
		currLeaf = currLeaf->nextLeaf;
	}
	//give the promoted leaf the right child sprig
	currLeaf->childSprig = newRightSprig;
	//currLeaf is now one step too far right...
	if (currLeaf->prevLeaf != NULL) {
		currLeaf->prevLeaf->childSprig = thisSprig;
	} else {
		currLeaf->currSprig->leftSprig = thisSprig;
	}
	//separate from the left leaf
	if (thisLeaf->prevLeaf != NULL) {
		thisLeaf->prevLeaf->nextLeaf = NULL;
	}
	//free up the memory of the left behind leaf
	free(thisLeaf);
}