Exemplo n.º 1
0
        /// <summary>
        /// Appends a single suggestion and its weight to the internal buffers.
        /// </summary>
        /// <param name="utf8">
        ///          The suggestion (utf8 representation) to be added. The content is
        ///          copied and the object can be reused. </param>
        /// <param name="bucket">
        ///          The bucket to place this suggestion in. Must be non-negative and
        ///          smaller than the number of buckets passed in the constructor.
        ///          Higher numbers indicate suggestions that should be presented
        ///          before suggestions placed in smaller buckets. </param>
        public virtual void Add(BytesRef utf8, int bucket)
        {
            if (bucket < 0 || bucket >= buckets)
            {
                throw new ArgumentException("Bucket outside of the allowed range [0, " + buckets + "): " + bucket);
            }

            if (scratch.Bytes.Length < utf8.Length + 1)
            {
                scratch.Grow(utf8.Length + 10);
            }

            scratch.Length   = 1;
            scratch.Bytes[0] = (sbyte)bucket;
            scratch.Append(utf8);
            sorter.Add(scratch);
        }