Example #1
0
            public override void Get(int docID, Int32sRef ordinals)
            {
                BytesRef bytes = new BytesRef();

                values.Get(docID, bytes);
                outerInstance.Decode(bytes, ordinals);
            }
Example #2
0
        /// <summary>
        /// Subclass &amp; override if you change the encoding.
        /// </summary>
        protected virtual void Decode(BytesRef buf, Int32sRef ordinals)
        {
            // grow the buffer up front, even if by a large number of values (buf.length)
            // that saves the need to check inside the loop for every decoded value if
            // the buffer needs to grow.
            if (ordinals.Int32s.Length < buf.Length)
            {
                ordinals.Int32s = ArrayUtil.Grow(ordinals.Int32s, buf.Length);
            }

            ordinals.Offset = 0;
            ordinals.Length = 0;

            // it is better if the decoding is inlined like so, and not e.g.
            // in a utility method
            int upto   = buf.Offset + buf.Length;
            int value  = 0;
            int offset = buf.Offset;
            int prev   = 0;

            while (offset < upto)
            {
                byte b = buf.Bytes[offset++];
                if ((sbyte)b >= 0)
                {
                    ordinals.Int32s[ordinals.Length] = ((value << 7) | b) + prev;
                    value = 0;
                    prev  = ordinals.Int32s[ordinals.Length];
                    ordinals.Length++;
                }
                else
                {
                    value = (value << 7) | (b & 0x7F);
                }
            }
        }
Example #3
0
 /// <summary>
 /// Get the ordinals for this document. The <paramref name="ordinals"/>.<see cref="Int32sRef.Offset"/>
 /// must always be 0!
 /// </summary>
 public abstract void Get(int doc, Int32sRef ordinals);