Skip to content

Commit 578add5

Browse files
authored
Merge pull request #13 from Abductcows/dev
v2.0.0
2 parents 8db6878 + 0df4b2e commit 578add5

File tree

8 files changed

+823
-450
lines changed

8 files changed

+823
-450
lines changed

README.md

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
1-
# Java BitArray
1+
# BitArray
22

33
[![Latest release][latest-release-shield]][latest-release-url]  
4-
[![Open Issues][open-issues-shield]][open-issues-url]  
5-
[![Contributors][contributors-shield]][contributors-url]
4+
[![Contributors][contributors-shield]][contributors-url]  
5+
[![Total alerts](https://img.shields.io/lgtm/alerts/g/Abductcows/java-bit-array.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Abductcows/java-bit-array/alerts/)  
6+
[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/Abductcows/java-bit-array.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Abductcows/java-bit-array/context:java)
67

7-
### TL;DR: Faster List<Boolean> than ArrayList with the same exact behaviour.
8+
### The cooler ArrayList\<Boolean\>
89
- [Documentation](https://abductcows.github.io/java-bit-array/gr/geompokon/bitarray/BitArray.html)
9-
- [Release](https://github.com/Abductcows/java-bit-array/releases/latest)
10+
- [Release](#getting-started)
1011
- [Benchmarks](https://github.com/Abductcows/bit-array-benchmarks)
11-
### Motivation
12-
This class is a replacement for the `ArrayList<Boolean>` type when working with its `List` interface. It boasts higher performance in add, remove and set operations and requires less memory for storing the same elements.
1312

14-
The BitArray is by all means an array; it is random access and all elements have contiguous indices at all times. Its behaviour is meant to be indistinguishable from ArrayList in order for programmers to be able to substitute it for the latter and benefit from its performance advantage.
13+
### Motivation
14+
This class was conceived as a replacement for the `ArrayList<Boolean>` type, when working with one of its interfaces. It boasts higher performance in CRUD operations and requires less memory to store the same elements. As its own type, it introduces new specialized methods that leverage its implementation to deliver more performance.
1515

16-
### Few details
17-
Internally the array stores the boolean elements in an array of long primitives. These long primitives essentially form a sequence of bits; their chained bit representation in 2's complement. Boolean elements are converted to and from their bit equivalent to perform insertions, deletions etc. With the appropriate bitwise operations new elements can be added at a specific index and elements already in the array can be shifted to preserve the previous order. Thanks to this "hack", element shifting and array resizing is much cheaper, all while the elements themselves occupy less space in memory.
16+
### Caveats
17+
- **No nulls:** The internal representation of the elements, namely the bits, have only 2 states, so null values cannot be accommodated. Null values will throw a NullPointerException.
18+
- **No references to the inserted objects are retained:** This should not concern you if you are using Java ≥ 9. But if for some twisted reason you are using new Boolean objects and == comparison, the Boolean you just put in could return as a different object. If so, this class is not for you.
1819

19-
### Thread safety
20-
The class is not currently thread-safe, I will look into it properly at some point. For the time being you can use `Collections.synchronizedList()`
20+
### Performance
21+
For the performance difference, check out the [benchmark repository](https://github.com/Abductcows/bit-array-benchmarks). It includes results from my runs and the benchmark files should you want to run them yourself. A general rule is that the performance margin widens as elements increase. Additionally, operations which move a lot of elements such as `add()/remove()` at the head scale even better than those which don't, such as `get()/set()`. Also, it can easily handle `INTEGER.MAX_VALUE` elements, but cannot hold more.
2122

22-
### Null values
23-
Unfortunately, due to the implementation I have not been able to accommodate null values in the array. Null insertions or updates will throw NullPointerException.
23+
### Thread safety / synchronization
24+
BitArray, being a List, is not inherently thread safe. It is also not synchronized, as it would harm performance. Synchronized access can be achieved as usual with [`Collections.synchronizedList(bitArray)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collections.html#synchronizedList(java.util.List))
2425

25-
### Performance
26-
For the performance difference, check out the [benchmark repository](https://github.com/Abductcows/bit-array-benchmarks). It includes results from my runs and the benchmark files should you want to run them yourself. A TLDR version is that it gets much faster the more the elements are in add/remove. The performance difference stems wholly from resizes and moves. For example, an insertion at random indices of 1000 elements with an initial capacity of 10 runs at 2x the speed. Same scenario but for 1.5M elements and the BitArray runs 13x faster. But for already resized arrays and insertions at the tail, the difference is miniscule. The numbers mentioned are quite conservative for safety. Also, it can easily handle `INTEGER.MAX_VALUE` elements, but cannot hold more.
26+
### Few implementation details
27+
Internally the array stores the boolean elements in an array of `long` primitives. These primitives essentially form a sequence of bits; their chained bit representation in 2's complement. Boolean elements are converted to and from their bit equivalent (i.e. `false ⟷ 0` and `true ⟷ 1`) to perform insertions, deletions etc. With the appropriate bitwise operations new elements can be added at a specific index and elements already in the array can be shifted to preserve the previous order. Thanks to that, element shifting and array resizing is much cheaper, all while the elements themselves occupy less space in memory.
2728

2829
# Getting Started
29-
You will need the class and source files. You can grab the [latest release](https://github.com/Abductcows/java-bit-array/releases/latest) (built with jdk-11) or download the project and run `mvn install` yourself. Releases contain a zip file with separate jars for classes, sources and javadoc. Include at least the class jar in your project and you will be able to use the BitArray. Looks like you are good to go.
30-
31-
### Versioning
32-
The project uses [SemVer](https://semver.org/) for versioning.
30+
You can grab the class from Maven or download the files yourself from the latest [release](https://github.com/Abductcows/java-bit-array/releases/latest).
3331

34-
### Contributions and future of this project
35-
I would like to work on this project with anyone willing to contribute. My estimation of the rough priority of actions needed is:
32+
### Maven
33+
```xml
34+
<dependency>
35+
<groupId>io.github.abductcows</groupId>
36+
<artifactId>bit-array</artifactId>
37+
<version>2.0.0</version>
38+
</dependency>
39+
```
3640

37-
- Testing: Improve tests to enhance confidence
38-
- Optimizing: 'cause why not. Maybe override a few of the AbstractList's default implementations
39-
- New features: Not sure if there is anything to add, suggestions very welcome
41+
# Project info
4042

41-
I would also appreciate you sharing your opinion on this class and the project as a whole. If you want to contribute, check out [CONTRIBUTING.md](https://github.com/Abductcows/java-bit-array/blob/master/CONTRIBUTING.md) for more info.
43+
### Versioning
44+
The project uses [SemVer 2.0.0](https://semver.org/) for versioning.
4245

4346
### License
4447
This Project is licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
4548

46-
### Authors
47-
- *George Bouroutzoglou* (georgebour@outlook.com)
49+
### Contributions and future of this project
50+
I would love to work on this project with anyone willing to contribute. My estimation of the remaining actions is
51+
52+
- Optimizing: 'cause why not. Maybe override a few of the AbstractList's default implementations
53+
- Add new methods, but not too many
4854

55+
If you want to contribute, check out [CONTRIBUTING.md](https://github.com/Abductcows/java-bit-array/blob/masternCONTRIBUTING.md) for more info.
4956

50-
[open-issues-url]: https://github.com/Abductcows/java-bit-array/issues
51-
[open-issues-shield]: https://img.shields.io/github/issues/abductcows/java-bit-array
57+
[lgtm-alerts-url]: https://lgtm.com/projects/g/Abductcows/java-bit-array/?mode=list
58+
[lgtm-alerts-shield]: https://img.shields.io/lgtm/alerts/github/abductcows/java-bit-array
59+
[lgtm-quality-url]: https://lgtm.com/projects/g/Abductcows/java-bit-array/?mode=list
60+
[lgtm-quality-shield]: https://img.shields.io/lgtm/grade/java/github/abductcows/java-bit-array
5261
[contributors-url]: https://github.com/Abductcows/java-bit-array/graphs/contributors
5362
[contributors-shield]: https://img.shields.io/github/contributors/abductcows/java-bit-array
5463
[latest-release-shield]: https://img.shields.io/github/v/release/abductcows/java-bit-array?sort=semver

pom.xml

Lines changed: 108 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,106 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--suppress KotlinMavenPluginPhase -->
23
<project xmlns="http://maven.apache.org/POM/4.0.0"
34
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
45
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
56
<modelVersion>4.0.0</modelVersion>
67

7-
8-
<groupId>gr.geompokon</groupId>
8+
<groupId>io.github.abductcows</groupId>
99
<artifactId>bit-array</artifactId>
10-
<version>1.0.3</version>
10+
<version>2.0.0</version>
1111

1212
<name>BitArray</name>
13-
<description>Java List of Booleans class with reduced memory usage and higher performance</description>
13+
<description>Fast, bitwise operation-based RandomAccess List&lt;Boolean&gt;</description>
1414
<url>https://github.com/Abductcows/java-bit-array</url>
1515
<inceptionYear>2021</inceptionYear>
1616

17-
<properties>
18-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19-
<maven.compiler.source>11</maven.compiler.source>
20-
<maven.compiler.target>11</maven.compiler.target>
21-
</properties>
22-
2317
<dependencies>
18+
<!-- https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305 -->
19+
<dependency>
20+
<groupId>com.google.code.findbugs</groupId>
21+
<artifactId>jsr305</artifactId>
22+
<version>${jsr305.version}</version>
23+
<scope>compile</scope>
24+
</dependency>
25+
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
26+
<dependency>
27+
<groupId>org.jetbrains</groupId>
28+
<artifactId>annotations</artifactId>
29+
<version>${jetbrains.annotations.version}</version>
30+
<optional>true</optional>
31+
</dependency>
32+
33+
<!-- Test Dependencies -->
34+
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
2435
<dependency>
2536
<groupId>org.junit.jupiter</groupId>
2637
<artifactId>junit-jupiter-engine</artifactId>
27-
<version>5.8.2</version>
38+
<version>${junit5.version}</version>
2839
<scope>test</scope>
29-
<optional>true</optional>
3040
</dependency>
41+
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
3142
<dependency>
3243
<groupId>org.junit.jupiter</groupId>
3344
<artifactId>junit-jupiter-params</artifactId>
34-
<version>5.8.2</version>
45+
<version>${junit5.version}</version>
3546
<scope>test</scope>
36-
<optional>true</optional>
37-
</dependency>
38-
<dependency>
39-
<groupId>org.jetbrains</groupId>
40-
<artifactId>annotations</artifactId>
41-
<version>23.0.0</version>
42-
<scope>compile</scope>
4347
</dependency>
4448
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
4549
<dependency>
4650
<groupId>org.assertj</groupId>
4751
<artifactId>assertj-core</artifactId>
48-
<version>3.21.0</version>
52+
<version>${assertj-core.version}</version>
53+
<scope>test</scope>
54+
</dependency>
55+
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8 -->
56+
<dependency>
57+
<groupId>org.jetbrains.kotlin</groupId>
58+
<artifactId>kotlin-stdlib-jdk8</artifactId>
59+
<version>${kotlin.version}</version>
4960
<scope>test</scope>
5061
</dependency>
5162
</dependencies>
5263

5364
<build>
5465
<plugins>
55-
<!-- Tests -->
66+
<!-- GPG sign plugin -->
5667
<plugin>
5768
<groupId>org.apache.maven.plugins</groupId>
58-
<artifactId>maven-surefire-plugin</artifactId>
59-
<version>2.22.0</version>
69+
<artifactId>maven-gpg-plugin</artifactId>
70+
<version>${maven-gpg-plugin.version}</version>
71+
<executions>
72+
<execution>
73+
<id>sign-artifacts</id>
74+
<phase>verify</phase>
75+
<goals>
76+
<goal>sign</goal>
77+
</goals>
78+
</execution>
79+
</executions>
80+
</plugin>
81+
82+
<!-- Jar -->
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-jar-plugin</artifactId>
86+
<version>${maven-jar-plugin.version}</version>
6087
<configuration>
61-
<excludes>
62-
<exclude>BitArrayVsArrayListBenchmarkTest.java</exclude>
63-
</excludes>
88+
<archive>
89+
<addMavenDescriptor>false</addMavenDescriptor>
90+
</archive>
6491
</configuration>
6592
</plugin>
6693

6794
<!-- Sources jar -->
6895
<plugin>
6996
<groupId>org.apache.maven.plugins</groupId>
7097
<artifactId>maven-source-plugin</artifactId>
71-
<version>3.2.0</version>
98+
<version>${maven-source-plugin.version}</version>
7299
<executions>
73100
<execution>
74101
<id>attach-sources</id>
75102
<goals>
76-
<goal>jar</goal>
103+
<goal>jar-no-fork</goal>
77104
</goals>
78105
</execution>
79106
</executions>
@@ -83,14 +110,21 @@
83110
<plugin>
84111
<groupId>org.apache.maven.plugins</groupId>
85112
<artifactId>maven-javadoc-plugin</artifactId>
86-
<version>3.2.0</version>
113+
<version>${maven-javadoc-plugin.version}</version>
87114
<configuration>
115+
<additionalOptions>
116+
-public
117+
--override-methods=summary
118+
-nonavbar
119+
-noindex
120+
-nohelp
121+
-notree
122+
-nodeprecatedlist
123+
</additionalOptions>
88124
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
89125
<level>public</level>
90-
91-
<defaultVersion>${project.version}</defaultVersion>
92-
<fixTags>version</fixTags>
93-
<force>true</force>
126+
<staleDataPath>${project.build.directory}/javadoc-stale-data/maven-javadoc-plugin-stale-data.txt
127+
</staleDataPath>
94128
</configuration>
95129
<executions>
96130
<execution>
@@ -122,12 +156,50 @@
122156
</license>
123157
</licenses>
124158

159+
<scm>
160+
<connection>scm:git:git://github.com/Abductcows/java-bit-array.git</connection>
161+
<developerConnection>no</developerConnection>
162+
<url>https://github.com/Abductcows/java-bit-array/tree/master/</url>
163+
</scm>
164+
165+
<distributionManagement>
166+
<snapshotRepository>
167+
<id>ossrh</id>
168+
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
169+
</snapshotRepository>
170+
<repository>
171+
<id>ossrh</id>
172+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
173+
</repository>
174+
</distributionManagement>
175+
125176
<developers>
126177
<developer>
127-
<id>0</id>
128178
<name>George Bouroutzoglou</name>
129-
<email>geompokon@csd.auth.gr</email>
179+
<email>abductcows@gmail.com</email>
180+
<organization>Abductcows</organization>
181+
<organizationUrl>https://github.com/Abductcows</organizationUrl>
130182
<timezone>+3</timezone>
131183
</developer>
132184
</developers>
185+
186+
<properties>
187+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
188+
189+
<kotlin.version>1.6.10</kotlin.version>
190+
<maven.compiler.source>11</maven.compiler.source>
191+
<maven.compiler.target>11</maven.compiler.target>
192+
193+
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
194+
<maven-source-plugin.version>3.2.0</maven-source-plugin.version>
195+
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
196+
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
197+
198+
<jsr305.version>3.0.2</jsr305.version>
199+
<jetbrains.annotations.version>23.0.0</jetbrains.annotations.version>
200+
201+
<junit5.version>5.8.2</junit5.version>
202+
<assertj-core.version>3.21.0</assertj-core.version>
203+
</properties>
204+
133205
</project>

0 commit comments

Comments
 (0)