Skip to content

vtf textbuffer chunkiter

srccircumflex edited this page Apr 24, 2023 · 4 revisions

↑ vtf-textbuffer

chunkiter

class chunkiter.ChunkIter(Reversible)

[ ADVANCED USAGE ]

An object to iterate through defined areas of the buffer across the boundaries to the swap. Return pairs of a _Row and the associated coordinate on iteration. If a chunk is needed for the current coordinate, it is temporarily loaded into memory as a ChunkBuffer; also, if currently loaded lines need to be read from the TextBuffer, an image is loaded into memory as a ChunkBuffer; thus, the rows in the iteration are always a part of a ChunkBuffer.

The coordinates in the iteration are from the coordinates passed at initialization parsed components of a chunk catalog which is realized as OrderedDict (ChunkIter.ParsedCoords). By this the adjusted coordinates to concerning chunks are stored.

Coordinates can be expressed and typed in different ways. The coordinate data must be defined as a sorted list of data points [ <int>, ... ] or as a sorted list of data ranges [ [<int>, <int>], ... ] (optional, by default it is iterated over the whole data).

To indicate what type of metadata it is, can be specified:
  • "data": orientate to the data points in rows. sorted_coord must be formulated with data points for this.
  • "content": orientate to the content data points in rows. sorted_coord must be formulated with content points for this.
  • "row": orientate to the row numbers. sorted_coord must be formulated with the row numbers for this.
  • "line": orientate to the line numbers in rows (compared to a row, a line is defined as the data between two line breaks + final line break). sorted_coord must be formulated with the line numbers for this.
Depending on how or if data of rows are edited during iteration, a mode of metadata adjustment must be parameterized:
  • "memory": allows editing the rows in chunk buffers without affecting the actual chunks (sandbox mode).
  • "live metas": overwrites the chunk slot after leaving a ChunkBuffer and directly adjusts the metadata of all chunks around the edit.
  • "shadow metas": also overwrites the chunkslot after leaving a ChunkBuffer but writes the differences in the chunks separately, the actual metadata is then finally adjusted when leaving the iterator.

ChunkIter is itself a reversible iterator, for this the mode is specified at creation. But the generator can also be obtained via the methods iter, reversed or coordreversed; in this case the mode can be rewritten again. If the ChunkIter is to be started directly as a coordreversed-iterator (is not reversible), the mode must be selected correspondingly from "coords reversed + m", "coords reversed + l" or "coords reversed + s". The generator then orients itself to reversed coordinates and iterates forward through the rows.

About the metadata and editing in the iteration:

Note that the rows in the ChunkBuffer are selected during iteration based on the coordinates. So if data of the current ChunkBuffer is edited and the rows contained in it are indexed, this may affect the selection of the following rows based on the original coordinates when iterating forward. If the "live metas" mode is used for editing in a forward iteration, this effect will additionally affect the chunk level.

At the end or break of the iteration, ChunkIter takes care of chunks that have become empty due to editing and removes them from the _Swap.

For the execution of functions within the ChunkIter during the iteration, these may be passed depending on the situation:
  • chunk_enter: executed whenever a new ChunkBuffer is created and entered; gets the ChunkBuffer and the parsed coordinates.
  • chunk_exit: is always executed when a ChunkBuffer is exited; gets the ChunkBuffer.
  • coord_enter: executed when a coordinate starts; gets the row and coordinate (coordinate is only None if no coordinates were passed).
  • coord_continue: executed when a coordinate is continued, and gets the row and coordinate.
  • coord_break: is executed at the interruption by a chunk boundary or at the termination of a coordinate and gets the current ChunkBuffer and the coordinate (never executed if no coordinates were passed).

class ParsedCoords(OrderedDict)

The adjusted ranges for a chunk are stored as a list or None under the chunk position number. If a coordinate spans multiple chunks, the original is stored in the adjusted values of the first affected chunk, if entire chunks are affected until the end of the coordinate, None are used as value instead of the list, under the last affected chunk, an adjusted version of the original is included in the list of values (the start is then equal to the chunk data start).

ordered, reversed and coordreversed are sorting methods and return a list of items.

coordreversed is a method to sort the coordinates backwards but the respective chunks forwards.

parsed_coords: ParsedCoords[int | None, list[int] | list[list[int, int]] | None]

__init__(__buffer__, mode, sorted_coords=None, coord_type='d', chunk_enter=lambda *_: None, chunk_exit=lambda *_: None, coord_enter=lambda *_: None, coord_continue=lambda *_: None, coord_break=lambda *_: None)

coordreversed(mode=None) -> Generator[tuple[_Row, list[int, int] | int | None]]

Return a generator for the forward iteration in the coordinates but from backward coordinates.

iter(mode=None) -> Generator[tuple[_Row, list[int, int] | int | None]]

Return a generator for a forward iteration.

staticmethod pars_meta_coords(__buffer__, sorted_meta_coords, coord_type) -> ChunkIter.ParsedCoords

Parse sorted meta coordinates to a chunk catalog; Or sort out not applicable coordinates if swap is not initialized.

Coordinates can be defined as ranges [ [start, stop], ... ] or as data points [ point, ... ]

[+] __swap__.adjust

reversed(mode=None) -> Generator[tuple[_Row, list[int, int] | int | None]]

Return a generator for a backward iteration.

run() -> int

Run the iteration, return the number of iterations.

Date: 21 Dec 2022
Version: 0.1
Author: Adrian Hoefflin [srccircumflex]
Doc-Generator: "pyiStructure-RSTGenerator" <prototype>
Clone this wiki locally