GizStackGizStack
View .mdOpen in ChatGPTOpen in Claude

gizlang/columns

encodings of one column of values, read back in parts. FSST compresses strings so that any range of them decodes alone; ALP turns doubles into small integers for bit packing. Stream compression is gizlang/compress.

gizlang
import * as Columns from "gizlang/columns";

Types

FsstHead

gizlang
type FsstHead = { size: i64; count: i64; table: bytes; lengths: Vec<i64>; ends: Vec<i64>; at: i64; }

An FSST block's head: its decoded size, each symbol in 8 bytes of table and its length, where each frame's codes end (from the first code) and where the codes start (at).

  • size: i64
  • count: i64
  • table: bytes
  • lengths: Vec<i64>
  • ends: Vec<i64>
  • at: i64

Alp

gizlang
type Alp = { exponent: i64; digits: Vec<i64>; at: Vec<i64>; exceptions: Vec<f64>; }

A vector of doubles as ALP integers: digits[i] / 10^exponent, except at the positions at, whose values are exceptions.

  • exponent: i64
  • digits: Vec<i64>
  • at: Vec<i64>
  • exceptions: Vec<f64>

Functions

fsstEncode

gizlang
function fsstEncode(data: bytes): bytes

data compressed by FSST: its length (u64), the symbol table (a count, then each symbol's length and bytes), the frames (their count, u32, and where each one's codes end, u64 from the first code) and the codes. A frame holds the codes of FSST_FRAME bytes of the input: a code carries no state to the next, so each frame decodes alone, and a read of a few strings decodes only their frames (fsstDecodeFrames). Sizes and contents of the input are kept exactly.

Effects: fail, alloc.

fsstHead

gizlang
function fsstHead(data: bytes): FsstHead throws string

The head of the FSST block DATA starts with; DATA may end where the codes start.

Effects: fail, alloc.

fsstFrames

gizlang
function fsstFrames(head: FsstHead, at: i64): Vec<i64>

Where each frame of HEAD's codes starts when they lie in one piece from AT (fsstDecodeFrames).

Effects: fail, alloc.

fsstDecode

gizlang
function fsstDecode(data: bytes): bytes throws string

The bytes fsstEncode compressed, or an error for data it did not write.

Effects: fail, alloc.

fsstDecodeAll

gizlang
function fsstDecodeAll(head: FsstHead, data: bytes, at: i64): bytes throws string

The bytes of HEAD's codes, which lie in one piece from AT of DATA.

Effects: fail, alloc.

fsstDecodeRanges

gizlang
function fsstDecodeRanges(data: bytes, from: Vec<i64>, to: Vec<i64>): bytes throws string

The bytes [FROM[k], TO[k]) of fsstDecode(DATA) for each k, joined: FROM ascending, the ranges apart.

Effects: fail, alloc.

fsstDecodeFrames

gizlang
function fsstDecodeFrames(head: FsstHead, codes: bytes, frames: Vec<i64>, from: Vec<i64>, to: Vec<i64>): bytes throws string

The bytes [FROM[k], TO[k]) that HEAD's codes decode to, for each k, joined: FROM ascending, the ranges apart. Frame f's codes are at FRAMES[f] of CODES (-1: not read; a range in it is an error). Each range starts at the frame that holds its first byte, so it decodes at most a frame more than its own bytes: a 12-hour filter's 682 request traces walked every code before them, 2.4 s for blocks of 40 MB.

Effects: fail, alloc.

alpEncode

gizlang
function alpEncode(v: Vec<f64>): Alp

The values of V in ALP form: integers at a decimal scale, with the values that do not fit kept apart.

Effects: fail, alloc.

alpDecode

gizlang
function alpDecode(a: Alp): Vec<f64> throws string

The doubles of a, or an error for an exponent or exception position out of range.

Effects: fail, alloc.

Constants

FSST_FRAME

gizlang
const FSST_FRAME: i64 = 8192

The input bytes of a frame of FSST codes (fsstEncode): 8 KiB, so a string read alone decodes a few KiB, and its frame's entry (8 bytes) adds a thousandth to the input.