I used RB tree for this. The implementation is based on the code on wikipedia about RB trees.
As the number of libraries is increasing, root directory starts to expand. This adds better organization for libraries