maybe O(n) for switching heap types