Lets look at the upd function that is part of the map benchmark I posted
above...
(defn upd [m i]
(let [m1 (assoc m i (- i))
bb (ByteBuffer/allocate (lazy-byte-length m1))]
(lazy-write m1 bb)
(.flip bb)
(load-aamap bb)))
And its invocation...
(def lazy-m (reduce upd lazy-map (range updates)))
Here we see that upd is called repeatedly by the reduce, its first argument
being the result of the previous call to upd.
m1 (assoc m i (- i)
The above is in the upd function. It uses assoc to create an updated copy of
the map.
bb (ByteBuffer/allocate (lazy-byte-length m1)
bb is a byte buffer with a capacity equal to the length of the serialized
contents of m1.
(lazy-write m1 bb)
(.flip bb)
(load-aamap bb))
Now we write the updated map to the byte buffer, flip it, and then create a new
map from the byte buffer. This new map is then passed back to the reduce method
which calls upd again with the new/updated map.
This usage, being a benchmark, is a bit atypical as we are serializing the
contents of the map with each update and then loading the result back into a
new map. But. You can see that the map works like the standard clojure map, and
only it works additionally with the lazy-byte-length, lazy-write and aamap-load
functions. The underlying tree is not normally accessed by the application
developer, just as the red/black tree used to implement clojure sorted maps are
not normally accessed by the application developer.
So aamap is used just like sorted-map, except for the additional capability of
being able to quickly load it from and write it to a ByteBuffer. And, like a
sorted-map, you can also specify a comparator for ordering the keys, though the
comparator would be passed in the optional opts map on the aamap-load function
or in the create-lazy-aamap function.
The full API is given here:
https://github.com/laforge49/aatree/blob/master/src/aatree/core.clj (Still need
to add doc strings though.)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.