# Source URL: https://dev.epicgames.com/community/snippets/Gw1G/fortnite-heaps-and-heapsort
# Local doc: epic-docs/community/snippets/Gw1G/fortnite-heaps-and-heapsort.md
Arrays<public> := module:
<# Array utility to swap the elements contained in indices I and J #>
(Array:[]t where t:type).Swap<public>(FirstIndex:int, SecondIndex:int)<decides><transacts>:[]t =
ArrayTemp := Array.ReplaceElement[FirstIndex, Array[SecondIndex]]
return ArrayTemp.ReplaceElement[SecondIndex, Array[FirstIndex]]
Heaps<public> := module:
using { Arrays }
MinHeap<public>(t:type) := class<concrete>:
# Properties
Heap<internal>:[]t = array{}
Size<internal>:int = 0
LessThan<internal>:?type{_(:t,:t)<decides><transacts>:void} = false
Equivalent<internal>:?type{_(:t,:t)<decides><transacts>:void} = false
# Get the size of the heap array
GetSize<public>()<transacts>:int =
Size
# Get a copy of the heap array
GetHeap<public>()<transacts>:[]t =
Heap
# Get the less than comparison function
# Fails if no less than specified, succeeds and returns the function if specified
GetLessThan<public>()<decides><transacts>:type{_(:t,:t)<decides><transacts>:void} =
LessThan?
# Get the equivalent comparison function
# Fails if no equivalent specified, succeeds and returns the function if specified
GetEquivalent<public>()<decides><transacts>:type{_(:t,:t)<decides><transacts>:void} =
Equivalent?
# Get the minimum value in the heap
Verse Library
verse
01 Snippet
Provides a generic min-heap class for efficient priority queue management and sorting large datasets in Verse.
extracted-snippets/community/snippets/Gw1G/fortnite-heaps-and-heapsort/01-snippet.verse
Sign in free to read the full source 🌴
This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.