top | item 42484185

(no title)

nrdvana | 1 year ago

Why was the solution not to get rid of the linked list and replace it with a red/black tree?

discuss

order

thayne|1 year ago

Or hash table, or any other kind of tree.

My guess would be because it was implemented in c, where the usual practice if you need a container type other than a fixed size array is to implement it yourself. IME, c code tends to use linked lists for a lot of things that in most other languages would be implemented using a better suited, and more performent, container type from the standard library.

One way that other languages can outperform c, is it is easier to use the right data structure.

masklinn|1 year ago

Blender's not even in C (the snippets are clearly C++), I wonder what the logic of having a sorted doubly linked list is: unless it's a skip list it's not like you can do bisection searches.

I guess a flat array could still be debatable if you're usually inserting near but not at the end, as it'll still need to move all the following elements. But it seems dubious.

Epa095|1 year ago

I got the impression that the expected performance of the double linked list insertion is actually O(1), since in most cases the elements arrive in sorted order. It's been a time since my algorithm courses, but I think all the 'normal' trees have log(n) insertion in that case.

nrdvana|1 year ago

O(n) is generally indistinguishable from O(log n) so if there is any chance of different behavior than the expected optimum, go with the better algorithm.