Fossil SCM

Minor tweaks to the hash color test page.

drh 2023-09-28 14:08 trunk
Commit 19799565b7a8c9ff0a10a6e927fe0dc8165cf0c9727efd865c2defe9440aa037
2 files changed +14 -5 +1 -2
+14 -5
--- src/color.c
+++ src/color.c
@@ -20,19 +20,30 @@
2020
**
2121
*/
2222
#include "config.h"
2323
#include <string.h>
2424
#include "color.h"
25
+
26
+/*
27
+** Compute a hash on a branch or user name
28
+*/
29
+static unsigned int hash_of_name(const char *z){
30
+ unsigned int h = 0;
31
+ int i;
32
+ for(i=0; z[i]; i++ ){
33
+ h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
34
+ }
35
+ return h;
36
+}
2537
2638
/*
2739
** Hash a string and use the hash to determine a background color.
2840
**
2941
** This value returned is in static space and is overwritten with
3042
** each subsequent call.
3143
*/
3244
char *hash_color(const char *z){
33
- int i; /* Loop counter */
3445
unsigned int h = 0; /* Hash on the branch name */
3546
int r, g, b; /* Values for red, green, and blue */
3647
int h1, h2, h3, h4; /* Elements of the hash value */
3748
int mx, mn; /* Components of HSV */
3849
static char zColor[10]; /* The resulting color */
@@ -45,13 +56,11 @@
4556
}else{
4657
ix[0] = 0xf8;
4758
ix[1] = 0x20;
4859
}
4960
}
50
- for(i=0; z[i]; i++ ){
51
- h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
52
- }
61
+ h = hash_of_name(z);
5362
h1 = h % 6; h /= 6;
5463
h3 = h % 10; h /= 10;
5564
h4 = h % 10; h /= 10;
5665
mx = ix[0] - h3;
5766
mn = mx - h4 - ix[1];
@@ -154,11 +163,11 @@
154163
for(i=cnt=0; i<10; i++){
155164
sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i);
156165
zBr = P(zNm);
157166
if( zBr && zBr[0] ){
158167
@ <p style='border:1px solid;background-color:%s(hash_color(zBr));'>
159
- @ %h(zBr) - %s(hash_color(zBr)) -
168
+ @ %h(zBr) - hash 0x%x(hash_of_name(zBr)) - color %s(hash_color(zBr)) -
160169
@ Omnes nos quasi oves erravimus unusquisque in viam
161170
@ suam declinavit.</p>
162171
cnt++;
163172
}
164173
}
165174
--- src/color.c
+++ src/color.c
@@ -20,19 +20,30 @@
20 **
21 */
22 #include "config.h"
23 #include <string.h>
24 #include "color.h"
 
 
 
 
 
 
 
 
 
 
 
 
25
26 /*
27 ** Hash a string and use the hash to determine a background color.
28 **
29 ** This value returned is in static space and is overwritten with
30 ** each subsequent call.
31 */
32 char *hash_color(const char *z){
33 int i; /* Loop counter */
34 unsigned int h = 0; /* Hash on the branch name */
35 int r, g, b; /* Values for red, green, and blue */
36 int h1, h2, h3, h4; /* Elements of the hash value */
37 int mx, mn; /* Components of HSV */
38 static char zColor[10]; /* The resulting color */
@@ -45,13 +56,11 @@
45 }else{
46 ix[0] = 0xf8;
47 ix[1] = 0x20;
48 }
49 }
50 for(i=0; z[i]; i++ ){
51 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
52 }
53 h1 = h % 6; h /= 6;
54 h3 = h % 10; h /= 10;
55 h4 = h % 10; h /= 10;
56 mx = ix[0] - h3;
57 mn = mx - h4 - ix[1];
@@ -154,11 +163,11 @@
154 for(i=cnt=0; i<10; i++){
155 sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i);
156 zBr = P(zNm);
157 if( zBr && zBr[0] ){
158 @ <p style='border:1px solid;background-color:%s(hash_color(zBr));'>
159 @ %h(zBr) - %s(hash_color(zBr)) -
160 @ Omnes nos quasi oves erravimus unusquisque in viam
161 @ suam declinavit.</p>
162 cnt++;
163 }
164 }
165
--- src/color.c
+++ src/color.c
@@ -20,19 +20,30 @@
20 **
21 */
22 #include "config.h"
23 #include <string.h>
24 #include "color.h"
25
26 /*
27 ** Compute a hash on a branch or user name
28 */
29 static unsigned int hash_of_name(const char *z){
30 unsigned int h = 0;
31 int i;
32 for(i=0; z[i]; i++ ){
33 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
34 }
35 return h;
36 }
37
38 /*
39 ** Hash a string and use the hash to determine a background color.
40 **
41 ** This value returned is in static space and is overwritten with
42 ** each subsequent call.
43 */
44 char *hash_color(const char *z){
 
45 unsigned int h = 0; /* Hash on the branch name */
46 int r, g, b; /* Values for red, green, and blue */
47 int h1, h2, h3, h4; /* Elements of the hash value */
48 int mx, mn; /* Components of HSV */
49 static char zColor[10]; /* The resulting color */
@@ -45,13 +56,11 @@
56 }else{
57 ix[0] = 0xf8;
58 ix[1] = 0x20;
59 }
60 }
61 h = hash_of_name(z);
 
 
62 h1 = h % 6; h /= 6;
63 h3 = h % 10; h /= 10;
64 h4 = h % 10; h /= 10;
65 mx = ix[0] - h3;
66 mn = mx - h4 - ix[1];
@@ -154,11 +163,11 @@
163 for(i=cnt=0; i<10; i++){
164 sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i);
165 zBr = P(zNm);
166 if( zBr && zBr[0] ){
167 @ <p style='border:1px solid;background-color:%s(hash_color(zBr));'>
168 @ %h(zBr) - hash 0x%x(hash_of_name(zBr)) - color %s(hash_color(zBr)) -
169 @ Omnes nos quasi oves erravimus unusquisque in viam
170 @ suam declinavit.</p>
171 cnt++;
172 }
173 }
174
+1 -2
--- src/sitemap.c
+++ src/sitemap.c
@@ -327,12 +327,11 @@
327327
if( g.perm.Read ){
328328
@ <li>%z(href("%R/test-rename-list"))List of file renames</a></li>
329329
}
330330
@ <li>%z(href("%R/test-builtin-files"))List of built-in files</a></li>
331331
@ <li>%z(href("%R/mimetype_list"))List of MIME types</a></li>
332
- @ <li>%z(href("%R/hash-color-test"))Page to experiment with the automatic
333
- @ colors assigned to branch names</a>
332
+ @ <li>%z(href("%R/hash-color-test"))Hash color test</a>
334333
if( g.perm.Admin ){
335334
@ <li>%z(href("%R/test-backlinks"))List of backlinks</a></li>
336335
@ <li>%z(href("%R/test-backlink-timeline"))Backlink timeline</a></li>
337336
@ <li>%z(href("%R/phantoms"))List of phantom artifacts</a></li>
338337
@ <li>%z(href("%R/test-warning"))Error Log test page</a></li>
339338
--- src/sitemap.c
+++ src/sitemap.c
@@ -327,12 +327,11 @@
327 if( g.perm.Read ){
328 @ <li>%z(href("%R/test-rename-list"))List of file renames</a></li>
329 }
330 @ <li>%z(href("%R/test-builtin-files"))List of built-in files</a></li>
331 @ <li>%z(href("%R/mimetype_list"))List of MIME types</a></li>
332 @ <li>%z(href("%R/hash-color-test"))Page to experiment with the automatic
333 @ colors assigned to branch names</a>
334 if( g.perm.Admin ){
335 @ <li>%z(href("%R/test-backlinks"))List of backlinks</a></li>
336 @ <li>%z(href("%R/test-backlink-timeline"))Backlink timeline</a></li>
337 @ <li>%z(href("%R/phantoms"))List of phantom artifacts</a></li>
338 @ <li>%z(href("%R/test-warning"))Error Log test page</a></li>
339
--- src/sitemap.c
+++ src/sitemap.c
@@ -327,12 +327,11 @@
327 if( g.perm.Read ){
328 @ <li>%z(href("%R/test-rename-list"))List of file renames</a></li>
329 }
330 @ <li>%z(href("%R/test-builtin-files"))List of built-in files</a></li>
331 @ <li>%z(href("%R/mimetype_list"))List of MIME types</a></li>
332 @ <li>%z(href("%R/hash-color-test"))Hash color test</a>
 
333 if( g.perm.Admin ){
334 @ <li>%z(href("%R/test-backlinks"))List of backlinks</a></li>
335 @ <li>%z(href("%R/test-backlink-timeline"))Backlink timeline</a></li>
336 @ <li>%z(href("%R/phantoms"))List of phantom artifacts</a></li>
337 @ <li>%z(href("%R/test-warning"))Error Log test page</a></li>
338

Keyboard Shortcuts

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