Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

soa

clojure structure of arrays data type

clojars

[selfsame/soa "0.6-SNAPSHOT"]

Soa graphs provide lower memory usage for collections of homogeneous data.

Briefly, instead of a vector of maps

[{:a1, :b2} {:a3, :b4}]

they're a map of vectors.

{:a [13]
:b [24]}

usage

soa.core/Graph behaves like a vector, and maintains the internal SoA map.

(require 'soa.core)
(graph [{:a1}{:b2}])
;#soa/graph [{:a 1, :b nil}{:a nil, :b 2}]
(.-rec g)
;{:a [1 nil], :b [nil 2]}
(into g g)
;#soa/graph [{:a 1, :b nil}{:a nil, :b 2}{:a 1, :b nil}{:a nil, :b 2}]

The introduction of novel keys affects all items.

(conj g {:c3})
;#soa/graph [{:a 1, :b nil, :c nil}{:a nil, :b 2, :c nil}{:a nil, :b nil, :c 3}]

iterating graphs returns instances of soa.core/Node, a wrapper for the graph and index. Nodes behave like maps.

(first g)
;#soa/node {:a 1, :b nil}
(.-index (first g))
;0
(map:a g)
;(1 nil)
(soa.core/gget g 0)
;{:a 1, :b nil}

Use gupdate and gassoc to alter a graph.

(gupdate g 0:b dec)
;#soa/graph [{:a 1, :b -1}{:a nil, :b 2}]
(gassoc g 1:z3)
;#soa/graph [{:a 1, :b nil, :z nil}{:a nil, :b 2, :z 3}]

About

clojure Structure of Arrays data type

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages