-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (55 loc) · 1.74 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from chaining import *
from cuckoo import *
from random import *
# 'chain' or 'cuckoo'
hashmap = "chain"
class Command(object):
def __init__(self, action, key, val):
self.action = action
self.key = key
self.val = val
to_insert = Command('i', floor(random() * 100), floor(random() * 100))
def generate_testcase(n):
filename = './testcase/insert/' + hashmap + '/test_' + str(n) + '.csv'
for i in range(0, n):
c = Command('i', floor(random() * 100), floor(random() * 100))
with open(filename, 'a') as f:
line = c.action + ',' + str(c.key) + ',' + str(c.val)
f.write(line)
f.write('\n')
f.close()
if __name__ == '__main__':
outfile = './output/insert/' + hashmap + '.csv'
N = 373
if hashmap == 'cuckoo':
N *= 2
alpha = 0.05
while alpha < 1:
n = floor(alpha * N)
if n == 0:
alpha += 0.05
continue
# generate_testcase(n)
filename = './testcase/insert/' + hashmap + '/test_' + str(n) + '.csv'
c = Chaining()
with open(filename, 'r') as f:
lines = f.readlines()
f.close()
for i in range(0, len(lines)):
line = lines[i]
info = line.split(',')
key = int(info[1])
val = int(info[2])
if info[0] == 'i':
c.insert(key, val)
elif info[0] == 's':
c.search(key)
elif info[0] == 'r':
c.remove(key)
c.insert(to_insert.key, to_insert.val)
line = str(alpha) + ',' + str(c.n_encountered)
with open(outfile, 'a') as f:
f.write(line)
f.write('\n')
f.close()
alpha += 0.05