4 # 1. Describe this thing as a whole
5 # 2. Check whether randint() is safe
7 # This software is licensed under the GPLv2
9 # Author: Luiz Fernando N. Capitulino <lcapitulino@gmail.com>
16 from random
import randint
18 nr_runs
= nr_found
= 0L
20 def sig_handler(signum
, frame
):
21 """Show current status."""
22 sys
.stdout
.write('-> Ran %d times with %d matches\n' %
28 sys
.stdout
.write('-> PID: %d\n\n' % getpid())
34 Randomly generate six not equal numbers between 1 and 60, return
35 them as a string formatted likes this: 12 03 21 22 43 25.
37 Note that we must always return two algarisms, because external data
44 # XXX: Is there something better than randint() to be
49 numbers
.append("%02d " % val
)
52 return ''.join(numbers
).rstrip()
55 global nr_runs
, nr_found
61 sys
.stderr
.write('usage: %s < -linear-probe | -double-hashing | -chained > < file-name >\n' % sys
.argv
[0])
64 if probe
== '-double-hashing':
65 table
= hashtable
.OpenAddressedDH(3119)
66 elif probe
== '-linear-probe':
67 table
= hashtable
.OpenAddressedLP(10240)
68 elif probe
== '-chained':
69 table
= hashtable
.Chained(2048)
71 sys
.stderr
.write('Unknown probe method: %s\n' % probe
)
74 table
.load_from_file(fname
)
80 # Print status when SIGUSR1 is sent
81 signal
.signal(signal
.SIGUSR1
, sig_handler
)
85 ret
= table
.lookup(name
)
87 sys
.stdout
.write('-> HIT in run %d: [%d] %s\n' %
94 if __name__
== "__main__":