Hi Tomas, > Why does inserting and removing using 'idx' require manual rebalancing
Well, as always in PicoLisp, this is under the control of the programmer. 'idx' is deliberately designed in this way. It does only the basic, straight-forward binary tree operations. This can be quite fast, because balancing operations (or using self-balancing trees like splay trees) introduce additional overhead. And - except for pathological situations where all data are inserted in sequentially ascending or descending order - this performs surprisingly well. > using 'balance' in the first place? I would expect insert and remove > to keep the tree balanced which should be more efficient than > rebalancing the whole tree. 'balance' does not "re"-balance the tree. Instead, it builds an optimally balanced tree, only once in the beginning. This is most useful in situation like we had with this unicode index, which is not modified thereafter but only used for rapid lookup. BTW, there is also an external program "@bin/balance" which does the same by reading from a file. It can typically be used as: (in (list "bin/balance" "-sort" MyFile) (while (line) .. (The "-sort" is not needed when the file is already sorted) > It seems to me that to keep key/value pairs in the tree, the key must > be a symbol holding that value. What if I want the keys to be numbers > or pairs? The key can be any kind of Lisp data, depending on the application. For the typical key-value situation, symbols work best, though. You can, for example, convert a numeric key to a symbol with 'format', and then store the value there (like we did with the glyphs). If you insert cells or lists with the key in the CAR, you can use 'lup' to lookup the data. Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe