Documentation

Complexity.Algorithms.WordRAM.PriorityQueue.BinaryHeap.Program

Indexed Binary Min-Heap: Exact-Basis Word-RAM Program #

This file defines the structured word-RAM code (Cslib.WordRAM.Code .exact 25) and PQCode calling convention for the standalone indexed binary min-heap on rBin = 25 registers.

Registers 0..4 (baseReg, nReg, hb, pb, sz) are persistent (input = false); registers 5..24 (frontierReg, tags, arguments, outputs, constants, and sift scratch registers) are caller-overwritable (input = true). Parent positions are computed via p ← k >>> one (k >>> 1 = k / 2), so no constant larger than 1 is ever loaded and all operations succeed at every word width w with Fits w (base + space n) and Fits w K_max (including n = 0, w = 1).

Main definitions #

References #

@[reducible, inline]

Total register count of the standalone binary heap (5 persistent + 20 caller/scratch).

Instances For
    @[reducible, inline]

    Persistent base address base of the key array ([base, base + n)).

    Instances For
      @[reducible, inline]

      Persistent handle bound n.

      Instances For
        @[reducible, inline]

        Persistent heap array base base + n (slots 1..sz at base + n + i).

        Instances For
          @[reducible, inline]

          Persistent pos array base base + 2 * n + 1.

          Instances For
            @[reducible, inline]

            Persistent current heap size sz ≤ n.

            Instances For
              @[reducible, inline]

              Bump-allocation frontier register.

              Instances For
                @[reducible, inline]

                High operation-tag bit (1 iff extractMin).

                Instances For
                  @[reducible, inline]

                  Middle operation-tag bit (1 iff insert or decreaseKey).

                  Instances For
                    @[reducible, inline]

                    Low operation-tag bit.

                    Instances For
                      @[reducible, inline]

                      Input handle argument v.val.

                      Instances For
                        @[reducible, inline]

                        Input key argument k.

                        Instances For
                          @[reducible, inline]

                          Output status/presence flag (output register).

                          Instances For
                            @[reducible, inline]

                            Output handle register (extractMin).

                            Instances For
                              @[reducible, inline]

                              Output key register (getKey, extractMin).

                              Instances For
                                @[reducible, inline]

                                Scratch constant 0 (also zeroReg for SubroutineCode.zeroFillCode).

                                Instances For
                                  @[reducible, inline]

                                  Scratch constant 1 (also oneReg for SubroutineCode.zeroFillCode).

                                  Instances For
                                    @[reducible, inline]

                                    Scratch address / comparison register (also curReg for SubroutineCode.zeroFillCode).

                                    Instances For
                                      @[reducible, inline]

                                      Current 1-based heap position during siftUp / siftDown.

                                      Instances For
                                        @[reducible, inline]

                                        Parent or chosen child position during siftUp / siftDown.

                                        Instances For
                                          @[reducible, inline]

                                          Handle at position k (or right child during siftDownChoose).

                                          Instances For
                                            @[reducible, inline]

                                            Handle at position p.

                                            Instances For
                                              @[reducible, inline]

                                              Key of vk.

                                              Instances For
                                                @[reducible, inline]

                                                Key of vp.

                                                Instances For
                                                  @[reducible, inline]

                                                  Left child 2 * k during siftDown.

                                                  Instances For
                                                    @[reducible, inline]

                                                    sz + 1 bound during siftDown.

                                                    Instances For

                                                      Register classification: 0..4 are persistent (false), 5..24 are caller/scratch (true).

                                                      Instances For

                                                        Bump-allocate space n = 3 * n + 1 words at frontierReg, recording baseReg, hb, and pb.

                                                        Instances For

                                                          Initialize hb := base + n, pb := base + 2 * n + 1, and sz := 0 assuming [base, base + space n) is already zero-filled.

                                                          Instances For

                                                            Swap heap entries at positions k (handle vk) and p (handle vp), updating pos.

                                                            Instances For
                                                              @[reducible, inline]

                                                              Set t := 1 iff IndexedMinPQ.RawPrioLT (vA, dA) (vB, dB), else t := 0.

                                                              Instances For
                                                                @[reducible, inline]

                                                                Set t := 1 iff IndexedMinPQ.RawPrioLT (vk, dk) (vp, dp), else t := 0.

                                                                Instances For
                                                                  @[reducible, inline]

                                                                  Set t := 1 iff IndexedMinPQ.RawPrioLT (vp, dp) (vk, dk), else t := 0.

                                                                  Instances For

                                                                    One iteration of siftUp from k ≥ 2, using k >>> one = k / 2 for the parent position.

                                                                    Instances For

                                                                      Choose the lexicographically smaller child of k (l vs l + 1) into (p, vp, dp).

                                                                      Instances For

                                                                        Swap k with chosen child (p, vp, dp) if IndexedMinPQ.RawPrioLT (vp, dp) (vk, dk), else stop siftDown.

                                                                        Instances For

                                                                          Handle getKey v: sets outFlag := 0 if pos[v] = 0, else outFlag := 1 and outK := key[v].

                                                                          Instances For

                                                                            Handle insert v k: stores key[v] := argK, appends v at sz + 1, and sifts up.

                                                                            Instances For

                                                                              Handle decreaseKey v k: updates key[v] := argK, reads k := pos[v], and sifts up.

                                                                              Instances For

                                                                                Non-empty branch of extractMin: reads root into (outV, outK), clears pos[outV], moves last entry to root when sz - 1 > 0, and sifts down.

                                                                                Instances For

                                                                                  Dispatch a single IndexedMinPQ.Op encoded in (tag2, tag1, tag0, argV, argK).

                                                                                  Instances For

                                                                                    Packaged PQCode .exact rBin for the standalone binary heap.

                                                                                    Instances For