Copied in local priority queue code