tech.v3.datatype.struct
Structs are datatypes composed of primitive datatypes or other structs.
Similar to records except they do not support string or object columns,
only numeric values. They have memset-0 initialization, memcpy copy
semantics. For correct equals, hashing, convert struct into a normal
persistent map via into
.
Example:
user> (require '[tech.v3.datatype :as dtype])
nil
user> (require '[tech.v3.datatype.struct :as dt-struct])
nil
user> (dt-struct/define-datatype! :vec3 [{:name :x :datatype :float32}
{:name :y :datatype :float32}
{:name :z :datatype :float32}])
{:datatype-size 12,
:datatype-width 4,
:data-layout
[{:name :x, :datatype :float32, :offset 0, :n-elems 1}
{:name :y, :datatype :float32, :offset 4, :n-elems 1}
{:name :z, :datatype :float32, :offset 8, :n-elems 1}],
:layout-map
{:x {:name :x, :datatype :float32, :offset 0, :n-elems 1},
:y {:name :y, :datatype :float32, :offset 4, :n-elems 1},
:z {:name :z, :datatype :float32, :offset 8, :n-elems 1}},
:datatype-name :vec3}
user> (dt-struct/new-struct :vec3)
{:x 0.0, :y 0.0, :z 0.0}
user> (.put *1 :x 2.0)
nil
user> *2
{:x 2.0, :y 0.0, :z 0.0}
column-map
(column-map ary)
Given an array of structs, return a map that maps the property to a primitive buffer for that column. This is appropriate for passing directly into ->dataset.
datatype->host-type
(datatype->host-type dt)
Structs allow size-t, offset-t, and pointer datatypes so this is an ovveride you have to use when working with them.
datatype-width
(datatype-width datatype)
Return the width or the of a datatype. The width dictates what address the datatype can start at when embedded in another datatype.
define-datatype!
(define-datatype! datatype-name datatype-seq)
Define a new struct datatype.
datatype-name
- keyword datatype name.datatype-seq
- Sequence of maps with the keys{:name :datatype}
which describe the new datatype.
Returns the new struct defintion.
Example:
(define-datatype! :vec3 [{:name :x :datatype :float32}
{:name :y :datatype :float32}
{:name :z :datatype :float32}])
(define-datatype! :segment [{:name :begin :datatype :vec3}
{:name :end :datatype :vec3}])
inplace-new-array-of-structs
(inplace-new-array-of-structs datatype buffer options)
(inplace-new-array-of-structs datatype buffer)
Create an array of structs from an existing buffer. Buffer must be an exact multiple of the size of the desired struct type.
inplace-new-struct
(inplace-new-struct datatype backing-store _options)
(inplace-new-struct datatype backing-store)
Create a new struct in-place in the backing store. The backing store must either be convertible to a native buffer or a byte-array.
Returns a new Struct datatype.
new-array-of-structs
(new-array-of-structs datatype n-elems options)
(new-array-of-structs datatype n-elems)
Create a new array of structs from new memory.
Options:
:container-type
- passed directly into make-container, defaults to:jvm-heap
. For native heap there is a further option of:resource-type
which can be on of the tech.v3.resource track types of nil, :stack, :gc, or :auto. Nil means this memory will either live for the lifetime of the process or need to be freed manually. For more options see tech.v3.datatype.native-buffer/malloc.
new-struct
(new-struct datatype options)
(new-struct datatype)
Create a new struct. By default this will use a byte array (:jvm-heap memory). Returns a new struct.
Options are passed into dtype/make-container so container-specific options apply.
Options:
:container-type
- Defaults to:jvm-heap
but often you want:native-heap
:resource-type
- If:native-heap
:container-type
is chosen, this dictates the resource strategy. Options are the same astech.v3.datatype.native-buffer/malloc
.
struct-datatype?
(struct-datatype? datatype)
Returns true of this datatype denotes a struct datatype.