porting C-based red-black tree