示例#1
0
 std::list<filepoint> findeq(const KeyType &key){
     Tnode<KeyType> tempnode;
     filepoint temp;
     std::list<filepoint> ans;
     temp = findLeaf (key);
     ans.clear();
     if (temp==0) return ans;
     tempnode = readFromFile (temp);
     if (tempnode.getLeaf ()==0) {
         //std::cout<<"wrong in findless"<<std::endl;
         return ans;
     }
     int kid = tempnode.getKeyIndex (key);
     if (kid>0 && tempnode.getKeyValue (kid-1)==key)
         ans.push_back (tempnode.getChild (kid-1));
     return ans;
 }
示例#2
0
 std::list<filepoint> findbig(const KeyType &key){
     Tnode<KeyType> tempnode;
     filepoint temp;
     temp = findLeaf (key);
     std::list<filepoint> ans;
     while (temp!=0){
         tempnode = readFromFile (temp);
         if (tempnode.getLeaf ()==0) {
             //std::cout<<"wrong in findless"<<std::endl;
             return ans;
         }
         int kid = tempnode.getKeyIndex (key);
         for (int i=kid;i<tempnode.getKeyNum ();++i)
             ans.push_back (tempnode.getChild (i));
         temp = tempnode.getChild (tempnode.getKeyNum ());
     }
     return ans;
 }
示例#3
0
RexxCompoundElement *RexxCompoundTable::next(
    RexxCompoundElement *node)             /* starting point we're drilling from */
{
    /* get the parent node */
    RexxCompoundElement *_parent = node->parent;
    if (_parent != OREF_NULL)
    {
        if (_parent->right == node)
        {      /* if coming back up from the right */
            return _parent;                /* this node's turn has come */
        }
        if (_parent->right != OREF_NULL)
        {  /* if no right child, do this one immediately */
            return findLeaf(_parent->right);/* drill down the other branch */
        }
        return _parent;
    }
    return OREF_NULL;                      /* we've reached the top */
}
示例#4
0
Neighborhood *Neighborhood_new(BPlusTree *tree, Measurement *measurement,int patternLength, int offset){
    
    Node * leafNode;
    
    leafNode = findLeaf(tree, measurement->value);
    int pointerIndex = findLeafKeyIndex(leafNode, measurement->value);
    
    ListValue *listValueOnThatKey = leafNode->pointers[pointerIndex];
    
    //The value will be at most patternLength away in the doubly, linked list
    int maxSteps = patternLength;
    while(listValueOnThatKey->timestamp != measurement->timestamp && maxSteps != 0){
        //go from newest value back towards oldest
        listValueOnThatKey = listValueOnThatKey->prev;
        maxSteps--;
    }
    
    setNeighborhoodPositions(newNeighborhood, leftNeighbourhoodPos, rightNeighbourhoodPos, pointerIndex, leafNode, listValueOnThatKey);
    
    return newNeighborhood;
}
示例#5
0
void KDTree::TraversalRope(KDTreeNode *N, Ray &ray,Point3 ray_Pos)
{
	if(N==NULL)
		return ;
	N = findLeaf(N,ray_Pos);
	Intersect(N->m_List->GetHead(),ray);
	Point3 Pos[8];
	Point3 hitPoint;
	int i;
	GetBoxVertex(N->box,Pos);

	for(i=0;i<6;i++)
		if(IntersectPlane(ray,ray_Pos,Pos[index[i][0]],Pos[index[i][1]],Pos[index[i][2]],Pos[index[i][3]],hitPoint))
			break;
	
	if(i>5)
		i++;
	ray_Pos = hitPoint;
	N = N->ropes[i];
	TraversalRope(N,ray,ray_Pos);
}
		QModelIndex findLeaf(const QModelIndex& curentIndex, int sectionIndex, int& curentLeafIndex)
		{
			if(curentIndex.isValid())
			{
				int childCount=curentIndex.model()->columnCount(curentIndex);
				if(childCount)
				{
					for(int i=0; i<childCount; ++i)
					{
						QModelIndex res(findLeaf(curentIndex.child(0, i), sectionIndex, curentLeafIndex));
						if(res.isValid())
							return res;
					}
				}
				else
				{
					++curentLeafIndex;
					if(curentLeafIndex==sectionIndex)
						return curentIndex;
				}
			}
			return QModelIndex();
		}
