Fossil SCM

Add the /hash-collisions webpage.

drh 2015-02-11 11:51 trunk
Commit 43e2aff58ae2bc0c59742038fd7eeefcb1d22f44
1 file changed +52
+52
--- src/name.c
+++ src/name.c
@@ -1058,5 +1058,57 @@
10581058
*/
10591059
void test_phatoms_cmd(void){
10601060
db_find_and_open_repository(0,0);
10611061
describe_artifacts_to_stdout("IN (SELECT rid FROM blob WHERE size<0)", 0);
10621062
}
1063
+
1064
+/*
1065
+** WEBPAGE: hash-collisions
1066
+**
1067
+** Show the number of hash collisions for hash prefixes of various lengths.
1068
+*/
1069
+void hash_collisions_webpage(void){
1070
+ int i;
1071
+ int nHash = 0;
1072
+ Stmt q;
1073
+ char zPrev[UUID_SIZE+1];
1074
+ struct {
1075
+ int cnt;
1076
+ char z[UUID_SIZE+1];
1077
+ } aCollide[UUID_SIZE+1];
1078
+ login_check_credentials();
1079
+ if( !g.perm.Read ){ login_needed(); return; }
1080
+ memset(aCollide, 0, sizeof(aCollide));
1081
+ memset(zPrev, 0, sizeof(zPrev));
1082
+ db_prepare(&q,
1083
+ "SELECT tkt_uuid FROM ticket\n"
1084
+ "UNION ALL\n"
1085
+ "SELECT substr(tagname,7) FROM tag WHERE tagname GLOB 'event-*'\n"
1086
+ "UNION ALL\n"
1087
+ "SELECT uuid FROM blob\n"
1088
+ "ORDER BY 1"
1089
+ );
1090
+ while( db_step(&q)==SQLITE_ROW ){
1091
+ const char *zUuid = db_column_text(&q,0);
1092
+ int n = db_column_bytes(&q,0);
1093
+ int i;
1094
+ nHash++;
1095
+ for(i=0; zPrev[i] && zPrev[i]==zUuid[i]; i++){}
1096
+ memcpy(zPrev, zUuid, n+1);
1097
+ if( i>0 && i<=UUID_SIZE ){
1098
+ aCollide[i].cnt++;
1099
+ if( aCollide[i].z[0]==0 ) memcpy(aCollide[i].z, zPrev, n+1);
1100
+ }
1101
+ }
1102
+ db_finalize(&q);
1103
+ style_header("Hash Prefix Collisions");
1104
+ @ <table border=1><thead>
1105
+ @ <tr><th>Length<th>Instances<th>First Instance</tr>
1106
+ @ </thead><tbody>
1107
+ for(i=1; i<UUID_SIZE; i++){
1108
+ if( aCollide[i].cnt==0 ) continue;
1109
+ @ <tr><td>%d(i)<td>%d(aCollide[i].cnt)<td>%h(aCollide[i].z)</tr>
1110
+ }
1111
+ @ </tbody></table>
1112
+ @ <p>Total number of hashes: %d(nHash)</p>
1113
+ style_footer();
1114
+}
10631115
--- src/name.c
+++ src/name.c
@@ -1058,5 +1058,57 @@
1058 */
1059 void test_phatoms_cmd(void){
1060 db_find_and_open_repository(0,0);
1061 describe_artifacts_to_stdout("IN (SELECT rid FROM blob WHERE size<0)", 0);
1062 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1063
--- src/name.c
+++ src/name.c
@@ -1058,5 +1058,57 @@
1058 */
1059 void test_phatoms_cmd(void){
1060 db_find_and_open_repository(0,0);
1061 describe_artifacts_to_stdout("IN (SELECT rid FROM blob WHERE size<0)", 0);
1062 }
1063
1064 /*
1065 ** WEBPAGE: hash-collisions
1066 **
1067 ** Show the number of hash collisions for hash prefixes of various lengths.
1068 */
1069 void hash_collisions_webpage(void){
1070 int i;
1071 int nHash = 0;
1072 Stmt q;
1073 char zPrev[UUID_SIZE+1];
1074 struct {
1075 int cnt;
1076 char z[UUID_SIZE+1];
1077 } aCollide[UUID_SIZE+1];
1078 login_check_credentials();
1079 if( !g.perm.Read ){ login_needed(); return; }
1080 memset(aCollide, 0, sizeof(aCollide));
1081 memset(zPrev, 0, sizeof(zPrev));
1082 db_prepare(&q,
1083 "SELECT tkt_uuid FROM ticket\n"
1084 "UNION ALL\n"
1085 "SELECT substr(tagname,7) FROM tag WHERE tagname GLOB 'event-*'\n"
1086 "UNION ALL\n"
1087 "SELECT uuid FROM blob\n"
1088 "ORDER BY 1"
1089 );
1090 while( db_step(&q)==SQLITE_ROW ){
1091 const char *zUuid = db_column_text(&q,0);
1092 int n = db_column_bytes(&q,0);
1093 int i;
1094 nHash++;
1095 for(i=0; zPrev[i] && zPrev[i]==zUuid[i]; i++){}
1096 memcpy(zPrev, zUuid, n+1);
1097 if( i>0 && i<=UUID_SIZE ){
1098 aCollide[i].cnt++;
1099 if( aCollide[i].z[0]==0 ) memcpy(aCollide[i].z, zPrev, n+1);
1100 }
1101 }
1102 db_finalize(&q);
1103 style_header("Hash Prefix Collisions");
1104 @ <table border=1><thead>
1105 @ <tr><th>Length<th>Instances<th>First Instance</tr>
1106 @ </thead><tbody>
1107 for(i=1; i<UUID_SIZE; i++){
1108 if( aCollide[i].cnt==0 ) continue;
1109 @ <tr><td>%d(i)<td>%d(aCollide[i].cnt)<td>%h(aCollide[i].z)</tr>
1110 }
1111 @ </tbody></table>
1112 @ <p>Total number of hashes: %d(nHash)</p>
1113 style_footer();
1114 }
1115

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button