git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Distribution of longest common hash prefixes

From
PEPeter Eriksen <s022018@student.dtu.dk>
Date
Apr 2, 2007, 15:28 UTC
Message-ID
<20070402152835.GB13293@bohr.gbar.dtu.dk>
In-Reply-To
<20070402145857.GA13293@bohr.gbar.dtu.dk>

On Mon, Apr 02, 2007 at 04:58:57PM +0200, Peter Eriksen wrote: ...

> Why does it look so sparse and strange?

... and here is the nonbroken version, which is neither sparse nor strange. Thanks to chris on #git for the nice programming lesson. More correct output and program bellow.

Peter
 0:  1
 1:  2
 2:  4
 3:  8
 4: 16
 5: 32
 6: 64
 7: 128
 8: 256
 9: 512
10: 1024
11: 2048
12: 4096
13: 8192
14: 16384
15: 32685
16: 60921
17: 86511
18: 84426
19: 61518
20: 37450
21: 20728
22: 11035
23: 5562
24: 2812
25: 1467
26: 738
27: 355
28: 191
29: 83
30: 49
31: 27
32: 10
33:  3
34:  1
35:  2
36:  0
37:  1
38:  0
39:  0
40:  0
41:  0
42:  0
43:  0
44:  0
45:  0
46:  0
47:  0
48:  0
49:  0
50:  0
51:  0
52:  0
53:  0
54:  0
55:  0
56:  0
57:  0
58:  0
59:  0
60:  0
61:  0
62:  0
63:  0

#include <stdio.h> #include <string.h>

int h2d(char c)
{
	if ('a' <= c && c <= 'f')
		return c-'a'+10;
	else
		return c-'0';
}
int lcprefix(char *a, char *b)
{
	int i = 0;
	int j = 4;
	while (a[i] == b[i])
		i++;
	while ((h2d(a[i])<<j & 128) == (h2d(b[i])<<j & 128))
		j++;
	
	return i*4 + j - 4;
}
int max(int a, int b)
{
	return a < b ? b : a;
}
int main(int argc, char **argv)
{
	FILE *fp;
	char old[41];
	char cur[41];
	int lcp = 0;
	int table[64];
	int i;
	int tmp;
	memset(table, 0, 64*sizeof(int));
	memset(old, '0', 40);
	old[40] = '\0';
	fp = fopen(argv[1], "r");
	fscanf(fp, "%s\n", cur);
	tmp = lcprefix(old, cur);
	table[tmp]++;
	lcp = max(lcp, tmp);
	while (fscanf(fp, "%s\n", cur) != EOF) {
		tmp = lcprefix(old, cur);
		table[tmp]++;
		lcp = max(lcp, tmp);
		if (lcp < tmp) {
			printf("%s\n%s\n", old, cur);
			lcp = lcprefix(old, cur);
			printf("lcprefix = %d\n", lcp);
		}
		memcpy(old, cur, 40);
	}
	for(i = 0; i < 64; i++) {
		printf("%2d: %2d\n", i, table[i]);
	}
	
	return 0;
}
Previous: James Cloos
Message 20 of 20 in “Distribution of longest common hash prefixes”
  1. Peter EriksenApr 2, 2007
  2. Linus TorvaldsApr 2, 2007
  3. Randal L. SchwartzApr 2, 2007
  4. Linus TorvaldsApr 2, 2007
  5. Randal L. SchwartzApr 2, 2007
  6. Randal L. SchwartzApr 2, 2007
  7. James CloosApr 3, 2007
  8. Randal L. SchwartzApr 3, 2007
  9. Shawn O. PearceApr 3, 2007
  10. Linus TorvaldsApr 3, 2007
  11. Junio C HamanoApr 3, 2007
  12. Linus TorvaldsApr 3, 2007
  13. Nicolas PitreApr 3, 2007
  14. Junio C HamanoApr 3, 2007
  15. Nicolas PitreApr 3, 2007
  16. Olivier GalibertApr 3, 2007
  17. Linus TorvaldsApr 3, 2007
  18. James CloosApr 4, 2007
  19. James CloosApr 2, 2007
  20. Peter EriksenApr 2, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.