org.h2.result.Sparse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of h2-mvstore Show documentation
Show all versions of h2-mvstore Show documentation
Fork of h2database to maintain Java 8 compatibility
The newest version!
/*
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (https://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.result;
import org.h2.value.Value;
import org.h2.value.ValueBigint;
/**
* Class Sparse.
*
* - 11/16/19 7:35 PM initial creation
*
*
* @author Andrei Tokar
*/
public final class Sparse extends DefaultRow {
private final int columnCount;
private final int[] map;
Sparse(int columnCount, int capacity, int[] map) {
super(new Value[capacity]);
this.columnCount = columnCount;
this.map = map;
}
@Override
public int getColumnCount() {
return columnCount;
}
@Override
public Value getValue(int i) {
if (i == ROWID_INDEX) {
return ValueBigint.get(getKey());
}
int index = map[i];
return index > 0 ? super.getValue(index - 1) : null;
}
@Override
public void setValue(int i, Value v) {
if (i == ROWID_INDEX) {
setKey(v.getLong());
}
int index = map[i];
if (index > 0) {
super.setValue(index - 1, v);
}
}
@Override
public void copyFrom(SearchRow source) {
setKey(source.getKey());
for (int i = 0; i < map.length; i++) {
int index = map[i];
if (index > 0) {
super.setValue(index - 1, source.getValue(i));
}
}
}
}