class

Scroll::SortWindow

Inherits Reference < Object

Maintains the top-N lines of the stream by the sort order, for --sort mode.

Rather than accumulate every line, it keeps at most capacity entries, sorted in display order (least-shown first, most-shown last). Each new line is keyed once; when the window is full and the new line is not greater than the current lowest kept entry, it is skipped with a single comparison. Otherwise it replaces the lowest entry and the window is re-sorted. So memory stays bounded at N and the common case (a line that does not make the cut) is O(1).

The window's contents are already in display order, so the render path draws snapshot directly — no further sorting needed.

Constants

NEWLINE = '\n'.ord.to_u8

Constructors

new(capacity : Int32, sorter : Sorter)
Source

Instance methods

feed(bytes : Bytes) : Nil

Feed a chunk of raw bytes; each complete line is offered to the window.

Source
finalize(include_trailing : Bool = false) : Nil

At EOF, optionally offer a trailing newline-less line (the --final option).

Source
size
Source
snapshot

The kept lines in display order (least-shown first). Size is at most N.

Source

Nested types