コード例 #1
0
Node *_delRedBlackTree(Node **rootPtr, Node *newNode, int (*compareNode)(void *data, void *object)){

  Node *root = *rootPtr, *node , *successorNode;
  if(root == NULL)
    Throw(ERR_NODE_UNAVAIBLE);

  else if(compareNode(root->data, newNode->data) == 1)
    node = _delRedBlackTree( &root->right, newNode, compareNode);
  else if(compareNode(root->data, newNode->data) == -1)
    node = _delRedBlackTree( &root->left, newNode, compareNode);
  
  else{
    if(root->left || root->right){      //Checking is the removeNode has childNode
      successorNode = removeNextLargerSuccessor(&(*rootPtr)->right);
      successorNode->left  = (*rootPtr)->left;
      successorNode->right = (*rootPtr)->right;
      *rootPtr = successorNode;
    }
    else *rootPtr = NULL;
    return root;
  }
  
  caseSelect(&(*rootPtr));
  return node;
}
コード例 #2
0
ファイル: BSTree.cpp プロジェクト: sam-hoover/css343-bst
// compareNode: equality helper
// Node-by-node comparison of this and tree. Returns true only if the 
// trees have the same data (including m_itemCount) and structure
// preconditions:	this not equal to nullptr
// postconditions:	If self and other have same data and structure then true
//					is returned, else false is returned.
//
bool BSTree::compareNode(Node *self, Node *other) const {
	if(self != nullptr && other != nullptr) {
		if(*self->m_item == *other->m_item && self->m_itemCount == other->m_itemCount) {
			bool l_retVal = compareNode(self->m_left, other->m_left);
			bool r_retVal = compareNode(self->m_right, other->m_right);
			
			// logical iff
			if((l_retVal && r_retVal) || (!l_retVal && !r_retVal)) {
				return(true);
			}
		}
	} else if(self == nullptr && other == nullptr) {
		return(true);
	}
	return(false);
}
コード例 #3
0
bool greedy::_run(Model& m, std::vector<Node*>& solution){    
    std::set<Node*> explored;
    std::priority_queue<Node*, std::vector<Node*>,compareNode> pq(compareNode(*this,m));
    std::map<Node*,Node*> cameFrom;
    Node* currentNode;

    pq.push(m.start_tile);        
    cameFrom[currentNode] = NULL;

    while(pq.empty() == false){
        currentNode = pq.top();
        pq.pop();

        numNodesVisited++;

        // already explored this node. done.
        if( explored.find(currentNode) != explored.end()){
            continue;
        }

        // this is the goal tile, we are done.
        if( currentNode == m.goal_tile){
            // create the solution chain back to the start tile            
            while(currentNode != NULL){
                solution.insert(solution.begin(), currentNode);
                currentNode = cameFrom[currentNode];
            }

            return true;
        }

        // mark as explored.
        explored.insert(currentNode);
    

        // add in all the neighbours into the priority queue
        Node* cand;
        for(int i =0 ;i <6; ++i) {
            cand = (*currentNode)[i];
            if( currentNode->canMove(i) == false){continue;}
            if( explored.find(cand) != explored.end()){continue;}

            numGenNodes++;
            pq.push(cand);

            // record where we came from
            cameFrom[cand] = currentNode;
        }

    }

    // didn't find a solution
    return false;
}
コード例 #4
0
ファイル: main2.cpp プロジェクト: scoiatael/ThingsIdidAtII
 typename Key::Value getValueAt(Key* k)
 {
   //std::cout << "Gettin val for " << *k << " in " << *this << "\n";
   assert(contains(k));
   if(key == k)
     return accum;
   if(compareNode(k))
     return lesser->getValueAt(k);
   else
     return accum + greater->getValueAt(k);
 }
コード例 #5
0
ファイル: main2.cpp プロジェクト: scoiatael/ThingsIdidAtII
 bool contains(Key* k)
 {
   //std::cout << "Lookin for " << k << " in " << *this << "\n";
   if(key == NULL)
     return false;
   if(key == k)
     return true;
   if(compareNode(k))
     return lesser->contains(k);
   return greater->contains(k);
 }
