tech.v3.datatype.packing

Implements the 'packed/unpacked' concept in datatype. This allows us to take objects like LocalDate's and store them in int32 storage which dramatically decreases their size.

add-packed-datatype!

(add-packed-datatype! object-cls object-datatype packed-datatype primitive-datatype pack-fn unpack-fn)

Add a datatype that you wish to be packed into a single scalar numeric value.

buffer-packing-pair

(buffer-packing-pair datatype)

If datatype is a packed datatype, return a pair of functions, unpacking-read and packing-write. unpacking-read reads the appropriate datatype and calls the datatype's unpack fn on it. packing-write packs the input and writes it to the appropriate place. Note that in this case those functions take the buffer and the index. returns {:unpacking-read :packing-write}

pack

(pack item)

Pack a scalar, iterable, or a reader into a new scalar, iterable or a reader. If this isn't a packable datatype this is a no-op.

pack-datatype

(pack-datatype datatype)

Returns the packed datatype for this unpacked datatype.

pack-scalar

(pack-scalar value dtype)

Pack a scalar value. Dtype is provided so nil can be packed.

Example:

tech.v3.datatype.packing> (pack-scalar nil :local-date)
-2147483648
tech.v3.datatype.packing> (pack-scalar (java.time.LocalDate/now) :local-date)
18775

packed-datatype?

(packed-datatype? datatype)

Returns true of this is a datatype that could be unpacked.

packing-pair

(packing-pair dtype)

If datatype is a packed datatype, return a pair of functions of the form pack-fn unpack-fn.

unpack

(unpack item)

Unpack a scalar, iterable, or a reader. If the item is not a packed datatype this is a no-op.

unpack-datatype

(unpack-datatype datatype)

Returns the unpacked datatype for this packed datatype.

unpacked-datatype?

(unpacked-datatype? datatype)

Returns true if this is a datatype that could be packed.

wrap-with-packing

(wrap-with-packing datatype src-fn)