From 3b065accbcb5a02ccf26f0b5e81a9808c6aeda21 Mon Sep 17 00:00:00 2001 From: Paula Gearon Date: Tue, 29 Sep 2020 22:14:59 -0400 Subject: [PATCH] fixed parameter passing --- src/asami/durable/block/bufferblock.clj | 18 +++++++++++------- test/asami/durable/block/test_blockfile.clj | 12 ++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/asami/durable/block/bufferblock.clj b/src/asami/durable/block/bufferblock.clj index 2d40de2..4a36cbe 100644 --- a/src/asami/durable/block/bufferblock.clj +++ b/src/asami/durable/block/bufferblock.clj @@ -7,11 +7,15 @@ ;; An implementation of Block that can have multiple readers, ;; but only a single writing thread (defrecord BufferBlock - [^ByteBuffer bb ^IntBuffer ib ^LongBuffer lb + [id + ^ByteBuffer bb ^IntBuffer ib ^LongBuffer lb ^ByteBuffer ro + size byte-offset int-offset long-offset] Block + (get-id [this] id) + (get-byte [this offset] (.get bb (+ byte-offset offset))) @@ -100,21 +104,21 @@ (defn- new-block "Internal implementation for creating a BufferBlock using a set of buffers. If lb is nil, then ib must also be nil" - [bb ib lb ro byte-offset] + [id bb ib lb ro size byte-offset] (assert (or (and ib lb) (not (or ib lb))) "int and long buffers must be provided or excluded together") (let [ib (or ib (-> bb .rewind .asIntBuffer)) lb (or lb (-> bb .asLongBuffer)) ro (or ro (.asReadOnlyBuffer bb)) int-offset (bit-shift-right byte-offset 2) long-offset (bit-shift-right byte-offset 3)] - (->BufferBlock bb ib lb ro byte-offset int-offset long-offset))) + (->BufferBlock id bb ib lb ro size byte-offset int-offset long-offset))) (defn ^BufferBlock create-block "Wraps provided buffers as a block" - ([size byte-offset byte-buffer ro-byte-buffer int-buffer long-buffer] - (new-block byte-buffer int-buffer long-buffer ro-byte-buffer size byte-offset)) - ([size byte-offset byte-buffer] - (new-block byte-buffer nil nil nil size byte-offset))) + ([id size byte-offset byte-buffer ro-byte-buffer int-buffer long-buffer] + (new-block id byte-buffer int-buffer long-buffer ro-byte-buffer size byte-offset)) + ([id size byte-offset byte-buffer] + (new-block id byte-buffer nil nil nil size byte-offset))) ;; The following functions are ByteBuffer specfic, diff --git a/test/asami/durable/block/test_blockfile.clj b/test/asami/durable/block/test_blockfile.clj index 2c3bf76..8144332 100644 --- a/test/asami/durable/block/test_blockfile.clj +++ b/test/asami/durable/block/test_blockfile.clj @@ -55,8 +55,8 @@ (deftest test-allocate (let [filename (util/temp-file "ualloc") - {:keys [block-file file]} (open-block-file filename test-block-size)] - (set-nr-blocks! block-file 1) + block-file (open-block-file filename test-block-size) + block-file (set-nr-blocks! block-file 1)] (try (let [blk (block-for block-file 0)] (is (not (nil? blk)))) @@ -68,7 +68,7 @@ (deftest test-write (let [file-str "bftest" filename (util/temp-file file-str) - {:keys [block-file file]} (open-block-file filename test-block-size) + block-file (open-block-file filename test-block-size) bf (set-nr-blocks! block-file 4) b (block-for bf 0) _ (put-string! b str0) @@ -89,7 +89,7 @@ (unmap bf) (cleanup) - (let [{:keys [block-file file]} (open-block-file filename test-block-size)] + (let [block-file (open-block-file filename test-block-size)] ;; did it persist @@ -107,8 +107,8 @@ (deftest test-performance (let [file-str "perftest" filename (util/temp-file file-str) - {:keys [block-file file]} (open-block-file filename test-block-size) - _ (clear! block-file) + block-file (open-block-file filename test-block-size) + block-file (clear! block-file) nr-blocks 100000 bf (set-nr-blocks! block-file nr-blocks)]