コード例 #6
0
void _addRedBlackTree(Node **rootPtr, Node *newNode, int (*compareNode)(void *data, void *object)){
	Node *root = *rootPtr;
	if(root == NULL){
		*rootPtr = newNode;
		return;
	}
  
  if(compareNode(root->data, newNode->data) == 0)
    Throw(ERR_EQUIVALENT_NODE);
	else if(compareNode(root->data, newNode->data) == 1)
		_addRedBlackTree( &root->right,	newNode, compareNode);
  else if(compareNode(root->data, newNode->data) == -1)
		_addRedBlackTree( &root->left ,	newNode, compareNode);

  if(!( (*rootPtr)->right && (*rootPtr)->left) )  // if root->right && root-> left are null
    return;

  else if( root->left->color == root->right->color && ( root->left->left || root->left->right || root->right->right || root->right->left )){
    root->color = 'r';
  	root->left->color = 'b';
  	root->right->color = 'b';
  }
}
コード例 #7
0
  virtual void visit(const shared_ptr<const Element>& e)
  {
    CHECK_MSG(_ref->containsElement(e->getElementId()), "Did not find element: " <<
              e->getElementId());
    const shared_ptr<const Element>& re = _ref->getElement(e->getElementId());

    Tags in1 = re->getTags();
    Tags in2 = e->getTags();

    if (_ignoreUUID)
    {
      in1.set("uuid","None");  // Wipe out the UUID's
      in2.set("uuid","None");
    }

    if (!_useDateTime)
    {
      in1.set("source:ingest:datetime","None");  // Wipe out the ingest datetime
      in2.set("source:ingest:datetime","None");
    }


    CHECK_MSG(in1 == in2, "Tags do not match: " << in1.toString() << " vs. " << in2.toString());

    CHECK_DOUBLE(re->getCircularError(), e->getCircularError(), _threshold);
    CHECK_MSG(re->getStatus() == e->getStatus(),
          "Status does not match: " << re->getStatusString() << " vs. " << e->getStatusString());
    switch(e->getElementType().getEnum())
    {
    case ElementType::Unknown:
      _matches = false;
      LOG_WARN("Encountered an unexpected element type.");
      break;
    case ElementType::Node:
      compareNode(re, e);
      break;
    case ElementType::Way:
      compareWay(re, e);
      break;
    case ElementType::Relation:
      compareRelation(re, e);
      break;
    }



  }
コード例 #8
0
ファイル: davix_ptree.hpp プロジェクト: ayllon/davix
    bool _findChainRec(typename std::vector<tree_type>::const_iterator begin,
                              typename std::vector<tree_type>::const_iterator end,
                              std::vector<tree_type::ptr_type> & res){
        if(begin == end)
            return true;

        if( compareNode(*begin)){
            res.push_back(this);
            begin++;
            for(iterator it = beginChildren(); it != endChildren(); ++it){
                if( it->_findChainRec(begin, end, res) == true){
                    return true;
                }
            }
        }
        return false;
    }
コード例 #9
0
ファイル: genotype.cpp プロジェクト: Fischx/evomorph
int morf_node::compareTree(morf_node* a, morf_node* b) 
{
  int i;

  if (a==NULL && b == NULL) return 0;
  if (b==NULL && a != NULL) return 1;
  if (a==NULL && b != NULL) return 1;

  compareNode( a, b );

  if( a->subnodes.size() != b->subnodes.size() ) return 1;

  for (i=0;i<a->subnodes.size();i++){
    if( compareTree(a->subnodes[i], b->subnodes[i]) != 0 )
      return 1;
  }
  return 0;
}
コード例 #10
0
ファイル: davix_ptree.hpp プロジェクト: ayllon/davix
    inline bool matchTree(const BasicPtree & rtree) const{
        if(compareNode(rtree) == false){
            return false;
        }

        for(const_iterator it_rtree = rtree.beginChildren(); it_rtree != rtree.endChildren(); ++it_rtree){
            bool found=false;
            for(const_iterator it = beginChildren(); it != endChildren(); ++it){
                if(it->matchTree(*it_rtree) ){
                    found = true;
                    break;
                }
            }
            if(!found){ // failed to find rtree node in main tree
                return false;
            }
        }
        std::cout << " end node " << rtree._data << std::endl;
        return true;
    }
コード例 #11
0
ファイル: BSTree.cpp プロジェクト: sam-hoover/css343-bst
// equality
// Node-by-node comparison of this and tree. Returns true only if the 
// trees have the same data (including m_itemCount) and structure
// preconditions:	tree must be a valid BSTree object (must not reference
//					a dereferenced nullptr); this not equal to nullptr.
// postconditions:	If this and tree have same data and structure then true
//					is returned, else false is returned.
//
bool BSTree::operator==(const BSTree &tree) const {
	if(this == &tree) {
		return(true);
	}
	return(compareNode(m_root, tree.m_root));
}
コード例 #12
0
ファイル: cw.c プロジェクト: tom-wr/FMP
/*
 * inserts an array of input elements into the tree.
 * a node is created if the current node being looked at is null
 * else the function contiues through the tree looking for the next empty spot
 *
 * params:
 * struct node ** tree_node - current node being evaluated
 * char * line[4] - input line to potentially be initialized into a new node
 * returns:
 * 
 */
void insert(struct node ** tree_node, char *line[4])
{
	if(initNode(tree_node, line)) // initializes node if null
		return; // returns if node has just been initialized
	compareNode(tree_node, line); // compares new entry variables to tree nodes and inserts accordingly
}