Skip to content
Bill La Forge edited this page Oct 21, 2015 · 9 revisions

API

When configured with aatree.core.lazy-opts, the Sorted Set created by the aatree.core.new-sorted-set function is an empty AASet configured to support lazy deserializng and reserializing operations:

  • (aatree.core.byte-length lazy-set) - Returns the number of bytes needed to hold the serialized sorted set.
  • (aatree.core.put-aa ByteBuffer lazy-sorted-set) - Serializes the sorted set into the byte buffer. Nodes are serialized only when a node or parent node has been updated.
  • (aatree.core.load-sorted-set ByteBuffer opts) - Returns a sorted set with internal references to the byte buffer. Deserialization will be performed lazily, as needed.
(ns aatree.lazy-sorted-set-examples
  (:require [aatree.core :refer :all])
  (:import (java.nio ByteBuffer)))

(set! *warn-on-reflection* true)

(def opts (lazy-opts))

(def empty-set (new-sorted-set opts))
(println (byte-length empty-set)); -> 1

(def ls1 (conj empty-set :dog :cat :rabbit))
(println ls1); -> #{:cat :dog :rabbit}

(def ls1-len (byte-length ls1))
(println ls1-len); -> 85

(def ^ByteBuffer bb (ByteBuffer/allocate ls1-len))
(put-aa bb ls1)
(.flip bb)
(def ls2 (load-sorted-set bb opts))
(println ls2); -> #{:cat :dog :rabbit}
Clone this wiki locally