void remove_cell_from_node(b_tree_node *n, b_tree_cell *cell) { if (n != nullptr && cell != nullptr) { b_tree_cell *old_header = n->header; n->erase(cell); if (old_header != n->header) { refresh_index_upwards(n); } if (n->size < (B_TREE_ORDER + 1) / 2 && n->pcell) { b_tree_node *target; if (n->pcell->next != nullptr) { target = n; merge_node(target, n->pcell->next->child); split_node(target); } else if (n->pcell->previous != nullptr) { target = n->pcell->previous->child; merge_node(target, n); split_node(target); } } while (root->size == 1 && root->header->child) { b_tree_node *t = root; root = root->header->child; root->pcell = nullptr; root->pnode = nullptr; delete t->header; delete t; } } }
YAML::Node Task::emit() const { YAML::Node node; node["vm-name"] = vm_name; merge_node(node, concurrent_execution.emit()); merge_node(node, time_measurement.emit()); return node; }
YAML::Node Task_container::emit() const { YAML::Node node; node["task"] = type(); node["vm-configurations"] = tasks; merge_node(node, concurrent_execution.emit()); merge_node(node, id.emit()); return node; }
YAML::Node Migrate::emit() const { YAML::Node node = Task::emit(); node["destination"] = dest_hostname; YAML::Node params = node["parameter"]; merge_node(params, live_migration.emit()); merge_node(params, rdma_migration.emit()); merge_node(params, pscom_hook_procs.emit()); return node; }
YAML::Node Start::emit() const { YAML::Node node = Task::emit(); merge_node(node, vcpus.emit()); merge_node(node, memory.emit()); merge_node(node, xml.emit()); if (!pci_ids.empty()) node["pci-ids"] = pci_ids; return node; }
static tree_node* delete_with_brother(tree_node *node, tree_node *parent, int ith, int direction) { tree_node *brother; if(direction == 0) brother = parent->children[ith-1]; else brother = parent->children[ith+1]; if(brother->keynum > 1) { if(direction == 0) { int i = node->keynum; while(i > 0) { node->key[i] = node->key[i-1]; node->children[i+1] = node->children[i]; i--; } node->children[i+1] = node->children[i]; node->key[0] = parent->key[ith-1]; node->keynum++; int n = brother->keynum - 1; parent->key[ith-1] = brother->key[n]; node->children[0] = brother->children[n+1]; brother->children[n+1] = NULL; brother->keynum--; } else { int n = node->keynum; node->key[n] = parent->key[ith]; node->keynum++; node->children[n+1] = brother->children[0]; parent->key[ith] = brother->key[0]; int i = 0; while(i < brother->keynum - 1) { brother->key[i] = brother->key[i+1]; brother->children[i] = brother->children[i+1]; i++; } brother->children[i] = brother->children[i+1]; brother->keynum--; } } else { node = merge_node(node, parent, ith, direction); } return node; }
YAML::Node Stop::emit() const { YAML::Node node = Task::emit(); merge_node(node, force.emit()); return node; }
dstring_t *haplo_split(GapIO *io, snp_t *snp, int nsnps, int verbose, double min_score, int two_pass, int fast_mode, double c_offset, int max_sets) { graph *g; edge *e; dstring_t *ds; verbosity = verbose; g = graph_from_snps(io, snp, nsnps, c_offset); if (verbosity >= 3) print_matrix(g); graph_add_edges(g); graph_calc_chimeric_scores(g); graph_calc_link_scores(g, 1); if (verbosity >= 3) graph_print(g, 0); if (verbosity) puts("Merging graph nodes"); while ((e = best_edge(g)) && (e->linkage_score > min_score)) { if (verbosity >= 1) { putchar('.'); fflush(stdout); } merge_node(g, e); graph_calc_link_scores(g, fast_mode ? 0 : 1); if (verbosity >= 4) { print_matrix(g); graph_print(g, 1); } } if (verbosity >= 1) puts(""); /* graph_print(g, 1); */ if (two_pass) { /* Add fake zero-score edges if we want just 2-haplotypes */ add_zero_edges(g); graph_calc_link_scores(g, 1); if (verbosity >= 4) graph_print(g, 1); puts("===pass 2==="); while ((e = best_edge(g)) && (e->linkage_score > min_score)) { merge_node(g, e); graph_calc_link_scores(g, fast_mode ? 0 : 1); /* graph_print(g, 1); */ } /* graph_print(g, 1); */ } /* Force number of groups to be X? */ if (max_sets) { int ngroups = count_groups(g); add_zero_edges(g); for (; ngroups > max_sets; ngroups--) { e = best_edge(g); if (!e) { printf("Bailed out as no edge connecting groups\n"); break; } merge_node(g, e); graph_calc_link_scores(g, fast_mode ? 0 : 1); } } /* print_groups(g); */ ds = list_groups(g); graph_destroy(g); return ds; }
tree_node* tree_delete(tree_node* root, int key) { tree_node *newNode; // case a: the key is in a leaf, delete the key directly. if(root->leaf == 1) newNode = delete_from_leaf(root, key); else { int i = 0; while((i < root->keynum)&&(root->key[i] < key)) i++; //case b: when the key in an internal node, if its left child's or // right child's keynum > 1, delete the node's predecessor or successor. // otherwise, merge two children. if((i < root->keynum)&&(root->key[i] == key)) { if(root->children[i]->keynum > 1) { int p = predecessor(root, i); root->key[i] = p; newNode = tree_delete(root->children[i], p); } else if(root->children[i+1]->keynum > 1) { int s = successor(root, i+1); root->key[i] = s; newNode = tree_delete(root->children[i+1], s); } else { root = merge_node(root->children[i], root, i, 1); newNode = tree_delete(root, key); } } else { //case c: the key in not in current internal node and the node which the // key is in is the offspring of the ith children of the current node. //c1: the ith child has enough keys. call tree_delete() recursively with the child. //c2: find the left or right brother who has enough keys, move one key from the parent // to the child, and move one key from brother to the parent. if both brothers have no // enough keys, merge the child with its one brother. if(root->children[i]->keynum > 1) { newNode = tree_delete(root->children[i], key); } else { tree_node *temp; if(i == 0) temp = delete_with_brother(root->children[0], root, 0, 1); else if(i == root->keynum) temp = delete_with_brother(root->children[root->keynum], root, root->keynum, 0); else { if(root->children[i-1]->keynum > 1) temp = delete_with_brother(root->children[i], root, i, 0); else temp = delete_with_brother(root->children[i], root, i, 1); } newNode = tree_delete(temp, key); } } } if(newNode->parent == NULL) root = newNode; return root; }