use of de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta in project elki by elki-project.
the class SimpleTransactionParser method nextEvent.
@Override
public Event nextEvent() {
if (nextevent != null) {
Event ret = nextevent;
nextevent = null;
return ret;
}
try {
while (reader.nextLineExceptComments()) {
// Don't reuse bitsets, will not be copied by BitVector constructor.
buf.clear();
for (; /* initialized by nextLineExceptComments() */
tokenizer.valid(); tokenizer.advance()) {
String token = tokenizer.getSubstring();
int t = keymap.getInt(token);
if (t < 0) {
t = keymap.size();
keymap.put(token, t);
}
final int word = t >>> 6;
final int off = t & 0x3F;
while (word >= buf.size()) {
// Ensure size.
buf.add(0L);
}
buf.set(word, buf.getLong(word) | (1L << off));
}
curvec = new BitVector(buf.toLongArray(), keymap.size());
return Event.NEXT_OBJECT;
}
nextevent = Event.END_OF_STREAM;
// Construct final metadata:
meta = new BundleMeta(1);
String[] colnames = new String[keymap.size()];
for (ObjectIterator<Object2IntMap.Entry<String>> iter = keymap.object2IntEntrySet().fastIterator(); iter.hasNext(); ) {
Object2IntMap.Entry<String> entry = iter.next();
colnames[entry.getIntValue()] = entry.getKey();
}
meta.add(new VectorFieldTypeInformation<>(BitVector.FACTORY, colnames.length, colnames));
// Force a final meta update.
return Event.META_CHANGED;
} catch (IOException e) {
throw new IllegalArgumentException("Error while parsing line " + reader.getLineNumber() + ".");
}
}
Aggregations