// sort the links in the routing table for all the DAGs, on // their proximities in descenting order (highest proximity link first). *operation* void sort_routing_table() *traverse* *from* RoutingTable *through* -> *, dag, * *to* DagAdjacency *carry* *in* Dag* dag = (@ this @) *along* *from* Dag *to* DagAdjacency *wrapper* DagAdjacency (@ this->sort_neighbors(dag); @) // sort the neighbors of the current dag adjacency *operation* void sort_neighbors(Dag* dag) *traverse* *from* DagAdjacency *through* -> *, neighbors, * *to* DagNeighbor *carry* *inout* DagNeighbor** neighbor_array = (@ new DagNeighbor*[get_neighbors()->list_length()] @), *inout* int count = (@ 0 @) *along* *from* DagAdjacency *through* -> *, neighbors, * *to* DagNeighbor *wrapper* DagNeighbor (@ neighbor_array[count++] = this; @) *wrapper* DagAdjacency *suffix* (@ sort_array(neighbor_array, count, dag); DagNeighbor_List* sorted_list = build_neighbors_from_array(neighbor_array, count); this->set_neighbors(sorted_list); delete neighbor_array; @) // sort the contents of the array, using insertion sort. *operation* void sort_array(DagNeighbor** array, int count, Dag* dag) *wrapper* DagAdjacency (@ int i,j; DagNeighbor* key; for (j=1; j < count; j++) { key = array[j]; i = j-1; while (i >= 0 && compare_neighbors(array[i], key, dag)) { array[i+1] = array[i]; i--; } array[i+1] = key; } @) // compare function used for sorting. *operation* int compare_neighbors(DagNeighbor* n1, DagNeighbor* n2, Dag* dag) *init* (@ 0 @) *wrapper* DagAdjacency (@ VNode* v1 = n1->get_neighbor(); VNode* v2 = n2->get_neighbor(); DagAdjacency* dag_adj1 = dag->find(v1); DagAdjacency* dag_adj2 = dag->find(v2); return_val = (*(dag_adj1->get_proximity()) < *(dag_adj2->get_proximity())); @) // make a list of the DagNeighbors in the array. *operation* DagNeighbor_List* build_neighbors_from_array(DagNeighbor** array, int count) *init* (@ new DagNeighbor_List() @) *wrapper* DagAdjacency (@ int i; for (i = 0; i < count ; i++) { return_val->append(array[i]); } @)