Skip to content

Commit e0511fa

Browse files
author
Emil Forslund
authored
Create README.md
1 parent 141fe81 commit e0511fa

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

README.md

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

0 commit comments

Comments
 (0)