1. I haven't tested it, but I suspect that variable access will be maybe three or four times faster than struct field access. In the case of variable, the engine caches the value of the variable, but for structs we have to do a lookup (log n, unfortunately). You might be better off with lists. An index into a list is linear (minus some setup time for caching):
Code: Select all
(@ someList 4) -> linear time
(@ someStruct 'someKey) -> log n (where n is the number of keys in someStruct).
2. Unfortunately, recursive pointers like you propose will leak memory in the current engine. I use a ref-counted system of memory management instead of garbage collection. The only way to prevent the memory leak would be to break the links (by setting to Nil) before letting the variable go out of scope.
3. The paper you point to looks fascinating. Are you trying to build a random gate network? If so, please keep me up to date on your progress. It sounds like a generally useful idea.
Your best bet might be to use lists of integers as indices into other lists (instead of pointers). For example, imagine the following implementation:
Code: Select all
(setq vertexList
(list
(list 0 0 Nil) ; The 0th vertex at position 0,0 (we'll fill in the Nil with a list of edges later)
(list 5 0 Nil) ; The 1st vertex at position 5,0
(list 0 5 Nil) ; The 2nd vertex at position 0,5
)
)
(setq edgesList
(list
(list 0 1) ; An edge from vertex 0 to 1
(list 1 2) ; An edge from vertex 1 to 2
(list 2 0) ; An edge from vertex 2 to 0
)
)
; Vertex 0 has two edges, 0 and 2 (these are indices into the edgesList list)
(set@ (@ vertexList 0) 2 (list 0 2))
; Vertex 1 has two edges, 0 and 1
(set@ (@ vertexList 1) 2 (list 0 1))
; Vertex 2 has two edges, 1 and 2
(set@ (@ vertexList 2) 2 (list 1 2))