\Drupal\strata\Codec\Dictionary DictionaryRef

Names one version of one realm's dictionary.

Every frame compressed against a dictionary records this id, and a frame that cannot name its dictionary cannot be decoded - which makes a dictionary the one kind of object a prune must never collect while any live frame references it.

Versioned rather than mutable. Retraining produces a new version and leaves the old one in place, because the frames written against it are still there and still have to open.

Summary

Methods
Properties
Constants
__construct
id
key
parse
jsonSerialize
realm
version
address
bytes
source
ratio
samples
trainedAt
PREFIX
RAW
TRAINED
No protected methods found
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Constant

PREFIX

PREFIX = 'dicts'

Key prefix dictionaries are stored under.

RAW

RAW = 'raw'

A dictionary built by concatenating samples.

Zstd accepts any byte string as a raw content dictionary, and on a self-similar corpus it beats a trained one outright: measured 11.64x against 8.42x on 200 entity payloads.

TRAINED

TRAINED = 'trained'

A dictionary built by the zstd trainer.

Wins on a diverse corpus - measured 5.42x against 4.96x on 400 mixed payloads - and needs the zstd binary, since no PHP extension exposes the training API.

Properties

$realm

$realm : string

Type

string

$version

$version : int

Type

int

$address

$address : string

Type

string

$bytes

$bytes : int

Type

int

$source

$source : string

Type

string

$ratio

$ratio : float

Type

float

$samples

$samples : int

Type

int

$trainedAt

$trainedAt : int

Type

int

Methods

__construct()

__construct(string  $realm, int  $version, string  $address, int  $bytes = 0, string  $source = \self::RAW, float  $ratio = 1.0, int  $samples = 0, int  $trainedAt = 0) : mixed

Constructs a reference.

Parameters

string $realm

Realm value the dictionary was trained for.

int $version

Version, counting from one.

string $address

Content address of the dictionary bytes.

int $bytes

How large the dictionary is.

string $source

Either RAW or TRAINED.

float $ratio

The compression ratio measured on the samples it was scored against, so the UI can show what the dictionary is worth rather than asserting that it helps.

int $samples

How many samples it was built from.

int $trainedAt

Unix seconds.

Throws

\InvalidArgumentException

When the realm is empty, the version is below one, or the address is not a digest.

Returns

mixed —

id()

id() : string

The identifier a frame records.

Returns

string —

Something such as "entity:3".

key()

key() : string

The object key the dictionary lives at.

Returns

string —

The key.

parse()

parse(string  $id) : array{realm: string, version: int}|null

The realm and version an id names.

Parameters

string $id

An id in the form produced by DictionaryRef::id().

Returns

array{realm: string, version: int}|null —

The parts, or NULL when the id is not one of ours.

jsonSerialize()

jsonSerialize() : array<string,mixed>

{@inheritdoc}

Returns

array

The reference as data.