From de783dceaee4d3f00c8a66bd5bc1f6076b3703e5 Mon Sep 17 00:00:00 2001 From: Bill Oley Date: Tue, 30 Jan 2018 11:27:36 -0500 Subject: [PATCH] closes #12 - Create copy constructors for LongArrayOutput and ByteBufferBitOutput --- .../compression/gorilla/ByteBufferBitOutput.java | 14 ++++++++++++++ .../ts/compression/gorilla/LongArrayOutput.java | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/fi/iki/yak/ts/compression/gorilla/ByteBufferBitOutput.java b/src/main/java/fi/iki/yak/ts/compression/gorilla/ByteBufferBitOutput.java index 29ae366..b1f4989 100644 --- a/src/main/java/fi/iki/yak/ts/compression/gorilla/ByteBufferBitOutput.java +++ b/src/main/java/fi/iki/yak/ts/compression/gorilla/ByteBufferBitOutput.java @@ -21,6 +21,20 @@ public ByteBufferBitOutput() { this(DEFAULT_ALLOCATION); } + /* + * Creates a deep copy of this object + */ + public ByteBufferBitOutput(ByteBufferBitOutput other) { + ByteBuffer otherBB = other.getByteBuffer(); + this.bb = ByteBuffer.allocateDirect(otherBB.capacity()); + otherBB.flip(); + this.bb.put(otherBB); + this.bb.limit(bb.capacity()); + otherBB.limit(otherBB.capacity()); + this.b = other.b; + this.bitsLeft = other.bitsLeft; + } + /** * Give an initialSize different than DEFAULT_ALLOCATIONS. Recommended to use values which are dividable by 4096. * diff --git a/src/main/java/fi/iki/yak/ts/compression/gorilla/LongArrayOutput.java b/src/main/java/fi/iki/yak/ts/compression/gorilla/LongArrayOutput.java index 5872d79..0c2ab40 100644 --- a/src/main/java/fi/iki/yak/ts/compression/gorilla/LongArrayOutput.java +++ b/src/main/java/fi/iki/yak/ts/compression/gorilla/LongArrayOutput.java @@ -1,5 +1,7 @@ package fi.iki.yak.ts.compression.gorilla; +import java.util.Arrays; + /** * An implementation of BitOutput interface that uses on-heap long array. * @@ -35,6 +37,15 @@ public class LongArrayOutput implements BitOutput { } } + /* + * Creates a deep copy of this object + */ + public LongArrayOutput(LongArrayOutput other) { + this.longArray = Arrays.copyOf(other.longArray, other.longArray.length); + this.position = other.position; + this.lB = other.lB; + this.bitsLeft = other.bitsLeft; + } /** * Creates a new ByteBufferBitOutput with a default allocated size of 4096 bytes.