ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Registry.Json.Intern

Description

The first copy of each key and string that one document's retained values hold, found by the bytes the lexer read before any text is built. Keep one table per read and drop it when the read ends, so no table outlives the document it serves. The table hashes with SipHash-1-3 under a key drawn for its read, so upstream text cannot choose which names collide.

Synopsis

Names as read

data Name Source #

A member name or string as the lexer read it: plain ASCII bytes, or text decoded from escapes or UTF-8.

Constructors

Plain !ByteString 

decodedName :: Text -> Name Source #

A name decoded from escapes or UTF-8. Its bytes are encoded once, when first asked for.

foldName :: (ByteString -> a) -> (Text -> a) -> Name -> a Source #

Take a name as its plain ASCII bytes or as its decoded text.

nameText :: Name -> Text Source #

The name's text on an array of its own. Plain bytes are copied, so no text keeps its input chunk.

nameBytes :: Name -> ByteString Source #

The name's UTF-8 bytes. Plain bytes are the input's own, so hold them only for the current lookup.

The table

data InternTable Source #

One read's table and its entry count. Each entry's text is also its key, and each key carries its hash.

data SipKey #

SigHash Key

Constructors

SipKey !Word64 !Word64 

newTableKey :: IO SipKey Source #

A fresh key for one read's table, so no key outlives the table it seeds.

newInternTable :: SipKey -> [Text] -> InternTable Source #

A table for one document that keeps the values of the named members as read. Name the members whose values differ in every release or file, so they never enter the table.

data Entry Source #

One table entry: the shared text, its shared string value, whether a member's value is kept as read, and its index. Only a table makes one, so every index lies within its table.

entryText :: Entry -> Text Source #

The entry's shared text.

entryString :: Entry -> Value Source #

The entry's text as its shared string value.

entryKeeps :: Entry -> Bool Source #

Whether a member of this name keeps its value as read.

entryIndex :: Entry -> Int Source #

The entry's index, which lies within the table that made it.

data Interned Source #

The table's entry for a name, with the table that holds it.

Constructors

Interned !Entry !InternTable 

internName :: Name -> InternTable -> Interned Source #

The table's entry for a name. A name the table lacks gets an entry of its own text, which the returned table holds from then on.

tableTexts :: InternTable -> SmallArray Text Source #

Every entry's text in index order. Each index below the table's count holds exactly one entry.

sipHash :: Int -> Int -> SipKey -> ByteString -> Word64 Source #

SipHash with the given compression and finalisation rounds, from one to four each, over the message's little-endian words. The table uses SipHash-1-3.