Last change
on this file since 166 was
166,
checked in by (none), 14 years ago
|
HadoopA51: imported git repository from github
|
-
Property svn:executable set to
*
|
File size:
995 bytes
|
Rev | Line | |
---|
[166] | 1 | #!/usr/bin/env python3 |
---|
| 2 | |
---|
| 3 | N=4 |
---|
| 4 | nr_tables=4 |
---|
| 5 | |
---|
| 6 | def gen_rainbow_reductors(k): |
---|
| 7 | def R1(x): |
---|
| 8 | return x / 10 * 10 + x % 3 |
---|
| 9 | |
---|
| 10 | def R2(x): |
---|
| 11 | return x / 10 * 10 % 3 + 3 |
---|
| 12 | |
---|
| 13 | def R3(x): |
---|
| 14 | return x / 10 * 10 % 3 + 6 |
---|
| 15 | |
---|
| 16 | def R4(x): |
---|
| 17 | return x / 10 * 10 + 9 |
---|
| 18 | |
---|
| 19 | Rint = [R1, R2, R3, R4] |
---|
| 20 | Rstr = [] |
---|
| 21 | for rint in Rint: |
---|
| 22 | Rstr.append(lambda s : str(int(rint(int(s, 10))) ^ k).zfill(N)) |
---|
| 23 | return Rstr |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | def hashfn(s): |
---|
| 27 | return s[2:] + s[0:2] |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | def chain_end(s, R): |
---|
| 31 | for r in R: |
---|
| 32 | s = r(hashfn(s)) |
---|
| 33 | return s |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | def generate_table(f, R): |
---|
| 37 | v = [] |
---|
| 38 | for l in f: |
---|
| 39 | v.append([l, chain_end(l, R)]) |
---|
| 40 | return v |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | def matches(k, v, needle, entry, R): |
---|
| 44 | start_string = entry[0] |
---|
| 45 | end_string = entry[1] |
---|
| 46 | s = start_string |
---|
| 47 | for i in range(0, k): |
---|
| 48 | s = R[i](hashfn(s)) |
---|
| 49 | return hashfn(s) == needle |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | def gen_chain_from(needle, k, R): |
---|
| 53 | for i in range(k, len(R) - 1): |
---|
| 54 | needle = hashfn(R[i](needle)) |
---|
| 55 | return R[len(R)-1](needle) |
---|
Note: See
TracBrowser
for help on using the repository browser.