Beispiel #1
0
        public override void BeforeClass()
        {
            base.BeforeClass();

            Random random = Random;

            INTS              = new int[COUNT];
            LONGS             = new long[COUNT];
            RANDOM_TEST_BYTES = new byte[COUNT * (5 + 4 + 9 + 8)];
            ByteArrayDataOutput bdo = new ByteArrayDataOutput(RANDOM_TEST_BYTES);

            for (int i = 0; i < COUNT; i++)
            {
                int i1 = INTS[i] = random.Next();
                bdo.WriteVInt32(i1);
                bdo.WriteInt32(i1);

                long l1;
                if (Rarely())
                {
                    // a long with lots of zeroes at the end
                    l1 = LONGS[i] = TestUtil.NextInt64(random, 0, int.MaxValue) << 32;
                }
                else
                {
                    l1 = LONGS[i] = TestUtil.NextInt64(random, 0, long.MaxValue);
                }
                bdo.WriteVInt64(l1);
                bdo.WriteInt64(l1);
            }
        }
Beispiel #2
0
 /// <summary>
 /// encodes an entry (bytes+weight) to the provided writer
 /// </summary>
 protected internal virtual void Encode(OfflineSorter.ByteSequencesWriter writer,
                                        ByteArrayDataOutput output, byte[] buffer, BytesRef spare, long weight)
 {
     if (spare.Length + 8 >= buffer.Length)
     {
         buffer = ArrayUtil.Grow(buffer, spare.Length + 8);
     }
     output.Reset(buffer);
     output.WriteBytes(spare.Bytes, spare.Offset, spare.Length);
     output.WriteInt64(weight);
     writer.Write(buffer, 0, output.Position);
 }
        /// <summary>
        /// encodes an entry (bytes+(contexts)+(payload)+weight) to the provided writer
        /// </summary>
        protected internal virtual void Encode(OfflineSorter.ByteSequencesWriter writer,
                                               ByteArrayDataOutput output, byte[] buffer, BytesRef spare, BytesRef payload,
                                               IEnumerable <BytesRef> contexts, long weight)
        {
            int requiredLength = spare.Length + 8 + ((hasPayloads) ? 2 + payload.Length : 0);

            if (hasContexts)
            {
                foreach (BytesRef ctx in contexts)
                {
                    requiredLength += 2 + ctx.Length;
                }
                requiredLength += 2; // for length of contexts
            }
            if (requiredLength >= buffer.Length)
            {
                buffer = ArrayUtil.Grow(buffer, requiredLength);
            }
            output.Reset(buffer);
            output.WriteBytes(spare.Bytes, spare.Offset, spare.Length);
            if (hasContexts)
            {
                foreach (BytesRef ctx in contexts)
                {
                    output.WriteBytes(ctx.Bytes, ctx.Offset, ctx.Length);
                    output.WriteInt16((short)ctx.Length);
                }
                output.WriteInt16((short)contexts.Count());
            }
            if (hasPayloads)
            {
                output.WriteBytes(payload.Bytes, payload.Offset, payload.Length);
                output.WriteInt16((short)payload.Length);
            }
            output.WriteInt64(weight);
            writer.Write(buffer, 0, output.Position);
        }