Update of /cvsroot/avl/avl/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7379
Modified Files:
avl.cpp bst.cpp test.cpp test.h
Log Message:
completed gtk gui and list-> vector conversion
Index: test.h
===================================================================
RCS file: /cvsroot/avl/avl/src/test.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** test.h 6 Sep 2004 13:16:36 -0000 1.9
--- test.h 7 Sep 2004 14:37:01 -0000 1.10
***************
*** 25,29 ****
#include <time.h>
! #include <list>
#include <algorithm>
--- 25,29 ----
#include <time.h>
! #include <vector>
#include <algorithm>
Index: bst.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/bst.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** bst.cpp 7 Sep 2004 13:03:21 -0000 1.13
--- bst.cpp 7 Sep 2004 14:37:01 -0000 1.14
***************
*** 491,495 ****
//needed workaround - aggiungo un primo elemento root
gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,NULL);
! gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, "Here Begins AVL Tree Diplay", -1);
//prendo la root e stampo tutto l'albero, appendo il primo valore e poi ricorsivamente tutti gli altri
--- 491,495 ----
//needed workaround - aggiungo un primo elemento root
gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,NULL);
! gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, "Here Begins Tree Diplay", -1);
//prendo la root e stampo tutto l'albero, appendo il primo valore e poi ricorsivamente tutti gli altri
***************
*** 505,509 ****
//finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero.
cell = gtk_cell_renderer_text_new ();
! column = gtk_tree_view_column_new_with_attributes ("AVL Tree",cell,"text", 0, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (column));
--- 505,509 ----
//finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero.
cell = gtk_cell_renderer_text_new ();
! column = gtk_tree_view_column_new_with_attributes ("Tree",cell,"text", 0, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (column));
Index: test.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/test.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** test.cpp 7 Sep 2004 10:40:17 -0000 1.11
--- test.cpp 7 Sep 2004 14:37:01 -0000 1.12
***************
*** 22,27 ****
Test::~Test() {
! //if (avlt) delete avlt;
! //if (bst) delete bst;
}
--- 22,26 ----
Test::~Test() {
!
}
***************
*** 45,48 ****
--- 44,48 ----
int random;
clock_t start, end;
+ GtkWidget *dialog;
srand ( time(NULL) );
***************
*** 55,59 ****
--- 55,65 ----
end = clock();
init_timer = ((double) (end - start)) / CLOCKS_PER_SEC;
+ #ifndef GUI
printf("AVL Initialization of %d items tree took %lf seconds\n",base_limit,init_timer);
+ #else
+ dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "AVL Initialization of %d items tree took %lf seconds\n",base_limit,init_timer);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ #endif
}
***************
*** 66,70 ****
--- 72,82 ----
end = clock();
init_timer = ((double) (end - start)) / CLOCKS_PER_SEC;
+ #ifndef GUI
printf("BST Initialization of %d items tree took %lf seconds\n",base_limit,init_timer);
+ #else
+ dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "BST Initialization of %d items tree took %lf seconds\n",base_limit,init_timer);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ #endif
}
}
***************
*** 77,85 ****
int random_erase;
int erase_counter=0,insert_counter=0;
! list<int>::iterator IT;
! list<int> insertion_list;
! int x;
clock_t start, end;
int waste=0;
srand ( time(NULL) );
--- 89,97 ----
int random_erase;
int erase_counter=0,insert_counter=0;
! vector<int> insertion_list;
clock_t start, end;
int waste=0;
+ GtkWidget *dialog;
+
srand ( time(NULL) );
***************
*** 97,114 ****
random_erase=rand()%insertion_list.size();
!
! for ( IT=insertion_list.begin(), x=0; x<=random_erase && IT!=insertion_list.end();
! IT++, x++)
! {
! if (x==random_erase) {
! //printf("x:%d value=%d\n",x,*IT);
! // printf("erased number %d\n",*IT);
! if (IT!=insertion_list.end()){
! avlt=avlt->erase(*IT);
! insertion_list.erase(IT);
! }
! erase_counter++;
! }
! }
}
else waste++;
--- 109,115 ----
random_erase=rand()%insertion_list.size();
! avlt=avlt->erase(insertion_list[random_erase]);
! insertion_list.erase(insertion_list.begin()+random_erase);
! erase_counter++;
}
else waste++;
***************
*** 117,122 ****
end=clock();
change_timer = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("AVL TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted:%d\n",insert_counter,erase_counter,change_timer,upper_limit,waste);
!
}
--- 118,128 ----
end=clock();
change_timer = ((double) (end - start)) / CLOCKS_PER_SEC;
+ #ifndef GUI
printf("AVL TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted:%d\n",insert_counter,erase_counter,change_timer,upper_limit,waste);
! #else
! dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"AVL TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted:%d\n",insert_counter,erase_counter,change_timer,upper_limit,waste);
! gtk_dialog_run (GTK_DIALOG (dialog));
! gtk_widget_destroy (dialog);
! #endif
}
***************
*** 129,137 ****
int random_erase;
int erase_counter=0,insert_counter=0;
! list<int>::iterator IT;
! list<int> insertion_list;
! int x;
clock_t start, end;
int waste=0;
srand ( time(NULL) );
--- 135,142 ----
int random_erase;
int erase_counter=0,insert_counter=0;
! vector<int> insertion_list;
clock_t start, end;
int waste=0;
+ GtkWidget *dialog;
srand ( time(NULL) );
***************
*** 149,175 ****
random_erase=rand()%insertion_list.size();
! for ( IT=insertion_list.begin(), x=0; x<=random_erase && IT!=insertion_list.end();IT++, x++)
! {
! if (x==random_erase) {
! //printf("x:%d value=%d\n",x,*IT);
! // printf("erased number %d\n",*IT);
! if (IT!=insertion_list.end()){
! //bst->erase(*IT);
! //printf("%d\n",*IT);
! insertion_list.erase(IT);
! }
!
! erase_counter++;
! }
! }
} else waste++;
}
end=clock();
change_timer = ((double) (end - start)) / CLOCKS_PER_SEC;
! printf("BST TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted %d\n",insert_counter,erase_counter,change_timer,upper_limit,waste);
!
}
-
}
//questo metodo fa un confronto delle prestazioni di un AVL e un BST
void Test::comparation(int base_tree_size, int upperbound ) {
--- 154,174 ----
random_erase=rand()%insertion_list.size();
! bst->erase(insertion_list[random_erase]);
! insertion_list.erase(insertion_list.begin()+random_erase);
! erase_counter++;
} else waste++;
}
end=clock();
change_timer = ((double) (end - start)) / CLOCKS_PER_SEC;
! #ifndef GUI
! printf("BST TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted:%d\n",insert_counter,erase_counter,change_timer,upper_limit,waste);
! #else
! dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"BST TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted:%d\n",insert_counter,erase_counter,change_timer,upper_limit,waste);
! gtk_dialog_run (GTK_DIALOG (dialog));
! gtk_widget_destroy (dialog);
! #endif
}
}
+
//questo metodo fa un confronto delle prestazioni di un AVL e un BST
void Test::comparation(int base_tree_size, int upperbound ) {
***************
*** 177,181 ****
double temp_timer,search_timer;
clock_t start, end;
!
bst=new Bst();
avlt=new Avlt();
--- 176,180 ----
double temp_timer,search_timer;
clock_t start, end;
! GtkWidget *dialog=NULL;
bst=new Bst();
avlt=new Avlt();
***************
*** 185,200 ****
sleep(5);
Test_Init(base_tree_size,0); //avl
printf("\nInit Result:\nBST -> %lf, AVL -> %lf\n",temp_timer,getInitTimer());
if ((temp_timer-getInitTimer())>double(0)) printf("***************************\nAVL faster\n***************************\n");
if ((temp_timer-getInitTimer())<double(0)) printf("***************************\nBST faster\n***************************\n");
if ((temp_timer-getInitTimer())==double(0)) printf("***************************\nNo real differences found\n***************************\n");
Bst_Test(upperbound);
temp_timer=getChangeTimer();
sleep(5);
Avl_Test(upperbound);
if ((temp_timer-getChangeTimer())>double(0)) printf("***************************\nAVL faster\n***************************\n");
if ((temp_timer-getChangeTimer())<double(0)) printf("***************************\nBST faster\n***************************\n");
if ((temp_timer-getChangeTimer())==double(0)) printf("***************************\nNo real differences found\n***************************\n");
!
int max=bst->max()->getValue(); //caching!
--- 184,215 ----
sleep(5);
Test_Init(base_tree_size,0); //avl
+ #ifndef GUI
printf("\nInit Result:\nBST -> %lf, AVL -> %lf\n",temp_timer,getInitTimer());
if ((temp_timer-getInitTimer())>double(0)) printf("***************************\nAVL faster\n***************************\n");
if ((temp_timer-getInitTimer())<double(0)) printf("***************************\nBST faster\n***************************\n");
if ((temp_timer-getInitTimer())==double(0)) printf("***************************\nNo real differences found\n***************************\n");
+ #else
+ if ((temp_timer-getInitTimer())>double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Init Result:\nBST -> %lf, AVL -> %lf\n***************************\nAVL faster\n***************************\n",temp_timer,getInitTimer());
+ if ((temp_timer-getInitTimer())<double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Init Result:\nBST -> %lf, AVL -> %lf\n***************************\nBST faster\n***************************\n",temp_timer,getInitTimer());
+ if ((temp_timer-getInitTimer())==double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Init Result:\nBST -> %lf, AVL -> %lf\n***************************\nNo real differences found\n***************************\n",temp_timer,getInitTimer());
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ #endif
Bst_Test(upperbound);
temp_timer=getChangeTimer();
sleep(5);
Avl_Test(upperbound);
+ #ifndef GUI
+ printf("Random modification test\n");
if ((temp_timer-getChangeTimer())>double(0)) printf("***************************\nAVL faster\n***************************\n");
if ((temp_timer-getChangeTimer())<double(0)) printf("***************************\nBST faster\n***************************\n");
if ((temp_timer-getChangeTimer())==double(0)) printf("***************************\nNo real differences found\n***************************\n");
! #else
! if ((temp_timer-getChangeTimer())>double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Random modification test\n***************************\nAVL faster\n***************************\n");
! if ((temp_timer-getChangeTimer())<double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Random modification test\n***************************\nBST faster\n***************************\n");
! if ((temp_timer-getChangeTimer())==double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Random modification test\n***************************\nNo real differences found\n***************************\n");
! gtk_dialog_run (GTK_DIALOG (dialog));
! gtk_widget_destroy (dialog);
! #endif
int max=bst->max()->getValue(); //caching!
***************
*** 209,217 ****
end=clock();
temp_timer=((double) (end - start)) / CLOCKS_PER_SEC;
! printf("Bst search time of its max value (%d):%lf\nBst search time of its max value (%d):%lf\n",bst->max()->getValue(),search_timer,max,temp_timer);
if ((temp_timer-search_timer)<double(0)) printf("***************************\nAVL faster\n***************************\n");
if ((temp_timer-search_timer)>double(0)) printf("***************************\nBST faster\n***************************\n");
if ((temp_timer-search_timer)==double(0)) printf("***************************\nNo real differences found\n***************************\n");
!
}
--- 224,239 ----
end=clock();
temp_timer=((double) (end - start)) / CLOCKS_PER_SEC;
! #ifndef GUI
! printf("BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n",bst->max()->getValue(),search_timer,max,temp_timer);
if ((temp_timer-search_timer)<double(0)) printf("***************************\nAVL faster\n***************************\n");
if ((temp_timer-search_timer)>double(0)) printf("***************************\nBST faster\n***************************\n");
if ((temp_timer-search_timer)==double(0)) printf("***************************\nNo real differences found\n***************************\n");
! #else
! if ((temp_timer-search_timer)<double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n***************************\nAVL faster\n***************************\n",bst->max()->getValue(),search_timer,max,temp_timer);
! if ((temp_timer-search_timer)>double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n***************************\nBST faster\n***************************\n",bst->max()->getValue(),search_timer,max,temp_timer);
! if ((temp_timer-search_timer)==double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n***************************\nNo real differences found\n***************************\n",bst->max()->getValue(),search_timer,max,temp_timer);
! gtk_dialog_run (GTK_DIALOG (dialog));
! gtk_widget_destroy (dialog);
! #endif
}
Index: avl.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/avl.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** avl.cpp 7 Sep 2004 13:03:21 -0000 1.14
--- avl.cpp 7 Sep 2004 14:37:01 -0000 1.15
***************
*** 24,40 ****
using namespace std;
- void p(){
- Avlt* av=new Avlt();
-
-
- for (int i=0;i<1500;i++) {
-
- av->insert(i);
- }
-
-
- }
-
-
int choice=0;
int base_tree=20;
--- 24,27 ----
***************
*** 64,93 ****
void start() {
- //Test *prova;
- //prova= new Test();
- //Avlt* aux_avl=NULL;
- //Bst* aux_bst=NULL;
-
base_tree=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton1));
upperbound=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton2));
- printf("%d %d %d\n", choice,base_tree, upperbound );
- /*
if (choice==0) {
- printf("Processing AVL, wait\n");
prova = new Test(0,upperbound,base_tree);
aux_avl=prova->getAvlt();
! printf("Processing AVL2, wait\n");
! return;
}
if (choice==1) {
prova = new Test(1,upperbound,base_tree);
aux_bst=prova->getBst();
}
if (choice==2) {
! prova = new Test(2,upperbound,base_tree);
! }
! */
GtkWidget *scrolled_window;
GtkWidget *tree_view;
--- 51,76 ----
void start() {
base_tree=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton1));
upperbound=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton2));
if (choice==0) {
prova = new Test(0,upperbound,base_tree);
aux_avl=prova->getAvlt();
! gtk_widget_destroy(node_list);
! node_list = aux_avl->print_best_look();
}
+
if (choice==1) {
prova = new Test(1,upperbound,base_tree);
aux_bst=prova->getBst();
+ gtk_widget_destroy(node_list);
+ node_list = aux_bst->print_best_look();
}
+
if (choice==2) {
!
! prova = new Test(2,upperbound,base_tree);
!
GtkWidget *scrolled_window;
GtkWidget *tree_view;
***************
*** 113,132 ****
gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,NULL);
! gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, "Prova", -1);
//finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero.
cell = gtk_cell_renderer_text_new ();
! column = gtk_tree_view_column_new_with_attributes ("AVL Tree",cell,"text", 0, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (column));
gtk_widget_destroy(node_list);
node_list=scrolled_window;
! //if (choice==0) node_list = aux_avl->print_best_look();
! // if (choice==1) node_list = aux_bst->print_best_look();
!
! gtk_paned_add1 (GTK_PANED (vpaned1), node_list);
! gtk_widget_show (node_list);
! gtk_widget_show (vpaned1);
}
--- 96,114 ----
gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,NULL);
! gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, "Empty tree, comparation selected", -1);
//finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero.
cell = gtk_cell_renderer_text_new ();
! column = gtk_tree_view_column_new_with_attributes ("No Trees",cell,"text", 0, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (column));
gtk_widget_destroy(node_list);
node_list=scrolled_window;
+ }
! gtk_paned_add1 (GTK_PANED (vpaned1), node_list);
! gtk_widget_show (node_list);
! gtk_widget_show (vpaned1);
!
}
***************
*** 215,224 ****
GtkAdjustment *adj=NULL;
GtkWidget *label=NULL;
! //Test *a=new Test();
! //p();
gtk_init (&argc, &argv);
! p();
! //Test *a=new Test();
! char* fullname="AVL Tree Visualization";
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
--- 197,204 ----
GtkAdjustment *adj=NULL;
GtkWidget *label=NULL;
!
gtk_init (&argc, &argv);
!
! char* fullname="AVL-BST Tree Visualization";
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
***************
*** 332,338 ****
gtk_main ();
-
#endif
! return EXIT_SUCCESS;
}
--- 312,317 ----
gtk_main ();
#endif
! return EXIT_SUCCESS;
}
|