Packet assembly using binary search tree