Initialise the heap, discarding any previous contents.
cap pre-allocates storage for at least that many entries (default
DEFAULT_CAPACITY); a non-positive cap allocates nothing yet.
max_heap = .true. selects max-heap ordering, the default is a
min-heap. Calling init on a heap that already holds entries resets
it to empty but keeps any storage it had already acquired.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(heap_t), | intent(inout) | :: | self | |||
| integer(kind=default_int), | intent(in), | optional | :: | cap | ||
| logical, | intent(in), | optional | :: | max_heap |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | wanted |
subroutine heap_init(self, cap, max_heap) !! Initialise the heap, discarding any previous contents. !! !! `cap` pre-allocates storage for at least that many entries (default !! `DEFAULT_CAPACITY`); a non-positive `cap` allocates nothing yet. !! `max_heap = .true.` selects max-heap ordering, the default is a !! min-heap. Calling `init` on a heap that already holds entries resets !! it to empty but keeps any storage it had already acquired. class(heap_t), intent(inout) :: self integer(default_int), intent(in), optional :: cap logical, intent(in), optional :: max_heap integer(default_int) :: wanted self%n_entries = 0 self%n_pushed = 0_int64 self%max_heap = .false. if (present(max_heap)) self%max_heap = max_heap wanted = DEFAULT_CAPACITY if (present(cap)) wanted = cap call self%reserve(wanted) end subroutine heap_init