7 #define BLOBSIZE (1<<(BLOBBITS-1))
9 #define WINDOWSIZE (1<<(WINDOWBITS-1))
12 // FIXME: replace this with a not-stupid rolling checksum algorithm,
13 // such as the one used in rsync (Adler32?)
14 static uint32_t stupidsum_add(uint32_t old, uint8_t drop, uint8_t add)
16 return ((old<<1) | (old>>31)) ^ drop ^ add;
20 static void test_sums()
25 for (i = 0; i < WINDOWSIZE; i++)
26 sum = stupidsum_add(sum, 0, i%256);
29 for (i = 0; i < WINDOWSIZE*2; i++)
30 sum = stupidsum_add(sum, i%256, i%256);
33 for (i = 0; i < WINDOWSIZE; i++)
34 sum = stupidsum_add(sum, i%256, 0);
41 assert(WINDOWSIZE >= 32);
42 assert(BLOBSIZE >= 32);
45 uint8_t buf[WINDOWSIZE];
47 int i = 0, count = 0, last_count = 0, c;
50 memset(buf, 0, sizeof(buf));
52 // FIXME: read more than one byte at a time. This is absurdly slow.
53 while ((c = fgetc(stdin)) != EOF)
55 sum = stupidsum_add(sum, buf[i], c);
61 fprintf(stderr, "[%5X] %08X '", i, sum);
62 for (j = i+1; j < i+1+WINDOWSIZE; j++)
64 int d = buf[j % WINDOWSIZE];
65 fputc((d >= 32 && d <= 126) ? d : '.', stderr);
67 fprintf(stderr, "'\n");
70 i = (i + 1) % WINDOWSIZE;
74 pipe = popen("git hash-object --stdin -w", "w");
76 // FIXME: write more than one byte at a time. This is absurdly
80 if ((sum & (BLOBSIZE-1)) == ((~0) & (BLOBSIZE-1)))
82 fprintf(stderr, "SPLIT @ %-8d size=%-8d (%d/%d)\n",
83 count, count - last_count, BLOBSIZE, WINDOWSIZE);
86 memset(buf, 0, sizeof(buf));