alloc() public method

This is to implement memory allocation in the array. Like malloc().
public alloc ( int size ) : int
size int
return int
Exemplo n.º 1
0
 public HyphenationTree()
 {
     stoplist = new Dictionary <>(23);    // usually a small table
     classmap = new TernaryTree();
     vspace   = new ByteVector();
     vspace.alloc(1);     // this reserves index 0, which we don't use
 }
Exemplo n.º 2
0
	  public HyphenationTree()
	  {
		stoplist = new Dictionary<>(23); // usually a small table
		classmap = new TernaryTree();
		vspace = new ByteVector();
		vspace.alloc(1); // this reserves index 0, which we don't use
	  }
Exemplo n.º 3
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="values"> a string of digits from '0' to '9' representing the
        ///        interletter values. </param>
        /// <returns> the index into the vspace array where the packed values are stored. </returns>
        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);
        }