TysonAndre / pecl-teds

Tentative Extra Data Structures for php
BSD 3-Clause "New" or "Revised" License
30 stars 4 forks source link

Idea: Immutable lists with modifications returning new lists - look into Relaxed Radix Binary Trees #104

Open TysonAndre opened 2 years ago

TysonAndre commented 2 years ago

Google searching mentioned Relaxed Radix Binary Trees, an immutable datastructure surprisingly claiming performance near arrays in most operations. https://hypirion.com/musings/thesis https://github.com/hyPiRion/c-rrb

TysonAndre commented 2 years ago

Those are technically logarithmic, the log depth is just small for realistic amounts of memory (only several times slower than arrays in that language).

Transients are a lot less convenient in php.

PHP's gc algorithm also poses unique problems - gc will be slow if a lot of immutable collections reference the same array

Something simpler that would have okay typical-case but worse worst-case performance: Storing references to at most 4 zend_array (packed list) instances/ImmutableList/individual zvals internally (and ranges of those arrays) may work for some common use case, for the head/tail for appending/prepending, combining them in place/freeing internally when reference counts drop to 1