dataframe-core-2.4.0.0: Core data structures for the dataframe library.
Safe HaskellNone
LanguageHaskell2010

DataFrame.Internal.PackedText

Description

Packed-text payload + byte-slice primitives. A PackedTextData shares one UTF-8 byte buffer across all rows of a string column, with n+1 row offsets, so no per-row Text header is materialized until decode is demanded. Offsets and selection vectors are stored Int32 whenever their values fit (Arrow-style), halving the per-row footprint of large string columns.

Synopsis

Documentation

data PackedTextData Source #

A shared UTF-8 byte buffer plus n+1 row offsets (base row r spans bytes [offsets!r, offsets!(r+1))); validity lives in the column's bitmap. ptSel is an optional selection layer letting a gatherjoinsort result share the buffer.

ptCanonicalSel marks a selection that is a canonical dictionary encoding: equal byte slices always map to the same base row (codes). Set by dictionary compaction; preserved by gather/take over an already-canonical selection (a row keeps its code); False for a gather over an unselected base, where two logical rows can select different but equal-byted base rows. Grouping keys on codes directly when it holds.

data PackedOffsets Source #

Row byte-offsets, physically Int32 when every value fits (total buffer bytes < 2^31) and Int otherwise. Values are non-negative byte positions.

Constructors

Offs32 !(Vector Int32) 
Offs64 !(Vector Int) 

data PackedSel Source #

A selection layer mapping logical rows to base rows; -1 marks an invalid/null row. Int32 when the base row count fits.

Constructors

Sel32 !(Vector Int32) 
Sel64 !(Vector Int) 

offAt :: PackedOffsets -> Int -> Int Source #

Offset at index i, widened to Int.

offCount :: PackedOffsets -> Int Source #

Number of offset entries (row count + 1).

selAt :: PackedSel -> Int -> Int Source #

Base row for logical row i (may be -1).

mkPackedContiguous :: Array -> Vector Int -> PackedTextData Source #

Build a contiguous packed payload (no selection): the freeze-path shape.

mkPackedContiguous32 :: Array -> Vector Int32 -> PackedTextData Source #

mkPackedContiguous from offsets already produced at Int32 width.

mkOffsets :: Vector Int -> PackedOffsets Source #

Narrow an Int offset vector when the final offset (total bytes) fits.

mkSel :: Int -> Vector Int -> PackedSel Source #

Narrow an Int base-row vector (-1 sentinels allowed) when the base row count fits in Int32.

packedGather :: Vector Int -> PackedTextData -> PackedTextData Source #

Reindex a packed payload by a selection vector, sharing the byte buffer; logical row i becomes base row indices!i. A negative or out-of-range index decodes to the empty slice. Composes with an existing selection; canonicality survives composition (a kept row keeps its code) but not a first selection over the unselected base.

packedTake :: Int -> PackedTextData -> PackedTextData Source #

Take the first k logical rows, sharing the byte buffer via a capped selection layer. O(k), no byte copy or decode — cheap take/display on a large packed column.

packedRowOffsets :: PackedTextData -> Maybe (Array, PackedOffsets) Source #

The shared buffer + contiguous n+1 offsets when the payload is the unselected base; a selected (gathered) payload returns Nothing (its rows are non-contiguous). Lets contiguous consumers skip the selection indirection.

packedLength :: PackedTextData -> Int Source #

Row count: length sel when selected, else length offsets - 1.

packedSlice :: PackedTextData -> Int -> (Array, Int, Int) Source #

Raw byte slice for logical row i: (buffer, offset, length). The hot accessor.

packedIndexText :: PackedTextData -> Int -> Text Source #

On-demand single Text for row i, using the same validate-or-lenient decode as the freeze path so output is bit-identical.

sliceEqBytes :: Array -> Int -> Int -> Array -> Int -> Int -> Bool Source #

Byte-wise equality of two slices. UTF-8 is injective on valid scalar sequences and lenient decode is deterministic, so this agrees with Text's == on the decoded values.

sliceCmpBytes :: Array -> Int -> Int -> Array -> Int -> Int -> Ordering Source #

Unsigned byte-lexicographic comparison (memcmp semantics). For well-formed UTF-8 this matches compare exactly, since UTF-8 byte order equals codepoint order for all valid scalars.