Exemplo n.º 1
0
void delAt(List &L, address Data){
	address P,prev,last;
	if(!isEmpty(L) && Data!=NULL)
	{
		prev=P=L.First;
		last=findLast(L);
		
		do
		{
			if(P==Data)
			{
				if(P==L.First) 
				{
					L.First=L.First->Next;
					last=L.First;
				}
				else 
				{
					prev=prevNode(L,Data);
					prev->Next=Data->Next;
				
				}
				delete(Data);
				return;
			}
			P=P->Next;
		}while(P->Next!=L.First);
	}
}
Exemplo n.º 2
0
void RecursiveCFGBuilder::visitStmt(ShPtr<Statement> stmt, bool visitSuccessors,
		bool visitNestedStmts) {
	if (!stmt) {
		return;
	}

	if (hasItem(accessedStmts, stmt)) {
		// The statement has been accessed.
		ShPtr<CFG::Node> stmtNode(firstStmtNodeMapping[stmt]);
		cfg->addEdge(currNode, stmtNode);
		return;
	}

	// When the statement is a goto target and there are some statements in the
	// current node, we have to emit the statement into a new node.
	if (stmt->isGotoTarget() && !currNode->stmts.empty()) {
		ShPtr<CFG::Node> prevNode(currNode);
		ShPtr<CFG::Node> stmtNode(addNode(stmt));
		cfg->addEdge(prevNode, stmtNode);
		return;
	}

	accessedStmts.insert(stmt);

	// The statement is not a goto target, so process it normally.
	stmt->accept(this);
}
Exemplo n.º 3
0
// Retrieve the index of the midnode of an edge, if it exists
int OctreeGrid::getMidEdgeNode(int node1, int node2, int axis) const {
	const Node &n1 = m_Nodes[node1];
	const Node &n2 = m_Nodes[node2];
	oct_debug(n1.position[axis] < n2.position[axis]);
	if (n1.next(axis) == node2) {
		oct_debug(n2.prev(axis) == node1);
		return -1;
	} else {
		const int c1 = n1.position[axis];
		const int c2 = n2.position[axis];
		const int c3 = (c1 + c2) / 2;
		oct_debug((c1 + c2) % 2 == 0);
		int m1 = n1.next(axis);
		int m2 = n2.prev(axis);
		while (m_Nodes[m1].position[axis] != c3 && m_Nodes[m2].position[axis] != c3) {
			m1 = nextNode(m1, axis);
			m2 = prevNode(m2, axis);
			oct_debug(m1 != -1 && m2 != -1);
			oct_debug(m1 != node2 && m2 != node1);
		}
		if (m_Nodes[m1].position[axis] == c3) {
			return m1;
		} else {
			return m2;
		}
	}
}
Exemplo n.º 4
0
void OctreeGrid::assertIsValid() {
	// Check node adjacency relations
	for (int node1 = 0; node1 < (int) m_Nodes.size(); ++node1) {
		for (int axis = 0; axis < 3; ++axis) {
			int node0 = prevNode(node1, axis);
			int node2 = nextNode(node1, axis);
			if (m_Nodes[node1].position[axis] == 0) {
				oct_debug(node0 == -1);
			} else if (node0 != -1) {
				oct_debug(nextNode(node0, axis) == node1);
			}
			if (m_Nodes[node1].position[axis] == m_CellGridSize[axis]) {
				oct_debug(node2 == -1);
			} else if (node2 != -1) {
				oct_debug(prevNode(node2, axis) == node1);
			}
		}
	}
	// Check cell adjacency relations
	for (int cell1 = 0; cell1 < (int) m_Cells.size(); ++cell1) {
		for (int axis = 0; axis < 3; ++axis) {
			int cell0 = prevCell(cell1, axis);
			int cell2 = nextCell(cell1, axis);
			if (cellCornerPos(cell1, CORNER_X0_Y0_Z0)[axis] == 0) {
				oct_debug(cell0 == -1);
			} else {
				oct_debug(cell0 != -1);
				if (cellExtent(cell1) == cellExtent(cell0)) {
					oct_debug(nextCell(cell0, axis) == cell1);
				}
			}
			if (cellCornerPos(cell1, CORNER_X1_Y1_Z1)[axis] == m_CellGridSize[axis]) {
				oct_debug(cell2 == -1);
			} else {
				oct_debug(cell2 != -1);
				if (cellExtent(cell1) == cellExtent(cell2)) {
					oct_debug(prevCell(cell2, axis) == cell1);
				}
			}
		}
	}
}
Exemplo n.º 5
0
// Create a new double-link adjacency relation along axis
void OctreeGrid::createNodeLinks(int node1, int node2, int axis) {
	oct_debug(node1 != -1 && node2 != -1);
	if (nextNode(node1, axis) == -1) {
		oct_debug(prevNode(node2, axis) == -1);
		m_Nodes[node1].setNext(axis, node2);
		m_Nodes[node2].setPrev(axis, node1);
		for (int c = 0; c < 3; ++c) {
			if (c == axis) { continue; }
			oct_debug(m_Nodes[node1].position[c] == m_Nodes[node2].position[c]);
		}
	}
}
Exemplo n.º 6
0
// Add a node at the middle of an edge
int OctreeGrid::addMidEdgeNode(int node1, int node2, int axis) {
	oct_debug(node1 != -1 && node2 != -1);
	oct_debug(nextNode(node1, axis) == node2);
	oct_debug(prevNode(node2, axis) == node1);

	// Setup node position
	Node newNode;
	newNode.position = m_Nodes[node1].position;
	newNode.position[axis] = (m_Nodes[node1].position[axis] + m_Nodes[node2].position[axis]) / 2;
	oct_debug((m_Nodes[node1].position[axis] + m_Nodes[node2].position[axis]) % 2 == 0);

	// Setup node adjacency
	int newId = (int) m_Nodes.size();
	m_Nodes.emplace_back(newNode);
	updateNodeLinks(node1, node2, newId, axis);
	return newId;
}
Exemplo n.º 7
0
// Return true iff the cell cellId is 2:1 graded
bool OctreeGrid::cellIs2to1Graded(int cellId) const {
	const Cell &cell = m_Cells[cellId];
	const int v0 = cell.corner(CORNER_X0_Y0_Z0);
	const int v1 = cell.corner(CORNER_X1_Y0_Z0);
	const int v2 = cell.corner(CORNER_X1_Y1_Z0);
	const int v3 = cell.corner(CORNER_X0_Y1_Z0);
	const int v4 = cell.corner(CORNER_X0_Y0_Z1);
	const int v5 = cell.corner(CORNER_X1_Y0_Z1);
	const int v6 = cell.corner(CORNER_X1_Y1_Z1);
	const int v7 = cell.corner(CORNER_X0_Y1_Z1);
	auto testEdge = [this] (int a, int b, int axis) {
		return (nextNode(a, axis) == b || nextNode(a, axis) == prevNode(b, axis));
	};
	return testEdge(v0, v1, X) && testEdge(v3, v2, X) && testEdge(v4, v5, X) && testEdge(v7, v6, X)
		&& testEdge(v0, v3, Y) && testEdge(v1, v2, Y) && testEdge(v4, v7, Y) && testEdge(v5, v6, Y)
		&& testEdge(v0, v4, Z) && testEdge(v1, v5, Z) && testEdge(v3, v7, Z) && testEdge(v2, v6, Z);
}
Node* Add(Node *H1, Node *H2, int diff)
{

	Node *prevNode(NULL);
	int temp_val=0;
	if(H1->next != NULL && H2->next != NULL){
		if(diff <= 0){
			prevNode = Add(H1->next, H2->next, --diff);
			temp_val = H1->Val + H2->Val + carry;}
		else{
			prevNode = Add(H1->next, H2, --diff);
			temp_val =  H1->Val + carry;}}

	if(diff < 0){
		temp_val = H1->Val + H2->Val + carry;}
	else{
		temp_val =  H1->Val + carry;}
	carry = 0;
	if(temp_val >=10) {carry = temp_val /10; temp_val =temp_val %10;}
	Node *newNode = new Node; newNode->Val=temp_val; newNode->next=prevNode;
	return newNode;
}