-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash.ew
87 lines (72 loc) · 2.12 KB
/
hash.ew
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
sequence class_list,class_freelist
class_list={}
class_freelist={}
constant hash_list = 1
function remove_line(sequence string, integer line)
sequence temp
integer len
len=length(string)
if line=1 then
return string[2..len]
elsif line=len then
return string[1..len-1]
else
temp=string[1..line-1]
return temp&string[line+1..len]
end if
end function
global procedure hash_insert(integer classhandle ,integer index, integer object_id, integer index2)
class_list[classhandle][hash_list][index]=append(class_list[classhandle][hash_list][index],{object_id, index2})
end procedure
global function hash_get_handle(integer classhandle,integer index, integer object_id)
for i=1 to length(class_list[classhandle][hash_list][index]) do
if class_list[classhandle][hash_list][index][i][1]=object_id then
return class_list[classhandle][hash_list][index][i][2]
end if
end for
return 0
end function
global procedure hash_remove_index(integer classhandle, integer index, integer object_id)
for i=1 to length(class_list[classhandle][hash_list][index]) do
if class_list[classhandle][hash_list][index][i][1]=object_id then
class_list[classhandle][hash_list][index]=remove_line(class_list[classhandle][hash_list][index], i)
exit
end if
end for
end procedure
global function hash_size(integer classhandle)
integer size
size=0
for i=1 to length(class_list[classhandle][hash_list]) do
size+=length(class_list[classhandle][hash_list][i])
end for
return size
end function
global function hash_index(integer v)
integer min, max
min=1
max=1000
while v<min do
v+=max
end while
while v>max do
v-=max
end while
return v
end function
global function hash_new()
integer handle
if length(class_freelist)>0 then
handle= class_freelist[1]
class_freelist = class_freelist[2..length(class_freelist)]
else
class_list= append(class_list,{})
handle=length(class_list)
end if
class_list[handle]={ repeat({},1000) }
return handle
end function
global procedure hash_delete(integer handle)
class_list[handle]={}
class_freelist =append(class_freelist, handle)
end procedure