2018-11-21 01:02:25 +01:00
|
|
|
package org.warp.jcwdb;
|
|
|
|
|
2018-12-04 23:57:49 +01:00
|
|
|
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
|
|
|
|
2018-12-20 00:16:16 +01:00
|
|
|
public class DBLightArrayListParser<T> extends DBTypeParserImpl<LightArrayList<T>> {
|
2018-11-21 01:02:25 +01:00
|
|
|
private final JCWDatabase db;
|
|
|
|
|
2018-12-20 00:16:16 +01:00
|
|
|
public DBLightArrayListParser(JCWDatabase db) {
|
2018-11-21 01:02:25 +01:00
|
|
|
this.db = db;
|
|
|
|
}
|
2018-12-20 00:16:16 +01:00
|
|
|
|
|
|
|
public DBReader<LightArrayList<T>> getReader() {
|
2018-11-22 23:31:41 +01:00
|
|
|
return (i, size) -> {
|
2018-12-04 23:57:49 +01:00
|
|
|
LongArrayList internalList = new LongArrayList();
|
2018-12-11 23:00:51 +01:00
|
|
|
long max = size / Long.BYTES;
|
2018-12-20 00:16:16 +01:00
|
|
|
for (int item = 0; item < max; item++) {
|
2018-11-22 23:31:41 +01:00
|
|
|
long itm = i.readLong();
|
|
|
|
internalList.add(itm);
|
|
|
|
}
|
2018-12-20 00:16:16 +01:00
|
|
|
return new LightArrayList<T>(db, internalList);
|
2018-11-21 01:02:25 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-12-20 00:16:16 +01:00
|
|
|
public DBDataOutput<LightArrayList<T>> getWriter(final LightArrayList<T> value) {
|
2018-12-04 23:57:49 +01:00
|
|
|
final int elementsCount = value.size();
|
2018-11-21 01:02:25 +01:00
|
|
|
return DBDataOutput.create((o) -> {
|
2018-12-04 23:57:49 +01:00
|
|
|
LongArrayList list = value.internalList;
|
|
|
|
for (int i = 0; i < elementsCount; i++) {
|
|
|
|
o.writeLong(list.getLong(i));
|
2018-11-22 23:31:41 +01:00
|
|
|
}
|
2018-12-20 00:16:16 +01:00
|
|
|
}, DBStandardTypes.LIGHT_LIST_ARRAY, elementsCount * Long.BYTES, calculateHash(value));
|
2018-12-04 23:57:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-20 00:16:16 +01:00
|
|
|
public long calculateHash(LightArrayList<T> value) {
|
2018-12-11 23:00:51 +01:00
|
|
|
return value.internalList.hashCode();
|
2018-11-21 01:02:25 +01:00
|
|
|
}
|
|
|
|
}
|