Example #1
0
 /**
  * Nodes can be ordered by id and version.
  * Note that we use the absolute value of the id for a
  * better ordering of objects with negative id.
  */
 inline bool operator<(const Node& lhs, const Node& rhs) {
     if (lhs.id() == rhs.id()) {
         return lhs.version() < rhs.version();
     } else {
         return std::abs(lhs.id()) < std::abs(rhs.id());
     }
 }
Example #2
0
bool Van::connect(const Node &node) {
  CHECK(node.has_id()) << node.ShortDebugString();
  CHECK(node.has_port()) << node.ShortDebugString();
  CHECK(node.has_hostname()) << node.ShortDebugString();

  NodeID id = node.id();
  // If the node.id is the same as myNode_.id, then we need to update current
  // node information. This new node information generally comes from scheduler.
  if (id == myNode_.id()) {
    myNode_ = node;
  }
  if (senders_.find(id) != senders_.end()) {
    return true;
  }
  void *sender = zmq_socket(context_, ZMQ_DEALER);
  CHECK(sender != nullptr) << zmq_strerror(errno);
  std::string myId = myNode_.id();
  zmq_setsockopt(sender, ZMQ_IDENTITY, myId.data(), myId.size());

  std::string addr =
      "tcp://" + node.hostname() + ":" + std::to_string(node.port());
  if (FLAGS_local) {
    addr = "ipc:///tmp/" + node.id();
  }
  if (zmq_connect(sender, addr.c_str()) != 0) {
    LOG(WARNING) << "connect to " + addr + " failed: " + zmq_strerror(errno);
    return false;
  }

  senders_[id] = sender;
  hostnames_[id] = node.hostname();
  VLOG(1) << "Connect to " << id << " [" << addr << "]";
  return true;
}
Example #3
0
 /**
  * Nodes can be ordered by id and version.
  * Note that we use the absolute value of the id for a
  * better ordering of objects with negative id.
  */
 friend bool operator<(const Node& lhs, const Node& rhs) {
     if (lhs.id() == rhs.id()) {
         return lhs.version() < rhs.version();
     } else {
         return abs(lhs.id()) < abs(rhs.id());
     }
 }
