Ejemplo n.º 1
0
CDGNode *getTopPath(CDGNode * node, Stack * changedNodes, Stack * changedBranches) {
  CDGNode *pathNode = newBlankNode();
  CDGNode *temp = pathNode;
  int branch;
  while (node) {
    if (0 != getScore(node)) {
      stackPush(changedNodes, &node);
      branch = getOutcome(node);
      stackPush(changedBranches, &branch);
      if (isLeaf(node)) {
	setScore(node, 0);
      } else {
	setNextNode(temp, copyToPathNode(newBlankNode(), node));
	temp = getNextNode(temp);
	if (getOutcome(node)) {
	  setBranchInfo(getID(node), 1, getBranchInfo(getID(node), 0));
	  setTrueNodeSet(temp, getTopPath(getTrueNodeSet(node), changedNodes, changedBranches));
	} else {
	  setBranchInfo(getID(node), getBranchInfo(getID(node), 1), 1);
	  setFalseNodeSet(temp, getTopPath(getFalseNodeSet(node), changedNodes, changedBranches));
	}
      }
    }
    node = getNextNode(node);
  }
  if (temp == pathNode) {
    deleteNode(pathNode);
    pathNode = NULL;
  } else {
    temp = pathNode;
    pathNode = getNextNode(pathNode);
    deleteNode(temp);
  }
  return pathNode;
}
Ejemplo n.º 2
0
//Adiciona na arvore
Arvore* adicionaInternal(Arvore* raiz,Arvore* pai, Arvore* filho){
	if(raiz){
		if(filho->hash > pai->hash){
			if(pai->direita == VAZIO){
				filho->pai = pai->pos;
				pai->direita = salvaFilho(filho);
				atualizaNo(pai);
				raiz = balanceia(raiz,filho);
			}
			else
				raiz = adicionaInternal(raiz,getNextNode(pai->direita),filho);
		}
		else{
			if(pai->esquerda ==VAZIO){
				filho->pai = pai->pos;
				pai->esquerda = salvaFilho(filho);
				atualizaNo(pai);
			 	raiz =	balanceia(raiz,filho);
			}			
			else
				raiz = adicionaInternal(raiz,getNextNode(pai->esquerda),filho);
		}
	}
	else{
		salvaRaiz(filho);
		raiz = filho;
	}
	return raiz;
}
Ejemplo n.º 3
0
 //Faz rotacao a direita na arvore
