Fossil SCM

On the /hash-collisions page, list the longer collisions with links to /whatid.

drh 2015-02-11 12:36 trunk
Commit 3234cf1efe96ad6d62249f1d7ce02a22d16728a7
1 file changed +20 -2
+20 -2
--- src/name.c
+++ src/name.c
@@ -1065,21 +1065,23 @@
10651065
** WEBPAGE: hash-collisions
10661066
**
10671067
** Show the number of hash collisions for hash prefixes of various lengths.
10681068
*/
10691069
void hash_collisions_webpage(void){
1070
- int i;
1070
+ int i, kk;
10711071
int nHash = 0;
10721072
Stmt q;
10731073
char zPrev[UUID_SIZE+1];
10741074
struct {
10751075
int cnt;
1076
+ Blob ex;
10761077
char z[UUID_SIZE+1];
10771078
} aCollide[UUID_SIZE+1];
10781079
login_check_credentials();
10791080
if( !g.perm.Read ){ login_needed(); return; }
10801081
memset(aCollide, 0, sizeof(aCollide));
1082
+ for(i=0; i<ArraySize(aCollide); i++) blob_init(&aCollide[i].ex,0,0);
10811083
memset(zPrev, 0, sizeof(zPrev));
10821084
db_prepare(&q,
10831085
"SELECT tkt_uuid FROM ticket\n"
10841086
"UNION ALL\n"
10851087
"SELECT substr(tagname,7) FROM tag WHERE tagname GLOB 'event-*'\n"
@@ -1094,21 +1096,37 @@
10941096
nHash++;
10951097
for(i=0; zPrev[i] && zPrev[i]==zUuid[i]; i++){}
10961098
if( i>0 && i<=UUID_SIZE ){
10971099
aCollide[i].cnt++;
10981100
if( aCollide[i].z[0]==0 ) memcpy(aCollide[i].z, zPrev, n+1);
1101
+ if( aCollide[i].cnt<25 ){
1102
+ blob_appendf(&aCollide[i].ex, " %z%.*s</a>",
1103
+ href("%R/whatis/%.*s", i, zPrev), i, zPrev);
1104
+ }
10991105
}
11001106
memcpy(zPrev, zUuid, n+1);
11011107
}
11021108
db_finalize(&q);
11031109
style_header("Hash Prefix Collisions");
11041110
@ <table border=1><thead>
11051111
@ <tr><th>Length<th>Instances<th>First Instance</tr>
11061112
@ </thead><tbody>
1107
- for(i=1; i<UUID_SIZE; i++){
1113
+ for(i=1; i<=UUID_SIZE; i++){
11081114
if( aCollide[i].cnt==0 ) continue;
11091115
@ <tr><td>%d(i)<td>%d(aCollide[i].cnt)<td>%h(aCollide[i].z)</tr>
11101116
}
11111117
@ </tbody></table>
11121118
@ <p>Total number of hashes: %d(nHash)</p>
1119
+ kk = 0;
1120
+ for(i=UUID_SIZE; i>=0; i--){
1121
+ if( aCollide[i].cnt==0 ) continue;
1122
+ if( aCollide[i].cnt>200 ) break;
1123
+ kk += aCollide[i].cnt;
1124
+ if( aCollide[i].cnt<25 ){
1125
+ @ <p>Collisions of length %d(i):
1126
+ }else{
1127
+ @ <p>First 25 collisions of length %d(i):
1128
+ }
1129
+ @ %s(blob_str(&aCollide[i].ex))</p>
1130
+ }
11131131
style_footer();
11141132
}
11151133
--- src/name.c
+++ src/name.c
@@ -1065,21 +1065,23 @@
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"
@@ -1094,21 +1096,37 @@
1094 nHash++;
1095 for(i=0; zPrev[i] && zPrev[i]==zUuid[i]; i++){}
1096 if( i>0 && i<=UUID_SIZE ){
1097 aCollide[i].cnt++;
1098 if( aCollide[i].z[0]==0 ) memcpy(aCollide[i].z, zPrev, n+1);
 
 
 
 
1099 }
1100 memcpy(zPrev, zUuid, n+1);
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
--- src/name.c
+++ src/name.c
@@ -1065,21 +1065,23 @@
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, kk;
1071 int nHash = 0;
1072 Stmt q;
1073 char zPrev[UUID_SIZE+1];
1074 struct {
1075 int cnt;
1076 Blob ex;
1077 char z[UUID_SIZE+1];
1078 } aCollide[UUID_SIZE+1];
1079 login_check_credentials();
1080 if( !g.perm.Read ){ login_needed(); return; }
1081 memset(aCollide, 0, sizeof(aCollide));
1082 for(i=0; i<ArraySize(aCollide); i++) blob_init(&aCollide[i].ex,0,0);
1083 memset(zPrev, 0, sizeof(zPrev));
1084 db_prepare(&q,
1085 "SELECT tkt_uuid FROM ticket\n"
1086 "UNION ALL\n"
1087 "SELECT substr(tagname,7) FROM tag WHERE tagname GLOB 'event-*'\n"
@@ -1094,21 +1096,37 @@
1096 nHash++;
1097 for(i=0; zPrev[i] && zPrev[i]==zUuid[i]; i++){}
1098 if( i>0 && i<=UUID_SIZE ){
1099 aCollide[i].cnt++;
1100 if( aCollide[i].z[0]==0 ) memcpy(aCollide[i].z, zPrev, n+1);
1101 if( aCollide[i].cnt<25 ){
1102 blob_appendf(&aCollide[i].ex, " %z%.*s</a>",
1103 href("%R/whatis/%.*s", i, zPrev), i, zPrev);
1104 }
1105 }
1106 memcpy(zPrev, zUuid, n+1);
1107 }
1108 db_finalize(&q);
1109 style_header("Hash Prefix Collisions");
1110 @ <table border=1><thead>
1111 @ <tr><th>Length<th>Instances<th>First Instance</tr>
1112 @ </thead><tbody>
1113 for(i=1; i<=UUID_SIZE; i++){
1114 if( aCollide[i].cnt==0 ) continue;
1115 @ <tr><td>%d(i)<td>%d(aCollide[i].cnt)<td>%h(aCollide[i].z)</tr>
1116 }
1117 @ </tbody></table>
1118 @ <p>Total number of hashes: %d(nHash)</p>
1119 kk = 0;
1120 for(i=UUID_SIZE; i>=0; i--){
1121 if( aCollide[i].cnt==0 ) continue;
1122 if( aCollide[i].cnt>200 ) break;
1123 kk += aCollide[i].cnt;
1124 if( aCollide[i].cnt<25 ){
1125 @ <p>Collisions of length %d(i):
1126 }else{
1127 @ <p>First 25 collisions of length %d(i):
1128 }
1129 @ %s(blob_str(&aCollide[i].ex))</p>
1130 }
1131 style_footer();
1132 }
1133

Keyboard Shortcuts

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