Example #4
0
//Metodo para procesar el algoritmo de fifo
void Queue::fifo()
{
    float suma = 0.0; // Suma del tiempo total
    int s = _s; // TamaƱo de la cola
    Node *control = start; // Asignamos control igual a inicio de la cola
    Queue *respaldo = new Queue(_s);

    printf("\nProcesando el algoritmo\n\n");

    print(); // Imprimimos la cola inicialmente

    // El ciclo correra mientras existan nodos de las colas
    while(control != NULL){
        Node *p = start; // Nodo a recorrer
        Node *aux = NULL;

        // Encontramos resultado
        suma += p->time(); // Aumentamos el tiempo total
        printf("\nTR%c = %.0f\n", p->id(), suma);
        respaldo->orderbyid(p->id(), (int) suma, p->time()); // Respaldamos
        supr(p->id()); // Eliminamos el nodo
        print(); // Imprimimos la cola

        // Reasignamos el valor de control
        control = start;
    }

    printf("\nTiempo total: %i\n", (int) respaldo->suma());
    printf("Tiempo promedio: %.1f\n\n", respaldo->suma() / s);
    printf("*** Tabla de resultados ***\n\n");
    respaldo->result();
}
Example #5
0
File: MLGDao.cpp Project: caomw/mld
HLink MLGDao::mirrorEdge( const HLink& current, Direction dir, const Layer& newLayer, NodeMap& nodeMap )
{
    // Find equivalent in top layer
    Node topSrc;
    auto it = nodeMap.find(current.source());
    if( it != nodeMap.end() ) { // not found
        topSrc = it->second;
    }
    else {
        topSrc = mirrorNode(current.source(), dir, newLayer);
        nodeMap.emplace(current.source(), topSrc);
    }

    Node topTgt;
    it = nodeMap.find(current.target());
    if( it != nodeMap.end() ) { // not found
        topTgt = it->second;
    }
    else {
        topTgt = mirrorNode(current.target(), dir, newLayer);
        // Add to map to retrieve edges
        nodeMap.emplace(current.target(), topTgt);
    }
    // Add new HLink
    return m_link->addHLink(topSrc.id(), topTgt.id(), current.weight());
}
Example #6
0
void Van::disconnect(const Node &node) {
  CHECK(node.has_id()) << node.ShortDebugString();
  NodeID id = node.id();
  if (senders_.find(id) != senders_.end()) {
    zmq_close(senders_[id]);
  }
  senders_.erase(id);
  VLOG(1) << "Disconnect from " << node.id();
}
Example #7
0
gssw_graph* Aligner::create_gssw_graph(Graph& g, int64_t pinned_node_id, gssw_node** gssw_pinned_node_out) {

    gssw_graph* graph = gssw_graph_create(g.node_size());
    unordered_map<int64_t, gssw_node*> nodes;

    for (int i = 0; i < g.node_size(); ++i) {
        Node* n = g.mutable_node(i);
        // switch any non-ATGCN characters from the node sequence to N
        auto cleaned_seq = nonATGCNtoN(n->sequence());
        gssw_node* node = (gssw_node*)gssw_node_create(n, n->id(),
                          cleaned_seq.c_str(),
                          nt_table,
                          score_matrix);
        if (pinned_node_id == n->id()) {
            *gssw_pinned_node_out = node;
        }
        nodes[n->id()] = node;
        gssw_graph_add_node(graph, node);
    }

    for (int i = 0; i < g.edge_size(); ++i) {
        // Convert all the edges
        Edge* e = g.mutable_edge(i);
        if(!e->from_start() && !e->to_end()) {
            // This is a normal end to start edge.
            gssw_nodes_add_edge(nodes[e->from()], nodes[e->to()]);
        } else if(e->from_start() && e->to_end()) {
            // This is a start to end edge, but isn't reversing and can be converted to a normal end to start edge.

            // Flip the start and end
            gssw_nodes_add_edge(nodes[e->to()], nodes[e->from()]);
        } else {
            // TODO: It's a reversing edge, which gssw doesn't support yet. What
            // we should really do is do a topological sort to break cycles, and
            // then flip everything at the lower-rank end of this edge around,
            // so we don't have to deal with its reversing-ness. But for now we
            // just die so we don't get nonsense into gssw.
            #pragma omp critical
            {
                // We need the critical section so we don't throw uncaught
                // exceptions in multiple threads at once, leading to C++ trying
                // to run termiante in parallel. This doesn't make it safe, just
                // slightly safer.
                cerr << "Can't gssw over reversing edge " <<e->from() << (e->from_start() ? " start" : " end") << " -> "
                     << e->to() << (e->to_end() ? " end" : " start")  << endl;
                // TODO: there's no safe way to kill the program without a way
                // to signal the master to do it, via a shared variable in the
                // clause that made us parallel.
            }
            exit(1);
        }
    }

    return graph;

}
Example #8
0
void
GapHeatTransfer::computeGapValues()
{
  if (!_quadrature)
  {
    _has_info = true;
    _gap_temp = _gap_temp_value[_qp];
    _gap_distance = _gap_distance_value[_qp];
  }
  else
  {
    Node * qnode = _mesh.getQuadratureNode(_current_elem, _current_side, _qp);
    PenetrationInfo * pinfo = _penetration_locator->_penetration_info[qnode->id()];

    _gap_temp = 0.0;
    _gap_distance = 88888;
    _has_info = false;
    _edge_multiplier = 1.0;

    if (pinfo)
    {
      _gap_distance = pinfo->_distance;
      _has_info = true;

      Elem * slave_side = pinfo->_side;
      std::vector<std::vector<Real> > & slave_side_phi = pinfo->_side_phi;
      _gap_temp = _variable->getValue(slave_side, slave_side_phi);

      Real tangential_tolerance = _penetration_locator->getTangentialTolerance();
      if (tangential_tolerance != 0.0)
      {
        _edge_multiplier = 1.0 - pinfo->_tangential_distance / tangential_tolerance;
        if (_edge_multiplier < 0.0)
        {
          _edge_multiplier = 0.0;
        }
      }
    }
    else
    {
      if (_warnings)
      {
        std::stringstream msg;
        msg << "No gap value information found for node ";
        msg << qnode->id();
        msg << " on processor ";
        msg << processor_id();
        mooseWarning( msg.str() );
      }
    }
  }

  Point current_point(_q_point[_qp]);
  GapConductance::computeGapRadii(_gap_geometry_type, current_point, _p1, _p2, _gap_distance, _normals[_qp], _r1, _r2, _radius);
}
Example #9
0
void CommandAdd::undoCommandImpl() {
  ElementManager &element_manager = m_manager->elementManager();

  if (m_node_struct) {
    Node *node = m_node_struct->m_node;

    element_manager.detachNode(node->id());
    m_manager->graphicElementsMap().erase(node->id());
    m_manager->graphicNodesMap().erase(node->id());
  }
}
Example #10
0
File: MLGDao.cpp Project: caomw/mld
bool MLGDao::verticalCopyHLinks( const Node& source,
                                 const Node& target,
                                 Direction dir,
                                 bool safe,
                                 const ObjectsPtr& subset,
                                 const WeightMergerFunc& f )
{
    if( safe ) {  // Check source and target affiliation
        if( !checkAffiliation(source.id(), target.id(), dir) ) {
            return false;
        }
    }

    // Get source's neighbors
    ObjectsPtr srcNeighbors;
    if( subset )
        srcNeighbors = subset; // Temporary borrow
    else
        srcNeighbors.reset(m_g->Neighbors(source.id(), hlinkType(), Any));

    ObjectsIt it(srcNeighbors->Iterator());
    while( it->HasNext() ) {
        oid_t current = it->Next();
        NodeVec kin;
        if( dir == TOP )
            kin = getParentNodes(current);
        else
            kin = getChildNodes(current);

        if( kin.empty() ) {
            LOG(logERROR) << "MLGDao::verticalCopyHLinks: node as no parents";
            return false;
        }

        HLink currentLink = getHLink(source.id(), current);
        // For each child or parent
        for( Node& k: kin ) {
            HLink link = getHLink(target.id(), k.id());
            if( link.id() == Objects::InvalidOID ) {  // Top HLink doesn't exist
                addHLink(target, k, currentLink.weight());
            }
            else {  // Update top HLink with functor
                link.setWeight( f(link.weight(), currentLink.weight()) );
                if( !updateHLink(link) ) {
                    LOG(logERROR) << "MLGDao::verticalCopyHLinks: Failed to update top/bottom nodes HLINK";
                    return false;
                }
            }
        }
    }
    return true;
}
Example #11
0
File: MLGDao.cpp Project: caomw/mld
VLink MLGDao::addVLink( const Node& child, const Node& parent, AttrMap& data )
{
#ifdef MLD_SAFE
    auto srcLayer = getLayerIdForNode(child.id());
    auto tgtLayer = getLayerIdForNode(parent.id());
    bool affiliated = m_layer->affiliated(srcLayer, tgtLayer);
    if( !affiliated ) {
        LOG(logERROR) << "MLGDao::addVLink: Layers are not affiliated";
        return VLink();
    }
#endif
    return m_link->addVLink(child.id(), parent.id(), data);
}
Example #12
0
void
GapConductance::computeGapValues()
{
  if (!_quadrature)
  {
    _has_info = true;
    _gap_temp = _gap_temp_value[_qp];
    _gap_distance = _gap_distance_value[_qp];
  }
  else
  {
    Node * qnode = _mesh.getQuadratureNode(_current_elem, _current_side, _qp);
    PenetrationInfo * pinfo = _penetration_locator->_penetration_info[qnode->id()];

    _gap_temp = 0.0;
    _gap_distance = 88888;
    _has_info = false;

    if (pinfo)
    {
      _gap_distance = pinfo->_distance;
      _has_info = true;

      const Elem * slave_side = pinfo->_side;
      std::vector<std::vector<Real>> & slave_side_phi = pinfo->_side_phi;
      std::vector<dof_id_type> slave_side_dof_indices;

      _dof_map->dof_indices(slave_side, slave_side_dof_indices, _temp_var->number());

      for (unsigned int i = 0; i < slave_side_dof_indices.size(); ++i)
      {
        // The zero index is because we only have one point that the phis are evaluated at
        _gap_temp += slave_side_phi[i][0] * (*(*_serialized_solution))(slave_side_dof_indices[i]);
      }
    }
    else
    {
      if (_warnings)
        mooseWarning("No gap value information found for node ",
                     qnode->id(),
                     " on processor ",
                     processor_id(),
                     " at coordinate ",
                     Point(*qnode));
    }
  }

  Point current_point(_q_point[_qp]);
  computeGapRadii(
      _gap_geometry_type, current_point, _p1, _p2, _gap_distance, _normals[_qp], _r1, _r2, _radius);
}
Example #13
0
void
GapConductance::computeGapValues()
{
  if(!_quadrature)
  {
    _has_info = true;
    _gap_temp = _gap_temp_value[_qp];
    _gap_distance = _gap_distance_value[_qp];
    return;
  }
  else
  {
    Node * qnode = _mesh.getQuadratureNode(_current_elem, _current_side, _qp);
    PenetrationInfo * pinfo = _penetration_locator->_penetration_info[qnode->id()];

    _gap_temp = 0.0;
    _gap_distance = 88888;
    _has_info = false;

    if (pinfo)
    {
      _gap_distance = pinfo->_distance;
      _has_info = true;

      Elem * slave_side = pinfo->_side;
      std::vector<std::vector<Real> > & slave_side_phi = pinfo->_side_phi;
      std::vector<unsigned int> slave_side_dof_indices;

      _dof_map->dof_indices(slave_side, slave_side_dof_indices, _temp_var->number());

      for(unsigned int i=0; i<slave_side_dof_indices.size(); ++i)
      {
        //The zero index is because we only have one point that the phis are evaluated at
        _gap_temp += slave_side_phi[i][0] * (*(*_serialized_solution))(slave_side_dof_indices[i]);
      }
    }
    else
    {
      if (_warnings)
      {
        std::stringstream msg;
        msg << "No gap value information found for node ";
        msg << qnode->id();
        msg << " on processor ";
        msg << processor_id();
        mooseWarning( msg.str() );
      }
    }
  }
}
Example #14
0
File: MLGDao.cpp Project: caomw/mld
HLink MLGDao::addHLink( const Node& src, const Node& tgt, AttrMap& data )
{
//#ifdef MLD_SAFE
//    auto srcLayer = getLayerIdForNode(src.id());
//    auto tgtLayer = getLayerIdForNode(tgt.id());
//    if( srcLayer != tgtLayer
//            || srcLayer == Objects::InvalidOID
//            || tgtLayer == Objects::InvalidOID ) {
//        LOG(logERROR) << "MLGDao::addHLink: Nodes are not on the same layer";
//        return HLink();
//    }
//#endif
    return m_link->addHLink(src.id(), tgt.id(), data);
}
Example #15
0
void TopologyMap::add_node(const Node& mid_node,
                           const std::vector<std::pair<dof_id_type, dof_id_type> >& bracketing_nodes)
{
  const dof_id_type mid_node_id = mid_node.id();

  libmesh_assert_not_equal_to(mid_node_id, DofObject::invalid_id);

  for (unsigned int i=0; i != bracketing_nodes.size(); ++i)
    {
      const dof_id_type id1 = bracketing_nodes[i].first;
      const dof_id_type id2 = bracketing_nodes[i].second;
      const dof_id_type lower_id = std::min(id1, id2);
      const dof_id_type upper_id = std::max(id1, id2);

      // We should never be inserting inconsistent data
#ifndef NDEBUG
      map_type::iterator it =
        _map.find(std::make_pair(lower_id, upper_id));

      if (it != _map.end())
        libmesh_assert_equal_to (it->second, mid_node_id);
#endif

      this->_map.insert(std::make_pair(std::make_pair(lower_id, upper_id),
                                       mid_node_id));

    }
}
Example #16
0
// Metodo para la eliminacion de nodos
// @param x ID del nodo a buscar
bool Queue::supr(char x)
{
    // Precondicion
    if(!empty()){
        // Inicializamos el puntero p
        Node *p = start;
        Node *q = NULL;

        // Buscamos el item
        if((q = search(x))) p = q->next();

        // Verificamos si encontramos el item
        if(p && p->id() == x){
            if(p == start){
                // Eliminamos por el frente
                start = p->next();
            } else {
                // Eliminamos por en medio
                q->next(p->next());
            }

            // Eliminamos p
            delete p;

            _s--; // Restamos el tamaƱo de la cola

            // Retornamos true por eliminar el nodo
            return true;
        }
    }
    // Retornamos false por no eliminar ningun nodo
    return false;
}
Example #17
0
void VTKIO::nodes_to_vtk()
{
  const MeshBase& mesh = MeshOutput<MeshBase>::mesh();

  // containers for points and coordinates of points
  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  vtkSmartPointer<vtkDoubleArray> pcoords = vtkSmartPointer<vtkDoubleArray>::New();
  pcoords->SetNumberOfComponents(LIBMESH_DIM);
  points->SetNumberOfPoints(mesh.n_local_nodes()); // it seems that it needs this to prevent a segfault

  unsigned int local_node_counter = 0;

  MeshBase::const_node_iterator nd = mesh.local_nodes_begin();
  MeshBase::const_node_iterator nd_end = mesh.local_nodes_end();
  for (; nd != nd_end; nd++, ++local_node_counter)
    {
      Node* node = (*nd);

      double pnt[LIBMESH_DIM];
      for (unsigned int i=0; i<LIBMESH_DIM; ++i)
        pnt[i] = (*node)(i);

      // Fill mapping between global and local node numbers
      _local_node_map[node->id()] = local_node_counter;

      // add point
      pcoords->InsertNextTupleValue(pnt);
    }

  // add coordinates to points
  points->SetData(pcoords);

  // add points to grid
  _vtk_grid->SetPoints(points);
}
Example #18
0
File: MLGDao.cpp Project: caomw/mld
HLink MLGDao::addHLink( const Node& src, const Node& tgt, double weight )
{
//#ifdef MLD_SAFE
//    auto srcLayer = getLayerIdForNode(src.id());
//    auto tgtLayer = getLayerIdForNode(tgt.id());
//    if( srcLayer != tgtLayer
//            || srcLayer == Objects::InvalidOID
//            || tgtLayer == Objects::InvalidOID ) {
//        LOG(logERROR) << "MLGDao::addHLink: Nodes are not on the same layer";
//        return HLink();
//    }
//#endif
    if( weight == HLINK_DEF_VALUE )
        return m_link->addHLink(src.id(), tgt.id());
    else
        return m_link->addHLink(src.id(), tgt.id(), weight);
}
Example #19
0
 void BB::print_vcg_edges(FILE* f, bool suppressTrivial) {
   for (Node* n = first; n != last->next(); n = n->next()) {
     if (n->deleted && !(n == first || n == last)) continue;
     if (suppressTrivial && n->isTrivial()) {
       // don't print
     } else {
       for (fint i = 0; i < n->nSuccessors(); i++) {
         Node* nnext = n->nexti(i);
         while (nnext &&
                (nnext->deleted || suppressTrivial && nnext->isTrivial()))
           nnext = nnext->next();
         if (nnext) 
           fprintf(f, "edge:{ sourcename:\"%d\" targetname: \"%d\" }\n",
                   n->id(), nnext->id());
       }
     }
   }
 }
