- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeMap.lua
More file actions
Latest commit
58 lines (48 loc) · 1.26 KB
/
Copy pathNodeMap.lua
File metadata and controls
58 lines (48 loc) · 1.26 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
NodeMap= {}
NodeMap._mt=Class( NodeMap )
functionNodeMap:new()
returnsetmetatable( {
nodes= {}
}, NodeMap._mt )
end
functionNodeMap:add( n, val, noexpand )
localnodes=self.nodes
ifnodes[ n[1] ] ==nilthen
nodes[ n[1] ] = {}
end
ifnodes[ n[1] ][ n[2] ] ==nilthen
nodes[ n[1] ][ n[2] ] = {}
end
ifnodes[ n[1] ][ n[2] ][ n[3] ] ==nilthen
nodes[ n[1] ][ n[2] ][ n[3] ] = {}
end
nodes[ n[1] ][ n[2] ][ n[3] ][ n[4] ] =val
end
functionNodeMap:hasKey( n )
returnself:get( n ) ~=nil
end
functionNodeMap:remove( n )
self.nodes[ n[1] ][ n[2] ][ n[3] ][ n[4] ] =nil
--yep, nodes grows with containers forever
end
functionNodeMap:get( n )
localnodes=self.nodes
returnnodes[ n[1] ]
andnodes[ n[1] ][ n[2] ]
andnodes[ n[1] ][ n[2] ][ n[3] ]
andnodes[ n[1] ][ n[2] ][ n[3] ][ n[4] ]
end
functionNodeMap:each()
localnodes=self.nodes
localfnodes= {}
forxi, xinpairs( nodes ) do
foryi, yinpairs( x ) do
forzi, zinpairs( y ) do
fordi, dinpairs( z ) do
table.insert( fnodes, d )
end
end
end
end
returnipairs( fnodes )
end