Example #1
0
/**
 * @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]); 
}
Example #2
0
static VOID local doCreate_Classes(HWND hWnd)
{
   PAINTSTRUCT ps;
   HDC   hDC;
   HFONT hSaveFont;
   INT   numClasses = classMax() - CLASSMIN; /* total number of classes */

   cBrowse.hNormalCursor = LoadCursor(NULL, IDC_ARROW);
   cBrowse.hMoveClassCursor = LoadCursor(hThisInstance, "MOVECLASSCURSOR");
   cBrowse.SelectedClass = -1;            
   cBrowse.Moved         = FALSE;                   
   cBrowse.ClassesTopX   = 10;
   cBrowse.ClassesTopY   = 10;
   cBrowse.XOffset       = 0;
   cBrowse.YOffset       = 0;

   if (!allocNodes(numClasses)) {
     MessageBox(hWnd, "Out of memory: create nodes list", NULL, MB_ICONEXCLAMATION | MB_OK);
     return;
   }

   hDC = BeginPaint(hWnd, &ps);

   hSaveFont = SelectObject(hDC, hDialogFont);
     
   buildClassGraph( hDC );

   /* Restore font */
   SelectObject(hDC, hSaveFont);
   
   EndPaint(hWnd, &ps);

   /* Show upper-left part of window */
   SetScrollPos(hWnd, SB_HORZ, 0, TRUE);
   SetScrollPos(hWnd, SB_VERT, 0, TRUE);

   setClassBrowserSize();
}
Example #3
0
/**
 * @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]);
}