Read-only primitive Java arrays backed by Direct Buffers and indexed using 64-bit indexes
Read-only primitive Java arrays backed by Direct Buffers and indexed using 64-bit indexes
The library uses a Builder Pattern for the array classes. When the builder is finalized, an appropriate implementation of the interface is choosen to fit the data. Here are some optimizations that are done upon build:
long[]
, int[]
, etc)DirectBuffer
long
to int
, int
to short
etc)The following interfaces are part of the API:
BooleanImmutableArray
ByteImmutableArray
DoubleImmutableArray
FloatImmutableArray
IntImmutableArray
LongImmutableArray
ShortImmutableArray
LongImmutableArray array = LongImmutableArray.builder()
.append(5)
.append(100_232)
.append(-32)
.build();
If all values follow the same pattern, they can be compressed upon build.
LongImmutableArray array = LongImmutableArray.builder()
.append(1)
.append(2)
.append(3)
.build(); // Will be backed internally by a `byte[]` of length 3
Add the following to your pom.xml
-file. The library has no external dependencies.
<dependency>
<groupId>com.github.pyknic</groupId>
<artifactId>immutable-array</artifactId>
<version>1.0.2</version>
</dependency>
Copyright 2016 Emil Forslund
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.