-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_splay.py
More file actions
91 lines (89 loc) · 4.5 KB
/
Copy pathtest_splay.py
File metadata and controls
91 lines (89 loc) · 4.5 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from neo_fairy_client import FairyClient, Hash160Str, Hash256Str
user = Hash160Str('0xb1983fa2479a0c8e2beae032d2df564b5451b7a5')
c = FairyClient(fairy_session='splay', wallet_address_or_scripthash=user, with_print=False)
c.virutal_deploy_from_path('./bin/sc/RelationalDB.nef')
table_name = 'rotate'
column_id = 0x01
r'''
1
/ \
2 3
4 5
'''
c.invokefunction('splayDebugPut', [user, table_name, column_id, 1, None, 2, 3])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 2, 1, 4, 5])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 3, 1, None, None])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 4, 2, None, None])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 5, 2, None, None])
for v in [1,2,3,4,5]:
print(v)
result = c.invokefunction('splayGetParent', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result, end=' ')
result = c.invokefunction('splayGetLeft', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result, end=' ')
result = c.invokefunction('splayGetRight', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result)
c.invokefunction('splayDebugRightRotateZig', [user, table_name, column_id, 2])
for v in [1,2,3,4,5]:
print(v)
result = c.invokefunction('splayGetParent', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result, end=' ')
result = c.invokefunction('splayGetLeft', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result, end=' ')
result = c.invokefunction('splayGetRight', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result)
print(table_name)
c.invokefunction('splayDebugLeftRotateZag', [user, table_name, column_id, 1])
for v in [1,2,3,4,5]:
print(v)
result = c.invokefunction('splayGetParent', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result, end=' ')
result = c.invokefunction('splayGetLeft', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result, end=' ')
result = c.invokefunction('splayGetRight', [user, table_name, column_id, v])
print(int.from_bytes(result.encode(), 'little', signed=True) if result else result)
print('----------')
r'''
g
/ \
p D
/ \
x C
A B
'''
table_name = 'splay'
c.invokefunction('splayDebugPut', [user, table_name, column_id, 'g', None, 'p', 'D'])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 'p', 'g', 'x', 'C'])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 'x', 'p', 'A', 'B'])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 'A', 'x', None, None])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 'B', 'x', None, None])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 'C', 'p', None, None])
c.invokefunction('splayDebugPut', [user, table_name, column_id, 'D', 'g', None, None])
for v in ['g','p','x','A','B','C','D']:
print(v)
result = c.invokefunction('splayGetParent', [user, table_name, column_id, v])
print(result if type(result) is str else chr(result) if result else 0, end=' ')
result = c.invokefunction('splayGetLeft', [user, table_name, column_id, v])
print(result if type(result) is str else chr(result) if result else 0, end=' ')
result = c.invokefunction('splayGetRight', [user, table_name, column_id, v])
print(result if type(result) is str else chr(result) if result else 0)
print(table_name)
c.invokefunction('splayDebugSplay', [user, table_name, column_id, 'x', None])
r'''
x
/ \
A p
/ \
B g
C D
'''
for v in ['g','p','x','A','B','C','D']:
print(v)
result = c.invokefunction('splayGetParent', [user, table_name, column_id, v])
print(result if type(result) is str else chr(result) if result else 0, end=' ')
result = c.invokefunction('splayGetLeft', [user, table_name, column_id, v])
print(result if type(result) is str else chr(result) if result else 0, end=' ')
result = c.invokefunction('splayGetRight', [user, table_name, column_id, v])
print(result if type(result) is str else chr(result) if result else 0)
print('----------')
table_name = 'splay'