hsplit
hjoin
+hashsplit
+hashjoin
*.o
*~
tags[12]
+out[12]
CFLAGS=-Wall -g -Werror
-all: hsplit
+default: all
-hsplit: hsplit.o
+all: hashsplit hashjoin
-hjoin: hjoin.sh
+hashsplit: hashsplit.o
-test: hsplit hjoin
- ./hsplit <testfile1 >tags1
- ./hsplit <testfile2 >tags2
- diff -u -U50 tags1 tags2 || true
+hashjoin: hashjoin.sh
+
+test: hashsplit hashjoin
+ ./hashsplit <testfile1 >tags1
+ ./hashsplit <testfile2 >tags2
+ diff -u tags1 tags2 || true
wc -c testfile1 testfile2
wc -l tags1 tags2
- ./hjoin <tags1 >out1
- ./hjoin <tags2 >out2
+ ./hashjoin <tags1 >out1
+ ./hashjoin <tags2 >out2
diff -u testfile1 out1
diff -u testfile2 out2
gcc -c -o $@ $^ $(CPPFLAGS) $(CFLAGS)
clean:
- rm -f *.o *~ hsplit hjoin
+ rm -f *.o *~ hashsplit hashjoin hsplit hjoin \
+ out[12] tags[12] .*~
--- /dev/null
+#!/bin/sh
+while read x junk; do
+ git cat-file -p "$x"
+done
--- /dev/null
+#include <stdio.h>
+#include <stdint.h>
+#include <assert.h>
+#include <memory.h>
+
+#define BLOBBITS (14)
+#define BLOBSIZE (1<<(BLOBBITS-1))
+#define WINDOWBITS (7)
+#define WINDOWSIZE (1<<(WINDOWBITS-1))
+
+
+static uint32_t rol(uint32_t v, unsigned bits)
+{
+ bits = bits % 32;
+ return (v << bits) | (v >> (32-bits));
+}
+
+
+static uint32_t stupidsum_add(uint32_t old, uint8_t drop, uint8_t add)
+{
+ return ((old<<1) | (old>>31)) ^ drop ^ add;
+}
+
+
+static void test_sums()
+{
+ uint32_t sum = 0;
+ int i;
+
+ for (i = 0; i < WINDOWSIZE; i++)
+ sum = stupidsum_add(sum, 0, i%256);
+ uint32_t sum1 = sum;
+
+ for (i = 0; i < WINDOWSIZE; i++)
+ sum = stupidsum_add(sum, i%256, i%256);
+ assert(sum1 == sum);
+
+ for (i = 0; i < WINDOWSIZE; i++)
+ sum = stupidsum_add(sum, i%256, 0);
+ assert(sum == 0);
+}
+
+
+int main()
+{
+ assert(rol(1,0) == 1);
+ assert(rol(1,1) == 2);
+ assert(rol(1,32) == 1);
+ assert(rol(1,33) == 2);
+ assert(rol(0x12345678, 16) == 0x56781234);
+ assert(rol(0x12345678, 34) == 0x48d159e0);
+ assert(rol(0x92345678, 34) == 0x48d159e2);
+ assert(WINDOWSIZE >= 32);
+ assert(BLOBSIZE >= 32);
+ test_sums();
+
+ uint8_t buf[WINDOWSIZE];
+ uint32_t sum = 0;
+ int i = 0, count = 0, c;
+ FILE *pipe = NULL;
+
+ memset(buf, 0, sizeof(buf));
+
+ while ((c = fgetc(stdin)) != EOF)
+ {
+ sum = stupidsum_add(sum, buf[i], c);
+ buf[i] = c;
+
+ if (0)
+ {
+ int j;
+ fprintf(stderr, "[%5X] %08X '", i, sum);
+ for (j = i+1; j < i+1+WINDOWSIZE; j++)
+ {
+ int d = buf[j % WINDOWSIZE];
+ fputc((d >= 32 && d <= 126) ? d : '.', stderr);
+ }
+ fprintf(stderr, "'\n");
+ }
+
+ i = (i + 1) % WINDOWSIZE;
+ count++;
+
+ if ((sum & (BLOBSIZE-1)) == 0)
+ {
+ fprintf(stderr, "SPLIT @ %-8d (%d/%d)\n",
+ count, BLOBSIZE, WINDOWSIZE);
+ i = 0;
+ memset(buf, 0, sizeof(buf));
+ sum = 0;
+ if (pipe)
+ {
+ fflush(stderr);
+ pclose(pipe);
+ pipe = NULL;
+ }
+ }
+
+ if (!pipe)
+ pipe = popen("git hash-object --stdin -w", "w");
+ fputc(c, pipe);
+ }
+
+ if (pipe)
+ pclose(pipe);
+
+ return 0;
+}
+++ /dev/null
-#!/bin/sh
-while read x junk; do
- git cat-file -p "$x"
-done
+++ /dev/null
-#include <stdio.h>
-#include <stdint.h>
-#include <assert.h>
-#include <memory.h>
-
-#define BLOBBITS (14)
-#define BLOBSIZE (1<<(BLOBBITS-1))
-#define WINDOWBITS (7)
-#define WINDOWSIZE (1<<(WINDOWBITS-1))
-
-
-static uint32_t rol(uint32_t v, unsigned bits)
-{
- bits = bits % 32;
- return (v << bits) | (v >> (32-bits));
-}
-
-
-static uint32_t stupidsum_add(uint32_t old, uint8_t drop, uint8_t add)
-{
- return ((old<<1) | (old>>31)) ^ drop ^ add;
-}
-
-
-static void test_sums()
-{
- uint32_t sum = 0;
- int i;
-
- for (i = 0; i < WINDOWSIZE; i++)
- sum = stupidsum_add(sum, 0, i%256);
- uint32_t sum1 = sum;
-
- for (i = 0; i < WINDOWSIZE; i++)
- sum = stupidsum_add(sum, i%256, i%256);
- assert(sum1 == sum);
-
- for (i = 0; i < WINDOWSIZE; i++)
- sum = stupidsum_add(sum, i%256, 0);
- assert(sum == 0);
-}
-
-
-int main()
-{
- assert(rol(1,0) == 1);
- assert(rol(1,1) == 2);
- assert(rol(1,32) == 1);
- assert(rol(1,33) == 2);
- assert(rol(0x12345678, 16) == 0x56781234);
- assert(rol(0x12345678, 34) == 0x48d159e0);
- assert(rol(0x92345678, 34) == 0x48d159e2);
- assert(WINDOWSIZE >= 32);
- assert(BLOBSIZE >= 32);
- test_sums();
-
- uint8_t buf[WINDOWSIZE];
- uint32_t sum = 0;
- int i = 0, count = 0, c;
- FILE *pipe = NULL;
-
- memset(buf, 0, sizeof(buf));
-
- while ((c = fgetc(stdin)) != EOF)
- {
- sum = stupidsum_add(sum, buf[i], c);
- buf[i] = c;
-
- if (0)
- {
- int j;
- fprintf(stderr, "[%5X] %08X '", i, sum);
- for (j = i+1; j < i+1+WINDOWSIZE; j++)
- {
- int d = buf[j % WINDOWSIZE];
- fputc((d >= 32 && d <= 126) ? d : '.', stderr);
- }
- fprintf(stderr, "'\n");
- }
-
- i = (i + 1) % WINDOWSIZE;
- count++;
-
- if ((sum & (BLOBSIZE-1)) == 0)
- {
- fprintf(stderr, "SPLIT @ %-8d (%d/%d)\n",
- count, BLOBSIZE, WINDOWSIZE);
- i = 0;
- memset(buf, 0, sizeof(buf));
- sum = 0;
- if (pipe)
- {
- fflush(stderr);
- pclose(pipe);
- pipe = NULL;
- }
- }
-
- if (!pipe)
- pipe = popen("git hash-object --stdin -w", "w");
- fputc(c, pipe);
- }
-
- if (pipe)
- pclose(pipe);
-
- return 0;
-}