Skip to content

selfsame/soa

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

[{:a 1, :b 2} 
 {:a 3, :b 4}]

they're a map of vectors.

{:a [1 3]
 :b [2 4]}

usage

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

(require 'soa.core)

(graph [{:a 1}{:b 2}])
;#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 {:c 3})
;#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 :z 3)
;#soa/graph [{:a 1, :b nil, :z nil}{:a nil, :b 2, :z 3}]

About

clojure Structure of Arrays data type

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published