Lucene40DocValuesFormat.BYTES_VAR_DEREF_VERSION_CURRENT);
// deduplicate
TreeSet<BytesRef> dictionary = new TreeSet<BytesRef>();
for (BytesRef v : values) {
dictionary.add(v == null ? new BytesRef() : BytesRef.deepCopyOf(v));
}
/* values */
long startPosition = data.getFilePointer();
long currentAddress = 0;
HashMap<BytesRef,Long> valueToAddress = new HashMap<BytesRef,Long>();
for (BytesRef v : dictionary) {
currentAddress = data.getFilePointer() - startPosition;
valueToAddress.put(v, currentAddress);
writeVShort(data, v.length);
data.writeBytes(v.bytes, v.offset, v.length);
}
/* ordinals */
long totalBytes = data.getFilePointer() - startPosition;
index.writeLong(totalBytes);
final int maxDoc = state.segmentInfo.getDocCount();
final PackedInts.Writer w = PackedInts.getWriter(index, maxDoc, PackedInts.bitsRequired(currentAddress), PackedInts.DEFAULT);
for (BytesRef v : values) {
w.add(valueToAddress.get(v == null ? new BytesRef() : v));
}
w.finish();
}