int main() { struct rbTree* t = treeInit(); struct rbTree *root = t = rbTreeInsert(t , 3); rbTreeInsert(t , 8); struct rbTree * x = rbTreeInsert(t , 4); struct rbTree * y = rbTreeInsert(t , 14); rbTreeInsert(t , 9); rbTreeInsert(t , 2); rbTreeInsert(t , 0); treeWalk(t); // treeWalk(t); // treeDelete(x); // treeWalk(root); // treeDelete(y); // treeWalk(root); // printf("\nmax = %d min = %d \n", treeMax(t) -> k, treeMin(t) -> k); // if(treeSearch(t, 3) != NULL) // printf("found\n"); // printf("%d\n",t -> k); // t = treeSuccessor(t); // printf("%d\n",t -> k); // t = treePredecessor(t); // printf("%d\n",t -> k); }
void nbodyBarnesHut(particle * particles, int count, int n, double timeDiff, double eps, char * outputPath) { int step; sprintf(fileParamBuff, "%s_%%0%dd.vtk", outputPath, ((int) log10(n) + 1)); bodyptr bodies = convertStruct(particles, count); /* End converting */ /* Do the stepping */ bodyptr p; for (step = 1; step <= 1; step++) { cellptr root; real rootSize; /* Make the tree */ treeInit(&root, bodies, count, &rootSize); /* Calculate force */ calculateForce(root, eps, rootSize); /* Advance each body */ for (p = bodies; p < bodies + count; p++) { /* Advance the speed */ /* Advance the position */ } /* Free the tree */ treeFree(&root); } }
/** * @brief test insert to AVL tree * **/ void test_insert_AVL(){ int i; treeInit(); srand(time(NULL)); /*test insert node*/ for(i = 0; i < MAX_NODES + 5; i++){ tree_node_t *node = allocNodes(); if(node == NULL) continue; obtain_random_node(node); printf("inserting [%d -- %d] R(%d) eventIndex %d \n", node->start_lba, node->end_lba, node->type, node->eventIndex); insertNode(&rootArray[0], node, 1); printf("AVL tree propety maintained? "); if(test_AVL_balanced(rootArray[0]) == 1) printf("Y\n"); else printf("N\n"); printf("\n"); } treeDump(rootArray[0]); }
void display (void) { glClearColor (1.0,1.0,1.0,1.0); glClear (GL_COLOR_BUFFER_BIT); glLoadIdentity(); gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //initialize with 15 iterations treeInit(15); glFlush(); }
void main() { char buffer[20000]; char *commits[1000]; int numcommits, i; numcommits = getHashes(buffer, commits); treeInit(commits, numcommits); printGraph(commits, numcommits); deinitialize(numcommits); }
ResultWidght::ResultWidght(QWidget *parent) : QWidget(parent), ui(new Ui::ResultWidght) { ui->setupUi(this); //set Layout to deal with Responsive Layout QGridLayout *resultLayout = new QGridLayout(this); resultLayout->addWidget(ui->gridLayoutWidget); //prepare network prepareNetManager(); //set connect connect(netManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(reply_get_essential_gene(QNetworkReply*))); treeInit(); }
/** * @brief: random test 2, unoverlapped range lock and unlock * */ void random_test2(){ int i, j; for(j = 0; j < 2; j++){ treeInit(); /* *to check the lock */ for(i = 0; i < MAX_NODES; i++){ unsigned start_lba = i*5; unsigned end_lba = start_lba + 4; unsigned type = rand()%2; lockRequest(start_lba, end_lba, type, 1, 0); } //treeDump(rootArray[0]); /* *to check the unlock */ for(i = 0; i < MAX_NODES -2; i++){ printf("\n\ndeleting case %d with", i+ 1); int index = (MAX_NODES - i - 1); printf(" event index %d\n", nodes[index].eventIndex); lockRelease(&nodes[index], 0); } treeDump(rootArray[0]); /* *to check the index overflow */ for(i = 0; i < MAX_NODES; i++){ unsigned start_lba = i*5; unsigned end_lba = start_lba + 4; unsigned type = rand()%2; lockRequest(start_lba, end_lba, type, 1, 0); treeDump(rootArray[0]); } printf("\n"); } }
void treeInsert(node **root, unsigned long long new_value) { unsigned long long direction; node *new_node; splay(root, new_value); if (*root != 0 && (*root)->value == new_value) return; new_node = malloc(sizeof(node)); treeInit(&new_node, new_value); if (*root == 0) { *root = new_node; return; } direction = (*root)->value > new_value; join(direction, &new_node, root); join(!direction, &new_node, &(*root)->child[!direction]); (*root)->child[!direction] = 0; *root = new_node; }
/** * @brief: Test one example */ void test_case1(){ treeInit(); tree_node_t *n1,*n2, *n3, *n4, *n5, *n6; n1 = allocNodes(); n2 = allocNodes(); n3 = allocNodes(); n4 = allocNodes(); n5 = allocNodes(); n6 = allocNodes(); /** * Event 1: R [ 1- 40] */ n1->eventIndex = 1; n1->start_lba = 1; n1->end_lba = 40; n1->type = 0; /** * Event 2: W [ 1- 10] */ n2->eventIndex = 2; n2->start_lba = 1; n2->end_lba = 10; n2->type = 1; /** * Event 3: W [ 8- 20] */ n3->eventIndex = 3; n3->start_lba = 8; n3->end_lba = 20; n3->type = 1; /** * Event 4: W [ 21- 30] */ n4->eventIndex = 4; n4->start_lba = 21; n4->end_lba = 30; n4->type = 1; /** * Event 5: W [ 31- 40] */ n5->eventIndex = 5; n5->start_lba = 31; n5->end_lba = 40; n5->type = 1; /** * Event 6: R [ 1- 40] */ n6->eventIndex = 6; n6->start_lba = 1; n6->end_lba = 40; n6->type = 0; /*insert all events, it should be a linked list * event 1 R[1-40] -->event 2 W[1-10] -->event 3 W[8-20] -->event 4 W[21-30] -->event 5 W[31-40] -->event 6 R[1-40] */ insertNode(&rootArray[0], n1, 1); insertNode(&rootArray[0], n2, 1); insertNode(&rootArray[0], n3, 1); insertNode(&rootArray[0], n4, 1); insertNode(&rootArray[0], n5, 1); insertNode(&rootArray[0], n6, 1); treeDump(rootArray[0]); printf("remove n1\n"); lockRelease(n1, 0); /* * the avl tree should be: * event 4 --> event 6 * / \ *event 3 <- event 2 event 5 */ treeDump(rootArray[0]); /** * delete event 6, and it should be rejected. */ printf("----\n\n"); printf("remove n6\n"); lockRelease(n6, 0); treeDump(rootArray[0]); /* * delete event 2, and the AVL tree should be like this * * event 4 --> event 3 -->event 6 * \ * event 5 */ printf("---\n\n"); printf("remove n2\n"); lockRelease(n2, 0); treeDump(rootArray[0]); /* * delete event 4, and the AVL tree should be like this * * event 5 ->event 6 * / * event 3 */ printf("--\n\n"); printf("remove n4\n"); lockRelease(n4, 0); treeDump(rootArray[0]); /* * delete event 5, and the AVL tree should be like this * * event 3 -->event 6 * */ printf("---\n\n"); printf("remove n5\n"); lockRelease(n5, 0); treeDump(rootArray[0]); /* * delete event 3, and the AVL tree should be like this. * * event 6 */ printf("--\n\n"); printf("remove n3\n"); lockRelease(n3, 0); treeDump(rootArray[0]); }