Hello,

I have a simple idea to improve performance for fact lookup, when facts describe links in a graph; and am wondering if this has merit.

What if a specialized atom and related data structure would be introduced that extends the current atom data structure to include a built-in list of pointers to other atoms; and a build-in predicate pointer/2 that retrieves (non-determinstically) atoms pointed to, such as so:

pointer(N, N_Next).

There would also be an *assert_pointer/2* built-in predicate, such as: assert_pointer(n1, n2), that establishes a(nother) pointer from n1 to n2.

The idea is that a predicate lookup such as:

```
get_next(N, N_Next) :-
pointer(N, N_Next).
```

With N bound to the atom n1, swi prolog would not use the usual hash lookup to get at pointer(n1, n2) (with an index pointing to functor, and arg1: n1; but would (non-deterministically) use the pointer list already stored in atom n1 to get to n2.

At its simplest, if N is not bound, then its illegal; and if N_Next is bound, then the predicate becomes a test whether n1 pointes to n2.

Alternatively, If N is not bound, then pointer/2 reverts back to a usual indexed lookup for N and behaves like a usual fact lookup. It fails if the related pointer fact was not asserted w/ assert_pointer.

If N_Next is bound, and N is not bound then then this could either revert to usual indexed lookup, or be illegal – to get to a doubly linked item one would need to assert another pointer(n2, n1).

pointer/2, would be a special purpose predicate to optimize basic lookup in linked atoms such as in graphs.

I think, this can’t be a simple external predicate since it would require extending / specialize the built-in data structure of an atom, to include a pointer list – to avoid the (costly) hash lookup within the external predicate to get at an externally defined pointer list from atom to atom.

Does this make sense?

thanks,

Dan