source: proiecte/HadoopA51/src/serial/py/rainbow_config.py @ 166

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
Line 
1#!/usr/bin/env python3
2
3N=4
4nr_tables=4
5
6def 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
26def hashfn(s):
27    return s[2:] + s[0:2]
28
29
30def chain_end(s, R):
31    for r in R:
32        s = r(hashfn(s))
33    return s
34
35
36def generate_table(f, R):
37    v = []
38    for l in f:
39        v.append([l, chain_end(l, R)])
40    return v
41
42
43def 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
52def 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.