]> arthur.barton.de Git - bup.git/commitdiff
Rename hsplit/hjoin to hashsplit/hashjoin.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 4 Oct 2009 01:49:43 +0000 (21:49 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 4 Oct 2009 01:49:43 +0000 (21:49 -0400)
.gitignore
Makefile
hashjoin.sh [new file with mode: 0755]
hashsplit.c [new file with mode: 0644]
hjoin.sh [deleted file]
hsplit.c [deleted file]

index 163f7831700a8709f2928edd6d2a4bedc5b7cc99..bd5c38958ecbe3fc79899fcde19c1e7ae55ad225 100644 (file)
@@ -1,5 +1,8 @@
 hsplit
 hjoin
+hashsplit
+hashjoin
 *.o
 *~
 tags[12]
+out[12]
index 72733b39a0f208cde53b8f575faef1f876b094e4..6c62c9b74a45b6db988118047f4ffacb19eef118 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,21 @@
 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
 
@@ -28,4 +30,5 @@ test: hsplit hjoin
        gcc -c -o $@ $^ $(CPPFLAGS) $(CFLAGS)
 
 clean:
-       rm -f *.o *~ hsplit hjoin
+       rm -f *.o *~ hashsplit hashjoin hsplit hjoin \
+               out[12] tags[12] .*~
diff --git a/hashjoin.sh b/hashjoin.sh
new file mode 100755 (executable)
index 0000000..b04ad43
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+while read x junk; do
+    git cat-file -p "$x"
+done
diff --git a/hashsplit.c b/hashsplit.c
new file mode 100644 (file)
index 0000000..fe130c8
--- /dev/null
@@ -0,0 +1,108 @@
+#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;
+}
diff --git a/hjoin.sh b/hjoin.sh
deleted file mode 100755 (executable)
index b04ad43..0000000
--- a/hjoin.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-while read x junk; do
-    git cat-file -p "$x"
-done
diff --git a/hsplit.c b/hsplit.c
deleted file mode 100644 (file)
index fe130c8..0000000
--- a/hsplit.c
+++ /dev/null
@@ -1,108 +0,0 @@
-#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;
-}