js-data-structures
                                
                                 js-data-structures copied to clipboard
                                
                                    js-data-structures copied to clipboard
                            
                            
                            
                        Scapegoat trees
Insertion only:
At each node remember:
- a counter initialized to the size of its subtree
- a counter initialized to 0 When inserting a new node increment the second counter of each ancestor If one of those second counters becomes equal to the first counter of the same node, rebuild its subtree from scratch in a balanced way.