Skip to content

Instantly share code, notes, and snippets.

@Bouke
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bouke/3dad30b8c7d2b9408b8d to your computer and use it in GitHub Desktop.
Save Bouke/3dad30b8c7d2b9408b8d to your computer and use it in GitHub Desktop.
Binary Heap (Priority Queue) in Swift
@littlebobert
Copy link

won't heapify fail to explore subtrees (that might violate min-heap properties) in the case where index is already the smallest? I guess it doesn't matter here since you only ever call heapify when the index is the only element that’s in violation…

@Bouke
Copy link
Author

Bouke commented Nov 2, 2014

This code was written when Swift didn't have access modifiers. Both var heap and func heapify are not part of the public API. You can only pop items onto the heap, so the result should always be a valid binary heap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment