Package-merge algorithm