示例#7
0
    Node *findLeaf(Node *node, Cell const &at, bool canSubdivide)
    {
        if(node->isLeaf()) return node;

        // Into which quadrant do we need to descend?
        Node::Quadrant q = node->quadrant(at);

        // Has this quadrant been initialized yet?
        Node **childAdr = &node->children[q];
        if(!*childAdr)
        {
            if(!canSubdivide) return 0;

            // Subdivide the space.
            uint const subSize = node->size >> 1;
            switch(q)
            {
            case Node::TopLeft:
                *childAdr = newNode(node->cell, subSize);
                break;

            case Node::TopRight:
                *childAdr = newNode(Cell(node->cell.x + subSize, node->cell.y), subSize);
                break;

            case Node::BottomLeft:
                *childAdr = newNode(Cell(node->cell.x, node->cell.y + subSize), subSize);
                break;
            case Node::BottomRight:
                *childAdr = newNode(Cell(node->cell.x + subSize, node->cell.y + subSize), subSize);
                break;
            }
        }

        return findLeaf(*childAdr, at, canSubdivide);
    }
bool startsWith(struct TrieNode *root, char *prefix)
{
    root = findLeaf(root, prefix);
    return root; //check whether the node is valid;
}
//AC - 36ms;
bool search(struct TrieNode *root, char *word)
{
    root = findLeaf(root, word);
    return root&&root->isWord; //check whether the node exists and it's the leaf of a word;
}
示例#10
0
 inline Node *findLeaf(Cell const &at, bool canCreate = false)
 {
     return findLeaf(&nodes.first(), at, canCreate);
 }
int main(int argc, char** argv) {

    // comprimento da aresta do cubo do ligante
    double cubeLig_edge;
    char str[MAX], lig_name[MAX], aux[11];
    Leaf *root, *leaf;
    int sum, *p_sum, a;
    Protein new_protein;
    Ligante new_ligante;
    LiganteList *ligant_list;

    // armazena o valor da aresta do cubo em volta de cada ligante
    fgets(str, sizeof (str), stdin);
    sscanf(str, " %lf", &cubeLig_edge);

    fgets(str, sizeof (str), stdin);
    sscanf(str, " %s %s", aux, lig_name);
    
    // declara a lista de Ligantes que será utilizada no final
    // para exibir na tela de forma ordenada.
    ligant_list = NULL;
    ligant_list = (LiganteList *) malloc( sizeof(LiganteList) );
    ligant_list->header = NULL;
    ligant_list->header = (Ligante *) malloc( sizeof(Ligante) );
    ligant_list->header->prox = NULL;

    
    // Enquanto não for inserido '-1'
    while (aux[0] != '-' && aux[1] != '1') {

	// declara uma nova raiz para a árvore
	root = NULL;
	root = (Leaf *) malloc(sizeof (Leaf)*2);
	root->is_leaf = 1;
	root->protein.isSet = 0;
        for(a = 0; a< 8; a++){
            root->sons[a] = NULL;
        }

	//seta a soma das interações do ligante em 0
	sum = 0;
	p_sum = &sum;
	// lê e insere no cubo alocado as coordenadas
	// de seus pontos extremos na raiz.
	setCubeCoords(root);

	fgets(str, sizeof (str), stdin);
	
	
	// ---- Leitura das Proteínas
	
	while (str[0] == 'P') {
	    // cria uma nova proteína:
	    //  - aloca espaço para ela
	    //  - recebe as coordenadas do stdin
	    new_protein = getNewProtein(str);
	    // percorre a raiz e encontra a folha
	    // referente às coordenadas da nova proteína.
	    leaf = findLeaf(root, new_protein.point);

	    // função recursiva que insere a proteína
	    // na folha escolhida.
	    setProtein(leaf, new_protein);
	    fgets(str, sizeof (str), stdin);
	}
	
	// ---- Leitura dos Ligantes

	while (str[0] == 'L') {

	    // agora recebemos os ligantes:
	    new_ligante = getNewLigante(str);
	    // copia o nome do ligante para ele.
	    strcpy(new_ligante.name, lig_name);
	    // função recursiva para somar as iterações.
	    getPointsInsideBox(root, new_ligante, cubeLig_edge, p_sum);
	    // recebe a soma final
	    new_ligante.sum = sum;
	    
	    fgets(str, sizeof (str), stdin);
	}
	
	// Insere de forma ordenada o ligante na lista.
	putLiganteOnLiganteList(new_ligante, ligant_list);
	
	// Limpa a árvore e todos seus filhos
	freeLeafs(root);
	sscanf(str, " %s %s", aux, lig_name);
    }
    
    //  ---- Resultado no STDOUT
    
    printResult(ligant_list);
    
    return (EXIT_SUCCESS);
}