From 53831b3a2264e24ca6c7ffcfe33c8653a72d51e1 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 14 Nov 2023 19:10:35 -0800 Subject: [PATCH] [Heap] Update docs --- Documentation/Heap.md | 10 +++++----- Sources/HeapModule/Heap.swift | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Documentation/Heap.md b/Documentation/Heap.md index 929c6fd4..2037472d 100644 --- a/Documentation/Heap.md +++ b/Documentation/Heap.md @@ -53,8 +53,8 @@ This works by adding the new element into the end of the backing array and then You can also insert a sequence of elements into a `Heap`: ```swift -var heap = Heap((0..<10)) -heap.insert(contentsOf: (20...100).shuffled()) +var heap = Heap(0 ..< 10) +heap.insert(contentsOf: (20 ... 100).shuffled()) heap.insert(contentsOf: [-5, -6, -8, -12, -3]) ``` @@ -63,9 +63,9 @@ heap.insert(contentsOf: [-5, -6, -8, -12, -3]) As mentioned earlier, the smallest and largest elements can be queried in constant time: ```swift -var heap = Heap((1...20)) -let min = heap.min() // min = 1 -let max = heap.max() // max = 20 +var heap = Heap(1 ... 20) +let min = heap.min // 1 +let max = heap.max // 20 ``` In a min-max heap, the smallest element is stored at index 0 in the backing array; the largest element is stored at either index 1 or index 2, the first max level in the heap (so to look up the largest, we compare the two and return the larger one). diff --git a/Sources/HeapModule/Heap.swift b/Sources/HeapModule/Heap.swift index 3016fb67..698f28f4 100644 --- a/Sources/HeapModule/Heap.swift +++ b/Sources/HeapModule/Heap.swift @@ -17,9 +17,9 @@ /// /// var queue: Heap = [3, 4, 1, 2] /// queue.insert(0) -/// print(queue.min()) // 0 +/// print(queue.min) // 0 /// print(queue.popMax()) // 4 -/// print(queue.max()) // 3 +/// print(queue.max) // 3 /// /// `Heap` implements the min-max heap data structure, based on /// [Atkinson et al. 1986].