Skip to content

Commit

Permalink
Merge pull request #32 from miraisolutions/feature/30_sparse_bit_set
Browse files Browse the repository at this point in the history
Use SparseBitSet instead of java.util.BitSet
  • Loading branch information
martinstuder authored Feb 12, 2024
2 parents 80aa717 + af6430a commit 545829d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>com.miraisolutions</groupId>
<artifactId>XLConnect</artifactId>
<packaging>jar</packaging>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</version>
<name>XLConnect</name>
<url>https://mirai-solutions.ch/</url>
<repositories>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/miraisolutions/xlconnect/data/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
*/
package com.miraisolutions.xlconnect.data;

import java.util.BitSet;
import com.zaxxer.sparsebits.SparseBitSet;
import java.util.Date;

public final class Column {
private final Object data;
private final int size;
private final BitSet missing;
private final SparseBitSet missing;
private final DataType type;

public Column(Object data, int size, BitSet missing, DataType type) {
public Column(Object data, int size, SparseBitSet missing, DataType type) {
this.data = data;
this.size = size;
this.missing = missing;
Expand All @@ -55,7 +55,7 @@ public String[] getStringData() {
return (String[]) data;
}

public BitSet getMissing() {
public SparseBitSet getMissing() {
return missing;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.miraisolutions.xlconnect.ErrorBehavior;
import com.miraisolutions.xlconnect.Workbook;
import com.miraisolutions.xlconnect.utils.CellUtils;
import com.zaxxer.sparsebits.SparseBitSet;
import org.apache.poi.ss.usermodel.*;

import java.util.*;
Expand Down Expand Up @@ -105,7 +106,7 @@ protected void addValue(Cell c, CellValue cv, DataType dt) {
public Column buildBooleanColumn() {
int size = values.size();
boolean[] colValues = new boolean[size];
BitSet missing = new BitSet(size);
SparseBitSet missing = new SparseBitSet(size);

int counter = 0;
for (CellValue cv : values) {
Expand Down Expand Up @@ -140,7 +141,7 @@ public Column buildBooleanColumn() {
public Column buildDateTimeColumn() {
int size = values.size();
Date[] colValues = new Date[size];
BitSet missing = new BitSet(size);
SparseBitSet missing = new SparseBitSet(size);

Iterator<CellValue> it = values.iterator();
Iterator<Cell> jt = cells.iterator();
Expand Down Expand Up @@ -196,7 +197,7 @@ public Column buildDateTimeColumn() {
public Column buildNumericColumn() {
int size = values.size();
double[] colValues = new double[size];
BitSet missing = new BitSet(size);
SparseBitSet missing = new SparseBitSet(size);

int counter = 0;
for (CellValue cv : values) {
Expand Down Expand Up @@ -242,7 +243,7 @@ public Column buildNumericColumn() {
public Column buildStringColumn() {
int size = values.size();
String[] colValues = new String[size];
BitSet missing = new BitSet(size);
SparseBitSet missing = new SparseBitSet(size);

Iterator<CellValue> it = values.iterator();
Iterator<Cell> jt = cells.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.miraisolutions.xlconnect.data.DataType;

import java.util.Arrays;
import java.util.BitSet;
import com.zaxxer.sparsebits.SparseBitSet;
import java.util.Date;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -90,14 +90,16 @@ public long[] getDateTimeColumn(int col) {

public boolean[] isMissing(int col) {
Column column = dataFrame.getColumn(col);
BitSet missing = column.getMissing();
SparseBitSet missing = column.getMissing();
boolean[] na = new boolean[column.size()];
missing.stream().forEach(i -> na[i] = true);
for (int i = missing.nextSetBit(0); i >= 0; i = missing.nextSetBit(i + 1)) {
na[i] = true;
}
return na;
}

private static BitSet toBitSet(boolean[] bits) {
BitSet bs = new BitSet(bits.length);
private static SparseBitSet toBitSet(boolean[] bits) {
SparseBitSet bs = new SparseBitSet(bits.length);
for (int i = 0; i < bits.length; i++) {
bs.set(i, bits[i]);
}
Expand Down

0 comments on commit 545829d

Please sign in to comment.