/* this finds the check bits for the basis of the d=7 binary lexicodes */ #include #define DIST 7 #define LENGTH 4096 typedef unsigned long int ub4; static ub4 last = 0; static int last_cnt = 1; static int last_k = DIST-1; /* show (n,k,d) and check bits for a basis member */ void show(int i, ub4 x, int d) { ub4 j; for (j=0; (((ub4)1)<>=1) { printf("%d", (x & j) ? 1 : 0); } printf("\n"); } /* count how many bits are set */ int count(ub4 x) { x = (x & 0x55555555) + ((x>>1 ) & 0x55555555); x = (x & 0x33333333) + ((x>>2 ) & 0x33333333); x = (x & 0x0f0f0f0f) + ((x>>4 ) & 0x0f0f0f0f); x = (x & 0x00ff00ff) + ((x>>8 ) & 0x00ff00ff); x = (x & 0x0000ffff) + ((x>>16) & 0x0000ffff); return (int)x; } /* see how big a suffix we can skip */ int suffix(ub4 x, int dist) { int i, j; int d = dist - count(x); for (i=0, j=0; j= last_k) { last = t; last_cnt = cnt; last_k = k; } } /* test a[len] against all XORs of cnt existing basis members */ int test(ub4 *a, int len, int dist, ub4 t, int pos, int num, int cnt) { int i; if (--num) { for (i=pos; i-- > num;) { t ^= a[i]; if (!test(a, len, dist, t, i, num, cnt)) return 0; t ^= a[i]; } } else { for (i=pos; i--;) { t ^= a[i]; if (cnt+count(a[len]^t) < dist) { update_last(a[len], t, cnt, dist); return 0; } t ^= a[i]; } } return 1; } /* construct the basis */ void construct(ub4 *a, int dist, int length) { int i=0, k, q; ub4 j=1, z; for (; i>k)<>k)+1)<>k)<