Hi Kazimir,

> one can use symbols with names like
> L10000,...,L99999
> ...
> For a comparison, access to list is much slower:
> ...
> (bench (do 1000000 (inc (nth List 50000))))
> 149.812 sec
> ...
> Generation of the symbol names has its price,
> however, for lot of data, it is still faster
> than list access.

Yes, this is a valid approach. Basically you use the symbol lookup
mechanism of 'intern'.

But I see several problems with that:

1. It clobbers the internal symbol name space.
2. There is the danger of conflict with existing symbols
3. The structure can only be cleaned up by calling 'zap' for each symbol
4. If you have many such structures, they will all use the same tree

There is a direct way to achieve something similar: The 'idx' mechanism,
using a binary tree. For example, creating a tree of 50000 random
"array" entries, each initialized to zero:

   (off Tree)
   (do 50000
      (idx 'Tree
         (def (format (rand 1 50000)) 0)
         T ) )

Then, incrementing a million random entries:

      (do 1000000
         (inc (car (idx 'Tree (format (rand 1 50000))))) ) )
   2.650 sec

This doesn't clobber any global structures. Instead of (off Tree), you
would say

   (let Tree NIL
      ... )

and the whole tree will become garbage as soon as the 'let' body

- Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to