Search lands in PR-5.1 (Pagefind).

How-to Intermediate

Chapter 3 Updated

Remove Interval

Each interval yields a left remnant, a right remnant, or both.

  • Full 5m
  • Revision 2m
  • Flow 1m

Remove Interval — control flow

flowchart TD
    S["<b>i · start</b><br/>result = []; rm_s, rm_e = toBeRemoved"]
      --> L{"<b>ii · next interval [s, e]?</b>"}
    L -->|"yes"| C{"<b>iii · no overlap?</b><br/>e ≤ rm_s or s ≥ rm_e"}
    C -->|"yes"| K["<b>iv · keep [s, e]</b>"]
    C -->|"no"| LR{"<b>v · left remnant?</b><br/>s &lt; rm_s"}
    LR -->|"yes"| PL["append [s, rm_s]"]
    LR -->|"no"| RR{"<b>vi · right remnant?</b><br/>e &gt; rm_e"}
    PL --> RR
    RR -->|"yes"| PR["append [rm_e, e]"]
    RR -->|"no"| L
    PR --> L
    K --> L
    L -->|"done"| O["<b>return</b> result"]
 
    classDef start fill:#f5efe1,stroke:#6a8a4f,stroke-width:2px,color:#1a1915;
    classDef decision fill:#fdecd3,stroke:#c2410c,stroke-width:2px,color:#1a1915;
    classDef action fill:#e7efd9,stroke:#587640,stroke-width:2px,color:#1a1915;
    class S start
    class L,C,LR,RR decision
    class K,PL,PR,O action
  • Start

    Empty result list; unpack the removal range.

  • Iterate

    Walk each interval `[s, e]`.

  • No-overlap test

    `e ≤ rm_s` (entirely before) OR `s ≥ rm_e` (entirely after).

  • Keep

    Push the interval unchanged.

  • Left remnant?

    `s < rm_s` — part of the interval is left of the removal zone.

  • Right remnant?

    `e > rm_e` — part of the interval is right of the removal zone.

Comments

Comments are disabled in this environment. Set PUBLIC_GISCUS_REPO, PUBLIC_GISCUS_REPO_ID, and PUBLIC_GISCUS_CATEGORY_ID to enable.