Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add java-api for LByteArray

  • Loading branch information...
commit e996a6a6ee047adec771cd40f03251733280c257 1 parent 0d0e5ad
Taro L. Saito authored
39 src/main/java/xerial/larray/java/LArray.java
View
@@ -0,0 +1,39 @@
+package xerial.larray.java;
+
+/**
+ * Java interface of LArray
+ * @author Taro L. Saito
+ */
+public interface LArray<A> {
+
+// /**
+// * Get an element at the given index
+// * @param i index
+// * @return element
+// */
+// public A get(long i);
+//
+// /**
+// * Set the element at the specified index
+// * @param i index
+// * @param v value to set
+// * @return new value that is set
+// */
+// public A set(long i, A v);
+
+ /**
+ * Array size
+ */
+ public long size();
+
+ /**
+ * Release the memory resource held by this LArray
+ */
+ public void free();
+
+ /**
+ * Byte length of this LArray
+ * @return
+ */
+ public long byteLength();
+}
45 src/main/java/xerial/larray/java/LByteArray.java
View
@@ -0,0 +1,45 @@
+package xerial.larray.java;
+
+import xerial.larray.Memory;
+
+/**
+ * @author Taro L. Saito
+ */
+public class LByteArray implements LArray<Byte> {
+
+ private final long size;
+ private final Memory m;
+
+ public LByteArray(long size) {
+ this(size, MemoryAllocator.defaultAllocator.allocate(size));
+ }
+
+ LByteArray(long size, Memory m) {
+ this.size = size;
+ this.m = m;
+ }
+
+ public byte get(long i) {
+ return m.getByte(i);
+ }
+
+ public byte set(long i, byte v) {
+ m.putByte(i, v);
+ return v;
+ }
+
+ @Override
+ public long size() {
+ return size;
+ }
+
+ @Override
+ public void free() {
+ m.free();
+ }
+
+ @Override
+ public long byteLength() {
+ return size;
+ }
+}
10 src/main/java/xerial/larray/java/MemoryAllocator.java
View
@@ -0,0 +1,10 @@
+package xerial.larray.java;
+
+import xerial.larray.DefaultAllocator;
+
+/**
+ * @author Taro L. Saito
+ */
+class MemoryAllocator {
+ static xerial.larray.MemoryAllocator defaultAllocator = new DefaultAllocator();
+}
Please sign in to comment.
Something went wrong with that request. Please try again.