Arvore * rotacaoDireita(Arvore * raiz, Arvore * atual) {
	Arvore * esquerda = atual->esquerda;
    Arvore* aux;
    atual->esquerda = esquerda->direita;
    if (esquerda->direita != VAZIO) {
        aux = getNextNode(esquerda->direita);
        aux->pai = atual->pos;
        atualizaNo(aux);
    }
    esquerda->pai = atual->pai;
    if (atual->pai == RAIZ) {
        raiz = esquerda; //raiz
    } else {
        aux = getNextNode(atual->pai);
        if (atual->pos == aux->direita) {
            aux->direita = esquerda->pos;
        } else {
            aux->esquerda = esquerda->pos;
            atualizaNo(aux);
        }
    }
    esquerda->direita = atual->pos;
    atual->pai = esquerda->pos;
    atualizaNo(esquerda);
    atualizaNo(atual);
    return raiz;
}
Ejemplo n.º 4
0
//Busca -- MELHORAR
char* buscaInternal(Arvore* raiz, Arvore* corrente, char data[], long int hash,int count){
	count++;
	if(raiz){
		if(hash == corrente->hash){
			if(strcmp(corrente->data, data) == 0){
				//printf("COR: %c POSICAO %d PAI: %d\n",corrente->cor,corrente->pos,corrente->pai);
				return novoRetorno(TRUE,count,corrente->data);
			}else if(corrente->esquerda != VAZIO)
					return buscaInternal(raiz,getNextNode(corrente->esquerda),data,hash,count);
				else 
				return novoRetorno(FALSE,count,data);
		}else if(hash < corrente->hash)
			if(corrente->esquerda != VAZIO)
				return buscaInternal(raiz,getNextNode(corrente->esquerda),data,hash,count);
			else
				return novoRetorno(FALSE,count,data);
		else 
			if(corrente->direita != VAZIO)
				return buscaInternal(raiz,getNextNode(corrente->direita),data,hash,count);
			else
				return novoRetorno(FALSE,count,data);
	}
	else
		return novoRetorno(FALSE,count,data);
}
Ejemplo n.º 5
0
GasMeter::GasMeter(llvm::IRBuilder<>& _builder, RuntimeManager& _runtimeManager) :
	CompilerHelper(_builder),
	m_runtimeManager(_runtimeManager)
{
	llvm::Type* gasCheckArgs[] = {Type::Gas->getPointerTo(), Type::Gas, Type::BytePtr};
	m_gasCheckFunc = llvm::Function::Create(llvm::FunctionType::get(Type::Void, gasCheckArgs, false), llvm::Function::PrivateLinkage, "gas.check", getModule());
	m_gasCheckFunc->setDoesNotThrow();
	m_gasCheckFunc->setDoesNotCapture(1);

	auto checkBB = llvm::BasicBlock::Create(_builder.getContext(), "Check", m_gasCheckFunc);
	auto updateBB = llvm::BasicBlock::Create(_builder.getContext(), "Update", m_gasCheckFunc);
	auto outOfGasBB = llvm::BasicBlock::Create(_builder.getContext(), "OutOfGas", m_gasCheckFunc);

	auto gasPtr = &m_gasCheckFunc->getArgumentList().front();
	gasPtr->setName("gasPtr");
	auto cost = gasPtr->getNextNode();
	cost->setName("cost");
	auto jmpBuf = cost->getNextNode();
	jmpBuf->setName("jmpBuf");

	InsertPointGuard guard(m_builder);
	m_builder.SetInsertPoint(checkBB);
	auto gas = m_builder.CreateLoad(gasPtr, "gas");
	auto gasUpdated = m_builder.CreateNSWSub(gas, cost, "gasUpdated");
	auto gasOk = m_builder.CreateICmpSGE(gasUpdated, m_builder.getInt64(0), "gasOk"); // gas >= 0, with gas == 0 we can still do 0 cost instructions
	m_builder.CreateCondBr(gasOk, updateBB, outOfGasBB, Type::expectTrue);

	m_builder.SetInsertPoint(updateBB);
	m_builder.CreateStore(gasUpdated, gasPtr);
	m_builder.CreateRetVoid();

	m_builder.SetInsertPoint(outOfGasBB);
	m_runtimeManager.abort(jmpBuf);
	m_builder.CreateUnreachable();
}
Ejemplo n.º 6
0
void ex4_6() {
    std::cout << "ex4.6 \n";
    std::vector<int> in;
    for (int sample = 0; sample <  10; ++sample)
        in.push_back(std::rand() % 2000);
    std::sort(in.begin(), in.end());
    TreeNode<int>* node = createBST(in, 0, (int) in.size()) ;
    auto root = node;
    TreeNode<int>* rightmost = root;
    std::cout << "root.value=" << root->value << ", node.value=" << node->value << ", rightmost.value=" << rightmost->value << std::endl;
    rightmost = rightmost->right;
    rightmost = rightmost->right;
    auto next = getNextNode(rightmost);
    std::cout << "next node of node "  << rightmost->value << " is " << (next ? next->value : -1 ) << std::endl;   //    std::cout << " sample size=" << in.size() << ", max height = " << height << ", log(size)=" << log2(in.size()) << std::endl;
    //std::cout << "is it a BST? " << checkBST(node);
    auto lists = createLists(node);
    for (int depth = 0; depth < lists.size(); ++depth) {
        std::cout << " level " << depth << ": ";
        for (auto elem : lists[depth]) {
            std::cout << elem->value << ", ";
        }
        std::cout << std::endl;
    }
   
    std::cout << "next node of node "  << node->value << " is " << getNextNode(node)->value << std::endl;
    node = node->right;
    std::cout << "next node of node "  << node->value << " is " << getNextNode(node)->value << std::endl;
    node = node->left;
    std::cout << "next node of node "  << node->value << " is " << getNextNode(node)->value << std::endl;
    node = node->left;
    std::cout << "next node of node "  << node->value << " is " << getNextNode(node)->value << std::endl;
}
Ejemplo n.º 7
0
inline void delete_node(void** seg, void** tail, void *bp)
{
#ifdef __DEBUG__
	printf("Delete node / *seg : %u, tail : %u, bp : %u\n", *seg, *tail, bp);
#endif
	if(isHead(bp) && isTail(bp)) //make list empty
	{
		*seg = NULL;
		*tail = NULL;
		return;
	}
	else if(isHead(bp)) //move head
	{
		*seg = getNextNode(*seg);
		setPrevNode(*seg, *seg);
		return;
	}
	else if(isTail(bp)) //move tail
	{
		*tail = getPrevNode(bp);
		setNextNode(*tail, *tail);
		return;
	}

	void *prev_bp, *next_bp; //link change
	prev_bp = getPrevNode(bp);
	next_bp = getNextNode(bp);
	setNextNode(prev_bp, next_bp);
	setPrevNode(next_bp, prev_bp);
}
Ejemplo n.º 8
0
//faz rotacao a esquerda na arvore
Arvore * rotacaoEsquerda(Arvore * raiz, Arvore * avo) {
    Arvore * pai = getNextNode(avo->direita);
    Arvore* aux;
    avo->direita = pai->esquerda;

    if (pai->esquerda != VAZIO) {
        aux = getNextNode(pai->esquerda);
        aux->pai = avo->pos;
        atualizaNo(aux);
    }

    pai->pai = avo->pai;
    if (avo->pai == RAIZ) {
        raiz = pai;
    } else {
        aux = getNextNode(avo->pai);
        if (avo->pos == aux->esquerda) {
            aux->esquerda = pai->pos;
        } else {
            aux->direita = pai->pos;
        }
        atualizaNo(aux);
    }
    pai->esquerda = avo->pos;
    avo->pai = pai->pos;
    atualizaNo(pai);
    atualizaNo(avo);
    return raiz;
}
Ejemplo n.º 9
0
CDGNode *getLastNode(CDGNode * node) {
  assert(NULL != node);
  CDGNode *curr = node;
  while (getNextNode(curr)) {
    curr = getNextNode(curr);
  }
  return curr;
}
Ejemplo n.º 10
0
CDGNode *buildFeasiblePath(CDGNode * node, CDGNode * list) {
  while (node && 0 == nodeExists(list, getID(node))) {
    node = getNextNode(node);
  }

  if (NULL == node)
    return NULL;

  CDGNode *out = NULL;
  out = copyToPathNode(newBlankNode(), node);
  setTrueNodeSet(out, buildFeasiblePath(getTrueNodeSet(node), list));
  setFalseNodeSet(out, buildFeasiblePath(getFalseNodeSet(node), list));
  setNextNode(out, buildFeasiblePath(getNextNode(node), list));

  return out;
}
Ejemplo n.º 11
0
int hasConditionalChild(CDGNode * node) {
  CDGNode *temp;
  temp = getTrueNodeSet(node);
  while (temp) {
    if (!isLeaf(temp))
      return 1;
    temp = getNextNode(temp);
  }
  temp = getFalseNodeSet(node);
  while (temp) {
    if (!isLeaf(temp))
      return 1;
    temp = getNextNode(temp);
  }
  return 0;
}
Ejemplo n.º 12
0
node *getTail(node* headNode)
{
	node *currentNode = headNode;
	if(currentNode == NULL)
	{
		printf("error: invalid head node given to getTail\n");
		return NULL;
	}
	node *nextNode;
	while(getNextNode(currentNode) != NULL)
	{
		nextNode = getNextNode(currentNode);
		currentNode = nextNode;
	}
	return currentNode;
}
Ejemplo n.º 13
0
// Ben's implementation that inserts in blockbased order
int insertNode(int *array, int node, int size) {
    /**
     * 1. Find the node to insert after
     * 2. Set our size up
     * 3. Set our next using preceding's next.
     * 4. Set the preceding node's next to point to new
     * 5. Set following node's prev to us.
     */
    int firstNode = array[0];
    int currentNodeIndex = array[0];
    array[node] = size;
    array[node+size -1] = size;

    while(array[currentNodeIndex + NEXT] < node) {
        if(array[currentNodeIndex + NEXT]  == firstNode) {
            //Been around linked list, we must be the last block.
            break; //Current node will be the last in the list

        }

        currentNodeIndex = getNextNode(array, currentNodeIndex);
    }
    //Should have our node...
    array[node + NEXT] = array[currentNodeIndex + NEXT];
    array[node + PREV] = currentNodeIndex;
    array[currentNodeIndex + NEXT] = node;
    array[ array[node + NEXT] + PREV ] = node;
    return 1;
}
Ejemplo n.º 14
0
llvm::Function* Array::createExtendFunc()
{
	llvm::Type* argTypes[] = {m_array->getType(), Type::Size};
	auto func = llvm::Function::Create(llvm::FunctionType::get(Type::Void, argTypes, false), llvm::Function::PrivateLinkage, "array.extend", getModule());
	func->setDoesNotThrow();
	func->setDoesNotCapture(1);

	auto arrayPtr = &func->getArgumentList().front();
	arrayPtr->setName("arrayPtr");
	auto newSize = arrayPtr->getNextNode();
	newSize->setName("newSize");

	InsertPointGuard guard{m_builder};
	m_builder.SetInsertPoint(llvm::BasicBlock::Create(m_builder.getContext(), {}, func));
	auto dataPtr = m_builder.CreateBitCast(arrayPtr, Type::BytePtr->getPointerTo(), "dataPtr");// TODO: Use byte* in Array
	auto sizePtr = m_builder.CreateStructGEP(getType(), arrayPtr, 1, "sizePtr");
	auto capPtr = m_builder.CreateStructGEP(getType(), arrayPtr, 2, "capPtr");
	auto data = m_builder.CreateLoad(dataPtr, "data");
	auto size = m_builder.CreateLoad(sizePtr, "size");
	auto extSize = m_builder.CreateNUWSub(newSize, size, "extSize");
	auto newData = m_reallocFunc.call(m_builder, {data, newSize}, "newData"); // TODO: Check realloc result for null
	auto extPtr = m_builder.CreateGEP(newData, size, "extPtr");
	m_builder.CreateMemSet(extPtr, m_builder.getInt8(0), extSize, 16);
	m_builder.CreateStore(newData, dataPtr);
	m_builder.CreateStore(newSize, sizePtr);
	m_builder.CreateStore(newSize, capPtr);
	m_builder.CreateRetVoid();
	return func;
}
Ejemplo n.º 15
0
// -----------------------------------------------------------------------------
void ArenaGraph::loadGoalNodes(const XMLNode *node)
{
    const XMLNode *check_node = node->getNode("checks");
    for (unsigned int i = 0; i < check_node->getNumNodes(); i++)
    {
        const XMLNode *goal = check_node->getNode(i);
        if (goal->getName() =="goal")
        {
            Vec3 p1, p2;
            bool first_goal = false;
            goal->get("first_goal", &first_goal);
            goal->get("p1", &p1);
            goal->get("p2", &p2);

            int first = Graph::UNKNOWN_SECTOR;
            findRoadSector(p1, &first, NULL, true);
            int last = Graph::UNKNOWN_SECTOR;
            findRoadSector(p2, &last, NULL, true);

            first_goal ? m_blue_node.insert(first) : m_red_node.insert(first);
            first_goal ? m_blue_node.insert(last) : m_red_node.insert(last);
            while (first != last)
            {
                // Find all the nodes which connect the two points of
                // goal, notice: only work if it's a straight line
                first = getNextNode(first, last);
                first_goal ? m_blue_node.insert(first) :
                    m_red_node.insert(first);
            }
        }
    }
}   // loadGoalNodes
Ejemplo n.º 16
0
/*Release dynamic memory allocated to the list, including all its nodes*/
void deleteLst(sequenceLst *seqLst,int counter)
{
    node * Node = seqLst->head, *toDelete;
    if (seqLst != NULL)
    {
        /* First release memory of all existing nodes */

        if(counter>0)
        {


            while (Node != NULL)
            {

                toDelete = Node;
                Node = getNextNode(Node);
                deleteNode(toDelete);

            }


        }



        free(seqLst);


    }
}
Ejemplo n.º 17
0
static void* find_fit(size_t size) //find best place
{
#ifdef __DEBUG__
	fprintf(stderr, "find fitting place - size : %d\n", size);
#endif
	void* bp;
	void* s;
	size_t sizeIndex = size;
	for(s = getSegBySize(size); ; s = getSegBySize(sizeIndex))  //increase seg size
	{
		sizeIndex = getNextSize(sizeIndex);
		for(bp = s; ; bp = getNextNode(bp)) //iterate list
		{
			if(bp==NULL) break;
#ifdef __DEBUG__
			fprintf(stderr, "searching : %u / allocated? : %u / size? : %u\n", getBlockHeader(bp), isAllocated(getBlockHeader(bp)), getSize(getBlockHeader(bp)));
#endif
			if(!isAllocated(getBlockHeader(bp)) && size <= getSize(getBlockHeader(bp)))
			{
				return bp;
			}
			if(isTail(bp)) break;
		}
		if(s==seg_inf) break;
	}
	return NULL;
}
Ejemplo n.º 18
0
void dijkstra(graph* G, long initial_node, char debug)
{
	long i,j,k;
	long aN; //actualNode
	G->D[initial_node] = 0;
	aN = initial_node;

	printf("Running dijkstra on graph\n");

	if(debug)
		printGraph(G);

	for(i = 0; i < G->N; i++)
	{
		G->visited[aN] = VISITED;

		if(debug){
			printf("It[%d] aN [%d]",i, aN); printStatus(G); printf("\n");
		}

		//Find all nodes connected to aN
		for(j=0;j<G->N;j++){
			if( (G->node[aN][j] != NO_CONN) ){
				if( (G->D[aN] + G->node[aN][j]) < G->D[j] ){
					G->D[j] = (G->D[aN] + G->node[aN][j]);
				}
			}
		}

		aN = getNextNode(G);
	}
	printf("Finished Dijkstra\n");
}
Ejemplo n.º 19
0
void pushNodeListToStack(Stack * s, CDGNode * node) {
  assert(NULL != node);

  do {
    stackPush(s, &node);
    node = getNextNode(node);
  } while (node);
}
Ejemplo n.º 20
0
void deleteNodeList(CDGNode * node) {
  assert(NULL != node);
  CDGNode *next;
  do {
    next = getNextNode(node);
    deleteNode(node);
    node = next;
  } while (node);
}
Ejemplo n.º 21
0
int getConditionalNodeSum(CDGNode * node) {
  int sum = 0;
  while (node != NULL) {
    if (!isLeaf(node)) {
      sum += getScore(node);
    }
    node = getNextNode(node);
  }
  return sum;
}
Ejemplo n.º 22
0
void traverseAndPrint(node *headNode)
{
	node *currentNode = headNode;
	while(currentNode != NULL)
	{
		printNode(currentNode);
		currentNode = getNextNode(currentNode);
	}
	return;
}
Ejemplo n.º 23
0
CDGNode *visitAnyOneNode(CDGNode * node) {
  assert(NULL != node);
  do {
    if (isLeaf(node) && 1 == getScore(node)) {
      setScore(node, 0);
      return node;
    }
    node = getNextNode(node);
  } while (node);
  return NULL;
}
Ejemplo n.º 24
0
void preOrderCDG(CDGNode* node) {
    while (node) {
        if ( 0 == getID(node) )
            printf("ID: %d, PID: 0", getID(node));
        else
            printf("ID: %d, PID: %d", getID(node), getID(getParent(node)));
        preOrderCDG(getTrueNodeSet(node));
        preOrderCDG(getFalseNodeSet(node));
        node = getNextNode(node);
    }
}
Ejemplo n.º 25
0
bool XmlTestParser::LoadTest(lc3_test_suite& suite, wxXmlNode* root)
{
    wxXmlNode* child = root->GetChildren();

    lc3_test test;

    test.has_halted = false;
    test.executions = 0;
    test.has_max_executions = false;
    test.has_disable_plugins = false;
    test.disable_plugins = false;
    test.max_executions = 0;
    test.passed = false;
    test.randomize = false;
    test.true_traps = false;
    test.interrupt_enabled = false;
    test.warnings = false;
    test.points = 0;
    test.max_points = 0;

    while(child)
    {
        if (child->GetName() == "name")
            test.name = child->GetNodeContent();
        else if (child->GetName() == "true-traps")
            test.true_traps = wxAtoi(child->GetNodeContent()) != 0;
        else if (child->GetName() == "has-max-executions")
            test.has_max_executions = wxAtoi(child->GetNodeContent()) != 0;
        else if (child->GetName() == "has-disable-plugins")
            test.has_disable_plugins = wxAtoi(child->GetNodeContent()) != 0;
        else if (child->GetName() == "disable-plugins")
            test.disable_plugins = wxAtoi(child->GetNodeContent()) != 0;
        else if (child->GetName() == "max-executions")
            test.max_executions = wxAtol(child->GetNodeContent());
        else if (child->GetName() == "randomize")
            test.randomize = wxAtoi(child->GetNodeContent()) != 0;
        else if (child->GetName() == "interrupt-enabled")
            test.interrupt_enabled = wxAtoi(child->GetNodeContent()) != 0;
        else if (child->GetName() == "input")
        {
            if (!LoadTestInput(test, child)) throw "test-input improperly formatted";
        }
        else if (child->GetName() == "output")
        {
            if (!LoadTestOutput(test, child)) throw "test-output improperly formatted";
        }

        child = getNextNode(child);
    }

    suite.tests.push_back(test);
    return true;
}
Ejemplo n.º 26
0
CDGNode *getMaxScoreConditionNode(CDGNode * node) {
  CDGNode *out = NULL;
  do {
    if (!isLeaf(node) && 0 < getScore(node)) {
      if ((NULL == out) || (getScore(out) < getScore(node))) {
	out = node;
      }
    }
    node = getNextNode(node);
  } while (NULL != node);
  return out;
}
Ejemplo n.º 27
0
List *lmap(List *src, void *(*func)(void *)) {
  List *results = NULL;
  if (src != NULL && func != NULL) {
    Node *head = src->head;
    while (head != NULL) {
      results = append(results, func(head->data));
      head = getNextNode(head);
    }
  }

  return results;
}
Ejemplo n.º 28
0
int hasUncoveredChild(CDGNode * node, int branch) {
  CDGNode *temp;
  if (branch)
    temp = getTrueNodeSet(node);
  else
    temp = getFalseNodeSet(node);
  while (temp) {
    if (isLeaf(temp) && 0 < getScore(temp))
      return 1;
    temp = getNextNode(temp);
  }
  return 0;
}
Ejemplo n.º 29
0
//------------------------------------------------------------------------
KdTree::KdTree(const SphereSet& set) :
	m_AxisAlignedBoundingBox(set.getAABB()),
	m_NextNodeIndex(0)
{
	m_Root = getNextNode();

	for (auto it = set.begin(); it != set.end(); it++)
	{
		m_Root->add(&*it);
	}

	m_Root->build(this, m_AxisAlignedBoundingBox, 0);
}
Ejemplo n.º 30
0
void XMLSceneryReader::parse() {

	DOMNode* firstNode = getFirstChild(); // scenery>tracks
	DOMNode* node = getFirstChild(); // tracks>track

//	m_tracks->read(this); // read tracks

	m_node = firstNode; // reset current node to scenery>tracks
	getNextNode(); // scenery>vehicles
	node = getFirstChild(); // vehicles>vehicle

//	m_vehicles->read(this); // read vehicles

}