Skip to content

Commit 9f6936f

Browse files
committed
Merge branch 'master' of github.com:Pyknic/immutable-array
2 parents 6c8df96 + 4736469 commit 9f6936f

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Immutable Array
2+
[![Javadocs](http://javadoc.io/badge/com.github.pyknic/immutable-array.svg)](http://javadoc.io/doc/com.github.pyknic/immutable-array)
3+
4+
Read-only primitive Java arrays backed by Direct Buffers and indexed using 64-bit indexes
5+
6+
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:
7+
8+
* Special implementation for empty arrays
9+
* Small arrays are backed by an OnHeap array (regular `long[]`, `int[]`, etc)
10+
* Medium sized arrays are backed by a single `DirectBuffer`
11+
* Very large arrays (more than 2^26 elements) are backed by a number of direct buffers
12+
* If all values fit a smaller primitive, they will be warped (`long` to `int`, `int` to `short` etc)
13+
14+
## Features
15+
* 64-bit indexing
16+
* Thread-safe (after build() has been called)
17+
* Immutability using a Builder pattern
18+
* Booleans are stored as efficient bitmaps
19+
* Backing structure is decided depending on the data
20+
* Allocated buffers are cleared as soon as they are no longer used (no need to wait for GC)
21+
22+
## Supported Types
23+
The following interfaces are part of the API:
24+
* `BooleanImmutableArray`
25+
* `ByteImmutableArray`
26+
* `DoubleImmutableArray`
27+
* `FloatImmutableArray`
28+
* `IntImmutableArray`
29+
* `LongImmutableArray`
30+
* `ShortImmutableArray`
31+
32+
## Example
33+
```java
34+
LongImmutableArray array = LongImmutableArray.builder()
35+
.append(5)
36+
.append(100_232)
37+
.append(-32)
38+
.build();
39+
```
40+
41+
If all values follow the same pattern, they can be compressed upon build.
42+
```java
43+
LongImmutableArray array = LongImmutableArray.builder()
44+
.append(1)
45+
.append(2)
46+
.append(3)
47+
.build(); // Will be backed internally by a `byte[]` of length 3
48+
```
49+
50+
## Usage
51+
Add the following to your `pom.xml`-file. The library has no external dependencies.
52+
```xml
53+
<dependency>
54+
<groupId>com.github.pyknic</groupId>
55+
<artifactId>immutable-array</artifactId>
56+
<version>1.0.0</version>
57+
</dependency>
58+
```
59+
60+
## License
61+
This project is available under the [Apache 2 license](http://www.apache.org/licenses/LICENSE-2.0).

0 commit comments

Comments
 (0)