]> arthur.barton.de Git - bup.git/commitdiff
Extremely cheesy initial implementation of rolling-sum-based splitting.
authorAvery Pennarun <apenwarr@gmail.com>
Sat, 3 Oct 2009 23:48:49 +0000 (19:48 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Sat, 3 Oct 2009 23:48:49 +0000 (19:48 -0400)
The checksum algorithm is crap, and we don't actually generate the output
files yet, so I'm guessing it's still junk.

.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
hsplit.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..243e38e
--- /dev/null
@@ -0,0 +1,4 @@
+hsplit
+hjoin
+*.o
+*~
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..cd739e6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,16 @@
+CFLAGS=-Wall -g -Werror
+
+all: hsplit
+
+hsplit: hsplit.o
+
+hjoin: hjoin.o
+
+%: %.o
+       gcc -o $@ $< $(LDFLAGS) $(LIBS)
+       
+%.o: %.c
+       gcc -c -o $@ $^ $(CPPFLAGS) $(CFLAGS)
+
+clean:
+       rm -f *.o *~ hsplit hjoin
diff --git a/hsplit.c b/hsplit.c
new file mode 100644 (file)
index 0000000..42d30c7
--- /dev/null
+++ b/hsplit.c
@@ -0,0 +1,64 @@
+#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;
+}
+
+
+int main()
+{
+    printf("hello world\n");
+    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);
+    
+    uint8_t buf[WINDOWSIZE];
+    uint32_t sum = 0;
+    int i = 0, count = 0, c;
+    
+    memset(buf, 0, sizeof(buf));
+    
+    while ((c = fgetc(stdin)) != EOF)
+    {
+       sum = stupidsum_add(sum, buf[i], c);
+       buf[i] = c;
+       
+       int cprint = (c >= 32 && c <= 126) ? c : '.';
+       printf("[%05X] %02X '%c' %08X\n", i, c, cprint, sum);
+       
+       i = (i + 1) % WINDOWSIZE;
+       count++;
+       
+       if ((sum & (BLOBSIZE-1)) == 0)
+       {
+           printf("\nSPLIT @ %d (%d)\n\n", count, BLOBSIZE);
+           count = i = 0;
+           memset(buf, 0, sizeof(buf));
+       }
+    }
+    
+    return 0;
+}