2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
3 * See COPYING file for license information
9 /* * * * MinGW search.h does not define tsearch * * * */
10 /* You can find an implementation at
11 http://sourceware.org/cgi-bin/cvsweb.cgi/src/winsup/mingw/mingwex/?cvsroot=src
14 http://www.cygwin.com/ml/cygwin-cvs/2007-q2/msg00050.html
17 http://www.google.dk/search?q=tsearch+search.h
19 Interface description:
20 http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/share/man/info/en_US/a_doc_lib/libs/basetrf2/tsearch.htm
21 http://www.cptec.inpe.br/sx4/sx4man2/g1ab02e/tsearch.3c.html
22 http://www.opengroup.org/onlinepubs/000095399/functions/tsearch.html
24 #include <tsearch/search.h>
28 #include <cbtcommon/hash.h>
30 #include "cvsps_types.h"
33 static unsigned int num_patch_sets
= 0;
34 static unsigned int num_ps_member
= 0, max_ps_member_in_ps
= 0;
35 static unsigned int num_authors
= 0, max_author_len
= 0, total_author_len
= 0;
36 static unsigned int max_descr_len
= 0, total_descr_len
= 0;
37 struct hash_table
*author_hash
;
39 static void count_hash(struct hash_table
*hash
, unsigned int *total
,
40 unsigned int *max_val
)
43 struct hash_entry
*fh
;
45 reset_hash_iterator(hash
);
46 while ((fh
= next_hash_entry(hash
)))
50 *max_val
= MAX(*max_val
, counter
);
53 static void stat_ps_tree_node(const void * nodep
, const VISIT which
, const int depth
)
57 struct list_head
* next
;
61 /* Make sure we have it if we do statistics */
63 author_hash
= create_hash_table(1023);
69 ps
= *(PatchSet
**)nodep
;
74 /* Author statistics */
75 if (put_hash_object_ex(author_hash
, ps
->author
, ps
->author
, HT_NO_KEYCOPY
, NULL
, &old
) >= 0 && !old
)
77 int len
= strlen(ps
->author
);
79 max_author_len
= MAX(max_author_len
, len
);
80 total_author_len
+= len
;
83 /* Log message statistics */
84 desc_len
= strlen(ps
->descr
);
85 max_descr_len
= MAX(max_descr_len
, desc_len
);
86 total_descr_len
+= desc_len
;
88 /* PatchSet member statistics */
90 next
= ps
->members
.next
;
91 while (next
!= &ps
->members
)
97 num_ps_member
+= counter
;
98 max_ps_member_in_ps
= MAX(max_ps_member_in_ps
, counter
);
106 void print_statistics(void * ps_tree
)
108 /* Statistics data */
109 unsigned int num_files
= 0, max_file_len
= 0, total_file_len
= 0;
110 unsigned int total_revisions
= 0, max_revisions_for_file
= 0;
111 unsigned int total_branches
= 0, max_branches_for_file
= 0;
112 unsigned int total_branches_sym
= 0, max_branches_sym_for_file
= 0;
115 struct hash_entry
*he
;
117 printf("Statistics:\n");
120 /* Gather file statistics */
121 reset_hash_iterator(file_hash
);
122 while ((he
=next_hash_entry(file_hash
)))
124 int len
= strlen(he
->he_key
);
125 CvsFile
*file
= (CvsFile
*)he
->he_obj
;
128 max_file_len
= MAX(max_file_len
, len
);
129 total_file_len
+= len
;
131 count_hash(file
->revisions
, &total_revisions
, &max_revisions_for_file
);
132 count_hash(file
->branches
, &total_branches
, &max_branches_for_file
);
133 count_hash(file
->branches_sym
, &total_branches_sym
,
134 &max_branches_sym_for_file
);
137 /* Print file statistics */
138 printf("Num files: %d\nMax filename len: %d, Average filename len: %.2f\n",
139 num_files
, max_file_len
, (float)total_file_len
/num_files
);
141 printf("Max revisions for file: %d, Average revisions for file: %.2f\n",
142 max_revisions_for_file
, (float)total_revisions
/num_files
);
143 printf("Max branches for file: %d, Average branches for file: %.2f\n",
144 max_branches_for_file
, (float)total_branches
/num_files
);
145 printf("Max branches_sym for file: %d, Average branches_sym for file: %.2f\n",
146 max_branches_sym_for_file
, (float)total_branches_sym
/num_files
);
148 /* Gather patchset statistics */
149 twalk(ps_tree
, stat_ps_tree_node
);
151 /* Print patchset statistics */
152 printf("Num patchsets: %d\n", num_patch_sets
);
153 printf("Max PS members in PS: %d\nAverage PS members in PS: %.2f\n",
154 max_ps_member_in_ps
, (float)num_ps_member
/num_patch_sets
);
155 printf("Num authors: %d, Max author len: %d, Avg. author len: %.2f\n",
156 num_authors
, max_author_len
, (float)total_author_len
/num_authors
);
157 printf("Max desc len: %d, Avg. desc len: %.2f\n",
158 max_descr_len
, (float)total_descr_len
/num_patch_sets
);