00001 00011 #include <stdlib.h> 00012 #include <stdio.h> 00013 00014 #include "odb.h" 00015 #include "op_types.h" 00016 00018 struct odb_hash_stat_t { 00019 odb_node_nr_t node_nr; 00020 odb_node_nr_t used_node_nr; 00021 count_type total_count; 00022 odb_index_t hash_table_size; 00023 odb_node_nr_t max_list_length; 00024 double average_list_length; 00025 /* do we need variance ? */ 00026 }; 00027 00028 odb_hash_stat_t * odb_hash_stat(odb_t const * odb) 00029 { 00030 size_t max_length = 0; 00031 double total_length = 0.0; 00032 size_t nr_non_empty_list = 0; 00033 size_t pos; 00034 odb_data_t * data = odb->data; 00035 00036 odb_hash_stat_t * result = calloc(1, sizeof(odb_hash_stat_t)); 00037 if (!result) { 00038 fprintf(stderr, "not enough memory\n"); 00039 exit(EXIT_FAILURE); 00040 } 00041 00042 result->node_nr = data->descr->size; 00043 result->used_node_nr = data->descr->current_size; 00044 result->hash_table_size = data->descr->size * BUCKET_FACTOR; 00045 00046 /* FIXME: I'm dubious if this do right statistics for hash table 00047 * efficiency check */ 00048 00049 for (pos = 0 ; pos < result->hash_table_size ; ++pos) { 00050 size_t cur_length = 0; 00051 size_t index = data->hash_base[pos]; 00052 while (index) { 00053 result->total_count += data->node_base[index].value; 00054 index = data->node_base[index].next; 00055 ++cur_length; 00056 } 00057 00058 if (cur_length > max_length) 00059 max_length = cur_length; 00060 00061 if (cur_length) { 00062 total_length += cur_length; 00063 ++nr_non_empty_list; 00064 } 00065 } 00066 00067 result->max_list_length = max_length; 00068 result->average_list_length = total_length / nr_non_empty_list; 00069 00070 return result; 00071 } 00072 00073 00074 void odb_hash_display_stat(odb_hash_stat_t const * stat) 00075 { 00076 printf("total node number: %d\n", stat->node_nr); 00077 printf("total used node: %d\n", stat->used_node_nr); 00078 printf("total count: %llu\n", stat->total_count); 00079 printf("hash table size: %d\n", stat->hash_table_size); 00080 printf("greater list length: %d\n", stat->max_list_length); 00081 printf("average non empty list length: %2.4f\n", stat->average_list_length); 00082 } 00083 00084 00085 void odb_hash_free_stat(odb_hash_stat_t * stat) 00086 { 00087 free(stat); 00088 }