Example #20
0
File: MLGDao.cpp Project: caomw/mld
OLink MLGDao::addOLink( const Layer& layer, const Node& node, AttrMap& data )
{
#ifdef MLD_SAFE
    if( !m_layer->exists(layer) ) {
        LOG(logERROR) << "MLGDao::addOLink: Layer doesn't exist!";
        return OLink();
    }
#endif
    return m_link->addOLink(layer.id(), node.id(), data);
}
Example #21
0
void Graph::outputNodes(std::ostream& s) const
{
  if (mNodes.size() == 0) {
    return;
  }
  for (const SLLNode<Node*>* curr = mNodes.head();
       curr != NULL; curr = curr->next()) {
    Node* n = curr->value();
    s << n->id() 
      << " [label="
      << "\""
      << n->id()
      << " (" << n->shortestDistance() << ")"
      << "\"" 
      << "]"
      << " [shape=box];"
      << std::endl;
  }
}
Example #22
0
File: MLGDao.cpp Project: caomw/mld
mld::Node MLGDao::mirrorNode( oid_t current, Direction dir, const Layer& newLayer )
{
    // Get each node on the previous layer
    Node prevNode = m_node->getNode(current);
    // Add node in top layer
    Node newNode = addNodeToLayer(newLayer);

    // Link them
    if( dir == TOP )
        m_link->addVLink(prevNode.id(), newNode.id());
    else
        m_link->addVLink(newNode.id(), prevNode.id());

    // Update node weight if needed
    if( prevNode.weight() != NODE_DEF_VALUE ) {
        newNode.setWeight(prevNode.weight());
        m_node->updateNode(newNode);
    }
    return newNode;
}
Example #23
0
void build_tree(Node<T>& parent, int depth) {
    if (depth == 0)
        return;
    int id = parent.id();
    T value = parent.value();
    auto left_child {std::make_unique<Node<T>>(id + 1, value + 1)};
    parent.set_left(left_child);
    auto right_child {std::make_unique<Node<T>>(id + 2, value + 2)};
    parent.set_right(right_child);
    build_tree(parent.left(), depth - 1);
    build_tree(parent.right(), depth - 1);
}
Example #24
0
SVGSVGElement* SVGElement::ownerSVGElement() const
{
    Node* n = isShadowNode() ? const_cast<SVGElement*>(this)->shadowParentNode() : parentNode();
    while (n) {
        if (/*n->hasTagName(SVGNames::svgTag)*/n->id() == SVGNames::svgTag.id())
            return static_cast<SVGSVGElement*>(n);

        n = n->isShadowNode() ? n->shadowParentNode() : n->parentNode();
    }

    return 0;
}
Example #25
0
Number
MooseVariable::getNodalValueOlder(const Node & node)
{
  mooseAssert(_subproblem.mesh().isSemiLocal(const_cast<Node *>(&node)), "Node is not Semilocal");

  // Make sure that the node has DOFs
  /* Note, this is a reproduction of an assert within libMesh::Node::dof_number, this is done to produce a
   * better error (see misc/check_error.node_value_off_block) */
  mooseAssert(node.n_dofs(_sys.number(), _var_num) > 0, "Node " << node.id() << " does not contain any dofs for the " << _sys.system().variable_name(_var_num) << " variable");

  dof_id_type dof = node.dof_number(_sys.number(), _var_num, 0);
  return _sys.solutionOlder()(dof);
}
Example #26
0
// Metodo para busqueda de nodos
// Adaptado para retornar un nodo anteriro al que se busca
// @param x id del nodo a buscar
Queue::Node *Queue::search(char x)
{
    // Verificamos que la cola no este vacia
    if(!empty()){
        // Inicializamos el puntero p
        Node *p = start;
        Node *q = NULL;

        // Recorremos en busca del nodo
        while(p && p->id() < x){
            q = p;
            p = p->next();
        }

        // Verificamos si el dato buscado es igual al del nodo
        if(p && p->id() == x) return q; // Retornamos el nodo
        else return NULL; // Retornamos null, al no encontrar el dato
    }

    // Si no existe el nodo retornamos null
    return NULL;
}
Example #27
0
void Viewer::selectById(const unsigned int & id)
{
    SceneTraverser traverser;
    Node * result = nullptr;
    traverser.traverse(*m_camera, [&result, &id](Node & node)
    {
        if( node.id() == id){
            result = &node;
            return false;
        }
        return true;
    });

    if (result)
    {
        Node * parent = *result->parents().begin();
        int siblings = parent->children().size() - 1;
        if (m_selectedNodes.contains(id))
        {
            this->deselectNode(result);
            if (!siblings)
            {
                this->deselectNode(parent);
                this->treeToggleSelection(parent->id());
            }
        }
        else
        {
            this->selectNode(result);
            if (!siblings)
            {
                this->selectNode(parent);
                this->treeToggleSelection(parent->id());
            }
        }
    }
    this->updateInfoBox();
}
Example #28
0
int main()
{
  /*uint32_t id1 = (4 | GraphElementId::ARC);
  printf("0x%x\n", id1);

  // Check removing flags ARC
  id1 = (id1 & ~GraphElementId::MASK) | GraphElementId::NODE;
  printf("0x%x\n", id1);

  // Check removing flags ARC and NODE
  id1 = (4 | GraphElementId::ARC);
  uint32_t id2 = (8 | GraphElementId::NODE);
  id1 = (id2 & ~GraphElementId::MASK) | GraphElementId::ZONE;
  printf("0x%x\n", id1);*/


  Node n1;
  Node n2;
  Node n3;
  Node n4;
  Node p;

  n1.m_arcs.push_back(&n2);
  n1.m_arcs.push_back(&n3);
  n1.m_arcs.push_back(&n4);

  std::cout << "ID: " << n1.id() << " arr: " << n1.m_arcs.size() << std::endl;
  std::cout << "ID: " << p.id() << " arr: " << p.m_arcs.size() << std::endl;

  std::swap(n1, p);

  std::cout << "ID: " << n1.id() << " arr: " << n1.m_arcs.size() << std::endl;
  std::cout << "ID: " << p.id() << " arr: " << p.m_arcs.size() << std::endl;

  return 0;
}
Example #29
0
 // Make sure to sort by node ID and not pointer value, because people will expect that.
 inline bool operator<(const NodeTraversal& other) const {
     if(node == nullptr && other.node != nullptr) {
         // We might have a null node when they don't.
         return true;
     }
     if(other.node == nullptr && node != nullptr) {
         // They might have a null node when we don't.
         return false;
     }
     if(other.node == nullptr && node == nullptr) {
         // We bith might have null nodes.
         return backward < other.backward;
     }
     // Now we know none of the nodes are null. Sort by actual ID.
     return node->id() < other.node->id() || (node == other.node && backward < other.backward);
 }
