org.apache.lucene.analysis.compound.hyphenation.HyphenationTree.packValues C# (CSharp) Method

packValues() protected method

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.
protected packValues ( string values ) : int
values string a string of digits from '0' to '9' representing the /// interletter values.
return int
	  protected internal virtual 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);
		sbyte[] va = vspace.Array;
		for (i = 0; i < n; i++)
		{
		  int j = i >> 1;
		  sbyte v = (sbyte)((values[i] - '0' + 1) & 0x0f);
		  if ((i & 1) == 1)
		  {
			va[j + offset] = (sbyte)(va[j + offset] | v);
		  }
		  else
		  {
			va[j + offset] = (sbyte)(v << 4); // big endian
		  }
		}
		va[m - 1 + offset] = 0; // terminator
		return offset;
	  }