-
Notifications
You must be signed in to change notification settings - Fork 4
/
cs256_example.clj
30 lines (26 loc) · 980 Bytes
/
cs256_example.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns aatree.cs256-example
(:require [aatree.core :refer :all]
[aatree.nodes :refer :all])
(:import (java.nio ByteBuffer)
(java.io File)))
(set! *warn-on-reflection* true)
(def opts (lazy-opts))
(def empty-set (new-sorted-set opts))
(let [ls1 (conj empty-set :dog :cat :rabbit)
bb-len (+ (byte-length ls1) 32)
^ByteBuffer bb (ByteBuffer/allocate bb-len)
_ (put-aa bb ls1)
^ByteBuffer csbb (.flip (.duplicate bb))
cs (compute-cs256 csbb)]
(put-cs256 bb cs)
(.flip bb)
(file-save bb (File. "cs245-example.lazy")))
(let [^ByteBuffer bb (file-load (File. "cs245-example.lazy"))
csp (- (.limit bb) 32)
^ByteBuffer csbb (.limit (.duplicate bb) csp)
cs (compute-cs256 csbb)
ocs (get-cs256 (.position (.duplicate bb) csp))
lv2 (if (= cs ocs)
(load-sorted-set bb opts)
(throw (java.lang.Exception. "Checksum does not match")))]
(println lv2)); -> #{:cat :dog :rabbit}