From bd43c44ab5216e53bddc0e5c33cf8976db4d54b3 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Sun, 20 Nov 2022 08:34:27 +0100 Subject: grt-algos: clarify the API --- src/grt/grt-algos.adb | 3 +++ src/grt/grt-algos.ads | 8 ++++---- src/grt/grt-waves.adb | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/grt/grt-algos.adb b/src/grt/grt-algos.adb index 6469e2b80..82c14bd8c 100644 --- a/src/grt/grt-algos.adb +++ b/src/grt/grt-algos.adb @@ -39,6 +39,9 @@ package body Grt.Algos is end Bubble_Down; begin + -- Note: if N < 2, there is nothing to sort. The loops are not + -- executed. + -- Heapify for I in reverse 1 .. N / 2 loop Bubble_Down (I, N); diff --git a/src/grt/grt-algos.ads b/src/grt/grt-algos.ads index 1197bcd7b..828960e11 100644 --- a/src/grt/grt-algos.ads +++ b/src/grt/grt-algos.ads @@ -15,12 +15,12 @@ -- along with this program. If not, see . package Grt.Algos is - -- Heap sort the N elements. + -- Heap sort the N elements. Indexes are from 1 to N. generic - -- Compare two elements, return true iff OP1 < OP2. - with function Lt (Op1, Op2 : Natural) return Boolean; + -- Compare two elements, return true iff L < R. + with function Lt (L, R : Positive) return Boolean; -- Swap two elements. - with procedure Swap (From : Natural; To : Natural); + with procedure Swap (P1 : Positive; P2 : Positive); procedure Heap_Sort (N : Natural); end Grt.Algos; diff --git a/src/grt/grt-waves.adb b/src/grt/grt-waves.adb index eb0f0a898..98a8538b3 100644 --- a/src/grt/grt-waves.adb +++ b/src/grt/grt-waves.adb @@ -1783,7 +1783,8 @@ package body Grt.Waves is procedure Wave_Cycle is - function Lt (Op1, Op2 : Natural) return Boolean is + function Lt (Op1, Op2 : Positive) return Boolean + is Left : Ghdl_Signal_Ptr; Right : Ghdl_Signal_Ptr; begin @@ -1793,7 +1794,8 @@ package body Grt.Waves is end Lt; pragma Inline (Lt); - procedure Swap (From, To : Natural) is + procedure Swap (From, To : Positive) + is Tmp : Ghdl_Signal_Ptr; begin Tmp := Changed_Sig_Table.Table (From); -- cgit v1.2.3