Example #30
0
    void
    bootstrap() {
        // Create initial nodes

        static Node bootstrap_type_nodes[] = {
            {  0, 9, { CALI_TYPE_USR    },  },
            {  1, 9, { CALI_TYPE_INT    },  },
            {  2, 9, { CALI_TYPE_UINT   },  },
            {  3, 9, { CALI_TYPE_STRING },  },
            {  4, 9, { CALI_TYPE_ADDR   },  },
            {  5, 9, { CALI_TYPE_DOUBLE },  },
            {  6, 9, { CALI_TYPE_BOOL   },  },
            {  7, 9, { CALI_TYPE_TYPE   },  },
            { CALI_INV_ID, CALI_INV_ID, { } } 
        };
        static Node bootstrap_attr_nodes[] = {
            {  8, 8,  { CALI_TYPE_STRING, "cali.attribute.name",  19 } },
            {  9, 8,  { CALI_TYPE_STRING, "cali.attribute.type",  19 } },
            { 10, 8,  { CALI_TYPE_STRING, "cali.attribute.prop",  19 } },
            { CALI_INV_ID, CALI_INV_ID, { } } 
        };

        m_node_id.store(11);

        // Fill type map

        for (Node* node = bootstrap_type_nodes ; node->id() != CALI_INV_ID; ++node)
            m_type_nodes[node->data().to_attr_type()] = node;

        // Initialize bootstrap attributes

        const MetaAttributeIDs keys = { 8, 9, 10 };
        m_meta_attributes = keys;

        struct attr_node_t { 
            Node* node; cali_attr_type type;
        } attr_nodes[] = { 
            { &bootstrap_attr_nodes[0], CALI_TYPE_STRING },
            { &bootstrap_attr_nodes[1], CALI_TYPE_TYPE   },
            { &bootstrap_attr_nodes[2], CALI_TYPE_INT    }
        };

        for ( attr_node_t p : attr_nodes ) {
            // Append to type node
            m_type_nodes[p.type]->append(p.node);
        }
    }