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> (define-datatype! :vec3 [{:name :x :datatype :float32}
{:name :y :datatype :float32}
{:name :z :datatype :float32}])
Syntax error compiling at (*cider-repl cnuernber/dtype-next:localhost:36129(clj)*:47:7).
Unable to resolve symbol: define-datatype! in this context
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}
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-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-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
.
offset-of
(offset-of struct-dtype-or-struct-def property-vec)
Returns a tuple of [offset dtype].
struct-datatype?
(struct-datatype? datatype)
Returns true of this datatype denotes a struct datatype.