/* Free functions */
+static void graph_node_data_free(void* n)
+{
+ graph_node_data_t data = static_cast<graph_node_data_t>(n);
+ delete data;
+}
+
static void graph_edge_data_free(void* e) // FIXME: useless code duplication
{
- sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t)e;
+ sg_platf_route_cbarg_t e_route = static_cast<sg_platf_route_cbarg_t>(e);
if (e_route) {
delete e_route->link_list;
- xbt_free(e_route);
+ delete e_route;
}
}
}
if (not found) {
- sg_platf_route_cbarg_t e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+ sg_platf_route_cbarg_t e_route = new s_sg_platf_route_cbarg_t;
e_route->link_list = new std::vector<surf::LinkImpl*>();
e_route->link_list->push_back(surf_network_model->loopback_);
xbt_graph_new_edge(routeGraph_, node, node, e_route);
xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_);
xbt_dynar_foreach (nodes, cursor, node) {
- graph_node_data_t data = (graph_node_data_t)xbt_graph_node_get_data(node);
+ graph_node_data_t data = static_cast<graph_node_data_t>(xbt_graph_node_get_data(node));
data->graph_id = cursor;
}
}
xbt_node_t DijkstraZone::routeGraphNewNode(int id, int graph_id)
{
- graph_node_data_t data = xbt_new0(s_graph_node_data_t, 1);
+ graph_node_data_t data = new s_graph_node_data_t;
data->id = id;
data->graph_id = graph_id;
xbt_node_t node = xbt_graph_new_node(routeGraph_, data);
- graph_node_map_element_t elm = xbt_new0(s_graph_node_map_element_t, 1);
+ graph_node_map_element_t elm = new s_graph_node_map_element_t;
elm->node = node;
graphNodeMap_.insert({id, elm});
graph_node_map_element_t src_elm = nodeMapSearch(src_id);
graph_node_map_element_t dst_elm = nodeMapSearch(dst_id);
- int src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id;
- int dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id;
+ int src_node_id = static_cast<graph_node_data_t>(xbt_graph_node_get_data(src_elm->node))->graph_id;
+ int dst_node_id = static_cast<graph_node_data_t>(xbt_graph_node_get_data(dst_elm->node))->graph_id;
/* if the src and dst are the same */
if (src_node_id == dst_node_id) {
if (edge == nullptr)
THROWF(arg_error, 0, "No route from '%s' to '%s'", src->name().c_str(), dst->name().c_str());
- sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t)xbt_graph_edge_get_data(edge);
+ sg_platf_route_cbarg_t e_route = static_cast<sg_platf_route_cbarg_t>(xbt_graph_edge_get_data(edge));
for (auto const& link : *e_route->link_list) {
route->link_list->insert(route->link_list->begin(), link);
} else { /* not cached mode, or cache miss */
int nr_nodes = xbt_dynar_length(nodes);
- double* cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
- pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
- xbt_heap_t pqueue = xbt_heap_new(nr_nodes, xbt_free_f);
+ double* cost_arr = new double[nr_nodes]; /* link cost from src to other hosts */
+ pred_arr = new int[nr_nodes]; /* predecessors in path from src */
+ xbt_heap_t pqueue = xbt_heap_new(nr_nodes, nullptr);
/* initialize */
cost_arr[src_node_id] = 0.0;
pred_arr[i] = 0;
/* initialize priority queue */
- int* nodeid = xbt_new0(int, 1);
- *nodeid = i;
+ int* nodeid = new int(i);
xbt_heap_push(pqueue, nodeid, cost_arr[i]);
}
xbt_dynar_foreach (xbt_graph_node_get_outedges(v_node), cursor, edge) {
xbt_node_t u_node = xbt_graph_edge_get_target(edge);
- graph_node_data_t data = (graph_node_data_t)xbt_graph_node_get_data(u_node);
+ graph_node_data_t data = static_cast<graph_node_data_t>(xbt_graph_node_get_data(u_node));
int u_id = data->graph_id;
- sg_platf_route_cbarg_t tmp_e_route = (sg_platf_route_cbarg_t)xbt_graph_edge_get_data(edge);
+ sg_platf_route_cbarg_t tmp_e_route = static_cast<sg_platf_route_cbarg_t>(xbt_graph_edge_get_data(edge));
int cost_v_u = tmp_e_route->link_list->size(); /* count of links, old model assume 1 */
if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
pred_arr[u_id] = *v_id;
cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
- int* nodeid = xbt_new0(int, 1);
- *nodeid = u_id;
+ int* nodeid = new int(u_id);
xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
}
}
/* free item popped from pqueue */
- xbt_free(v_id);
+ delete v_id;
}
- xbt_free(cost_arr);
+ delete[] cost_arr;
xbt_heap_free(pqueue);
}
if (edge == nullptr)
THROWF(arg_error, 0, "No route from '%s' to '%s'", src->name().c_str(), dst->name().c_str());
- sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t)xbt_graph_edge_get_data(edge);
+ sg_platf_route_cbarg_t e_route = static_cast<sg_platf_route_cbarg_t>(xbt_graph_edge_get_data(edge));
NetPoint* prev_gw_src = gw_src;
gw_src = e_route->gw_src;
if (not routeCache_.empty() && elm == nullptr) {
/* add to predecessor list of the current src-host to cache */
- elm = xbt_new0(s_route_cache_element_t, 1);
+ elm = new s_route_cache_element_t;
elm->pred_arr = pred_arr;
elm->size = size;
routeCache_.insert({src_id, elm});
}
if (routeCache_.empty())
- xbt_free(pred_arr);
+ delete[] pred_arr;
}
DijkstraZone::~DijkstraZone()
{
- xbt_graph_free_graph(routeGraph_, &xbt_free_f, &graph_edge_data_free, &xbt_free_f);
+ xbt_graph_free_graph(routeGraph_, &graph_node_data_free, &graph_edge_data_free, nullptr);
}
/* Creation routing model functions */