class HyphenationTree {
/**
* Packs the values by storing them in 4 bits, two values into a byte
* Values range is from 0 to 9. We use zero as terminator,
* so we'll add 1 to the value.
* @param values a string of digits from '0' to '9' representing the
* interletter values.
* @return the index into the vspace array where the packed values
* are stored.
*/
protected int packValues(String values) {
int i, n = values.length();
int m = (n & 1) == 1 ? (n >> 1) + 2 : (n >> 1) + 1;
int offset = vspace.alloc(m);
byte[] va = vspace.getArray();
for (i = 0; i < n; i++) {
int j = i >> 1;
byte v = (byte)(values.charAt(i) - '0' + 1 & 0x0f);
if ((i & 1) == 1) {
va[j + offset] = (byte)(va[j + offset] | v);
} else {
va[j + offset] = (byte)(v << 4); // big endian
}
}
va[m - 1 + offset] = 0; // terminator
return offset;
}
}