Exemple #1
0
        /// <exception cref="System.IO.IOException"/>
        public SpillRecord(Path indexFileName, JobConf job, Checksum crc, string expectedIndexOwner
                           )
        {
            FileSystem        rfs = FileSystem.GetLocal(job).GetRaw();
            FSDataInputStream @in = SecureIOUtils.OpenFSDataInputStream(new FilePath(indexFileName
                                                                                     .ToUri().GetRawPath()), expectedIndexOwner, null);

            try
            {
                long length     = rfs.GetFileStatus(indexFileName).GetLen();
                int  partitions = (int)length / MapTask.MapOutputIndexRecordLength;
                int  size       = partitions * MapTask.MapOutputIndexRecordLength;
                buf = ByteBuffer.Allocate(size);
                if (crc != null)
                {
                    crc.Reset();
                    CheckedInputStream chk = new CheckedInputStream(@in, crc);
                    IOUtils.ReadFully(chk, ((byte[])buf.Array()), 0, size);
                    if (chk.GetChecksum().GetValue() != @in.ReadLong())
                    {
                        throw new ChecksumException("Checksum error reading spill index: " + indexFileName
                                                    , -1);
                    }
                }
                else
                {
                    IOUtils.ReadFully(@in, ((byte[])buf.Array()), 0, size);
                }
                entries = buf.AsLongBuffer();
            }
            finally
            {
                @in.Close();
            }
        }
Exemple #2
0
 public override LongBuffer Put(LongBuffer src)
 {
     if (src is HeapLongBuffer)
     {
         if (src == this)
         {
             throw new IllegalArgumentException();
         }
         HeapLongBuffer sb = (HeapLongBuffer)src;
         int            n  = sb.Remaining();
         if (n > Remaining())
         {
             throw new BufferOverflowException();
         }
         System.Array.Copy(sb.Hb, sb.Ix(sb.Position()), Hb, Ix(Position()), n);
         sb.Position(sb.Position() + n);
         Position(Position() + n);
     }
     else if (src.Direct)
     {
         int n = src.Remaining();
         if (n > Remaining())
         {
             throw new BufferOverflowException();
         }
         src.Get(Hb, Ix(Position()), n);
         Position(Position() + n);
     }
     else
     {
         base.Put(src);
     }
     return(this);
 }
 private static void bulkGet(LongBuffer b)
 {
     int n = b.Capacity;
     long[] a = new long[n + 7];
     b.Get(a, 7, n);
     for (int i = 0; i < n; i++)
         ck(b, (long)a[i + 7], (long)((long)Ic(i)));
 }
 private static void relPut(LongBuffer b)
 {
     int n = b.Capacity;
     b.Clear();
     for (int i = 0; i < n; i++)
         b.Put((long)Ic(i));
     b.Flip();
 }
 private static void relGet(LongBuffer b, int start)
 {
     int n = b.Remaining;
     long v;
     for (int i = start; i < n; i++)
         ck(b, (long)b.Get(), (long)((long)Ic(i)));
     b.Rewind();
 }
 private static void absGet(LongBuffer b)
 {
     int n = b.Capacity;
     long v;
     for (int i = 0; i < n; i++)
         ck(b, (long)b.Get(), (long)((long)Ic(i)));
     b.Rewind();
 }
 private static void absPut(LongBuffer b)
 {
     int n = b.Capacity;
     b.Clear();
     for (int i = 0; i < n; i++)
         b.Put(i, (long)Ic(i));
     b.Limit = (n);
     b.Position = (0);
 }
Exemple #8
0
        public static LongBuffer Wrap(long[] data)
        {
            LongBuffer buf = new LongBuffer(new byte[data.Length * 8], 0, data.Length * 8);

            for (int i = 0; i < data.Length; i++)
            {
                buf.PutLong(data[i]);
            }
            return(buf);
        }
 private static void bulkPutArray(LongBuffer b)
 {
     int n = b.Capacity;
     b.Clear();
     long[] a = new long[n + 7];
     for (int i = 0; i < n; i++)
         a[i + 7] = (long)Ic(i);
     b.Put(a, 7, n);
     b.Flip();
 }
        public MersenneTwisterData()
        {
            // index a value in 'state'
            // the array for the state vector
            ByteBuffer buff = ByteBuffer.AllocateDirect(MT_N * 8);

            buff.Order(ByteBuffer.NativeOrder());
            state = buff.AsLongBuffer();
            state.Clear();
            state.Position(0);
            state.Limit(MT_N);
        }
        public LongBuffer AsLongBuffer()
        {
            LongBuffer buf = new LongBuffer();

            buf.buffer = new byte[this.buffer.Length];
            this.buffer.CopyTo(buf.buffer, 0);

            buf.c        = this.c;
            buf.capacity = this.capacity;
            buf.index    = this.index;
            buf.limit    = this.limit;
            buf.mark     = this.mark;
            buf.offset   = this.offset;
            buf.order    = this.order;
            return(buf);
        }
 public override LongBuffer put(LongBuffer prm1)
 {
     return(default(LongBuffer));
 }
Exemple #13
0
 public SpillRecord(int numPartitions)
 {
     buf     = ByteBuffer.Allocate(numPartitions * MapTask.MapOutputIndexRecordLength);
     entries = buf.AsLongBuffer();
 }
 public override LongBuffer Put(LongBuffer src)
 {
     throw new ReadOnlyBufferException();
 }
 private static void bulkPutBuffer(LongBuffer b)
 {
     int n = b.Capacity;
     b.Clear();
     LongBuffer c = LongBuffer.Allocate(n + 7);
     c.Position = (7);
     for (int i = 0; i < n; i++)
         c.Put((long)Ic(i));
     c.Flip();
     c.Position = (7);
     b.Put(c);
     b.Flip();
 }
        //6231529
        private static void callReset(LongBuffer b)
        {
            b.Position = (0);
            b.Mark();

            b.Duplicate().Reset();

            // LUCENENET: AsReadOnlyBuffer() not implemented
            //b.AsReadOnlyBuffer().Reset();
        }
 private static void checkSlice(LongBuffer b, LongBuffer slice)
 {
     ck(slice, 0, slice.Position);
     ck(slice, b.Remaining, slice.Limit);
     ck(slice, b.Remaining, slice.Capacity);
     if (b.IsDirect != slice.IsDirect)
         fail("Lost direction", slice);
     if (b.IsReadOnly != slice.IsReadOnly)
         fail("Lost read-only", slice);
 }
        /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
        private void ReadObjects(ScriptBlock block, BinaryReader br)
        {
            int totalSize = br.ReadInt32();

            string[]     strarray = mStringArray;
            ByteBuffer[] bbarray  = mByteBufferArray;
            double[]     dblarray = mDoubleArray;
            byte[]       barray   = mByteArray;
            short[]      sarray   = mShortArray;
            int[]        iarray   = mIntArray;
            long[]       larray   = mLongArray;
            int          toplevel = br.ReadInt32();
            int          objcount = br.ReadInt32();

            mObjectsCache.Create(objcount);
            InterCodeObject[]       objs = mObjectsCache.mObjs;
            AList <VariantRepalace> work = mObjectsCache.mWork;

            int[]   parent           = mObjectsCache.mParent;
            int[]   propSetter       = mObjectsCache.mPropSetter;
            int[]   propGetter       = mObjectsCache.mPropGetter;
            int[]   superClassGetter = mObjectsCache.mSuperClassGetter;
            int[][] properties       = mObjectsCache.mProperties;
            for (int o = 0; o < objcount; o++)
            {
                if (br.ReadChars(4).ToRealString() != FILE_TAG_LE)
                {
                    throw new TjsException("ByteCode Broken");
                }
                int objsize = br.ReadInt32();
                parent[o] = br.ReadInt32();
                int name                        = br.ReadInt32();
                int contextType                 = br.ReadInt32();
                int maxVariableCount            = br.ReadInt32();
                int variableReserveCount        = br.ReadInt32();
                int maxFrameCount               = br.ReadInt32();
                int funcDeclArgCount            = br.ReadInt32();
                int funcDeclUnnamedArgArrayBase = br.ReadInt32();
                int funcDeclCollapseBase        = br.ReadInt32();
                propSetter[o]       = br.ReadInt32();
                propGetter[o]       = br.ReadInt32();
                superClassGetter[o] = br.ReadInt32();
                int        count  = br.ReadInt32();
                LongBuffer srcpos = null;
                // codePos/srcPos は今のところ使ってない、ソート济みなので、longにする必要はないが……
                // codePos/srcPos currently not used. it's for debug. Please refer to newer krkrz code and fix here later.
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        br.ReadInt64();
                    }
                }
                else
                {
                    //br.BaseStream.Seek(count << 3, SeekOrigin.Current);
                    //br.ReadInt32();
                }

                count = br.ReadInt32();
                short[] code = new short[count];
                for (int i = 0; i < count; i++)
                {
                    code[i] = br.ReadInt16();
                }
                //TranslateCodeAddress( block, code, codeSize );
                var padding = 4 - (count * 2) % 4;
                if (padding > 0 && padding < 4)
                {
                    br.ReadBytes(padding);
                }

                count = br.ReadInt32();
                int vcount = count * 2;
                if (mVariantTypeData == null || mVariantTypeData.Length < vcount)
                {
                    mVariantTypeData = new short[vcount];
                }
                for (int i = 0; i < vcount; i++)
                {
                    mVariantTypeData[i] = br.ReadInt16();
                }
                Variant[] vdata     = new Variant[count];
                int       datacount = count;
                Variant   tmp;
                for (int i = 0; i < datacount; i++)
                {
                    int pos   = i << 1;
                    int type  = mVariantTypeData[pos];
                    int index = mVariantTypeData[pos + 1];
                    switch (type)
                    {
                    case TYPE_VOID:
                    {
                        vdata[i] = new Variant();
                        // null
                        break;
                    }

                    case TYPE_OBJECT:
                    {
                        vdata[i] = new Variant(null, null);
                        // null Array Dictionary はまだサポートしていない TODO
                        break;
                    }

                    case TYPE_INTER_OBJECT:
                    {
                        tmp = new Variant();
                        work.AddItem(new VariantRepalace(tmp, index));
                        vdata[i] = tmp;
                        break;
                    }

                    case TYPE_INTER_GENERATOR:
                    {
                        tmp = new Variant();
                        work.AddItem(new VariantRepalace(tmp, index));
                        vdata[i] = tmp;
                        break;
                    }

                    case TYPE_STRING:
                    {
                        vdata[i] = new Variant(strarray[index]);
                        break;
                    }

                    case TYPE_OCTET:
                    {
                        vdata[i] = new Variant(bbarray[index]);
                        break;
                    }

                    case TYPE_REAL:
                    {
                        vdata[i] = new Variant(dblarray[index]);
                        break;
                    }

                    case TYPE_BYTE:
                    {
                        vdata[i] = new Variant(barray[index]);
                        break;
                    }

                    case TYPE_SHORT:
                    {
                        vdata[i] = new Variant(sarray[index]);
                        break;
                    }

                    case TYPE_INTEGER:
                    {
                        vdata[i] = new Variant(iarray[index]);
                        break;
                    }

                    case TYPE_LONG:
                    {
                        vdata[i] = new Variant(larray[index]);
                        break;
                    }

                    case TYPE_UNKNOWN:
                    default:
                    {
                        vdata[i] = new Variant();
                        // null;
                        break;
                        break;
                    }
                    }
                }
                count = br.ReadInt32();
                int[] scgetterps = new int[count];
                for (int i = 0; i < count; i++)
                {
                    scgetterps[i] = br.ReadInt32();
                }
                // properties
                count = br.ReadInt32();
                if (count > 0)
                {
                    int   pcount = count << 1;
                    int[] props  = new int[pcount];
                    for (int i = 0; i < pcount; i++)
                    {
                        props[i] = br.ReadInt32();
                    }
                    properties[o] = props;
                }
                //IntVector superpointer = IntVector.wrap( scgetterps );
                InterCodeObject obj = new InterCodeObject(block, mStringArray[name], contextType,
                                                          code, vdata, maxVariableCount, variableReserveCount, maxFrameCount, funcDeclArgCount
                                                          , funcDeclUnnamedArgArrayBase, funcDeclCollapseBase, true, srcpos, scgetterps);
                //objs.add(obj);
                objs[o] = obj;
            }
            Variant val = new Variant();

            for (int o = 0; o < objcount; o++)
            {
                InterCodeObject parentObj           = null;
                InterCodeObject propSetterObj       = null;
                InterCodeObject propGetterObj       = null;
                InterCodeObject superClassGetterObj = null;
                if (parent[o] >= 0)
                {
                    parentObj = objs[parent[o]];
                }
                if (propSetter[o] >= 0)
                {
                    propSetterObj = objs[propSetter[o]];
                }
                if (propGetter[o] >= 0)
                {
                    propGetterObj = objs[propGetter[o]];
                }
                if (superClassGetter[o] >= 0)
                {
                    superClassGetterObj = objs[superClassGetter[o]];
                }
                objs[o]
                .SetCodeObject(parentObj, propSetterObj, propGetterObj, superClassGetterObj
                               );
                if (properties[o] != null)
                {
                    InterCodeObject obj = parentObj;
                    // objs.get(o).mParent;
                    int[] prop   = properties[o];
                    int   length = (int)(((uint)prop.Length) >> 1);
                    for (int i = 0; i < length; i++)
                    {
                        int pos   = i << 1;
                        int pname = prop[pos];
                        int pobj  = prop[pos + 1];
                        val.Set(objs[pobj]);
                        obj.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP, mStringArray[pname], val
                                    , obj);
                    }
                    properties[o] = null;
                }
            }
            for (int i = 0; i < work.Count; i++)
            {
                VariantRepalace w = work[i];
                w.Work.Set(objs[w.Index]);
            }
            work.Clear();
            InterCodeObject top = null;

            if (toplevel >= 0)
            {
                top = objs[toplevel];
            }
            block.SetObjects(top, objs, objcount);
        }
 private static void fail(string problem,
                          LongBuffer xb, LongBuffer yb,
                          long x, long y)
 {
     fail(problem + string.Format(": x={0} y={1}", x, y), xb, yb);
 }
        public static void test(int level, LongBuffer b, bool direct)
        {

            Show(level, b);

            if (direct != b.IsDirect)
                fail("Wrong direction", b);

            // Gets and puts

            relPut(b);
            relGet(b);
            absGet(b);
            bulkGet(b);

            absPut(b);
            relGet(b);
            absGet(b);
            bulkGet(b);

            bulkPutArray(b);
            relGet(b);

            bulkPutBuffer(b);
            relGet(b);

            // Compact

            relPut(b);
            b.Position = (13);
            b.Compact();
            b.Flip();
            relGet(b, 13);

            // Exceptions

            relPut(b);
            b.Limit = (b.Capacity / 2);
            b.Position = (b.Limit);

            tryCatch(b, typeof(BufferUnderflowException), () =>
            {
                b.Get();
            });

            tryCatch(b, typeof(BufferOverflowException), () =>
            {
                b.Put((long)42);
            });

            // The index must be non-negative and lesss than the buffer's limit.
            tryCatch(b, typeof(IndexOutOfRangeException), () =>
            {
                b.Get(b.Limit);
            });
            tryCatch(b, typeof(IndexOutOfRangeException), () =>
            {
                b.Get(-1);
            });

            tryCatch(b, typeof(IndexOutOfRangeException), () =>
            {
                b.Put(b.Limit, (long)42);
            });

            tryCatch(b, typeof(InvalidMarkException), () =>
            {
                b.Position = (0);
                b.Mark();
                b.Compact();
                b.Reset();
            });

            // Values

            b.Clear();
            b.Put((long)0);
            b.Put((long)-1);
            b.Put((long)1);
            b.Put(long.MaxValue);
            b.Put(long.MinValue);

            long v;
            b.Flip();
            ck(b, b.Get(), 0);
            ck(b, b.Get(), (long)-1);
            ck(b, b.Get(), 1);
            ck(b, b.Get(), long.MaxValue);
            ck(b, b.Get(), long.MinValue);


            // Comparison
            b.Rewind();
            LongBuffer b2 = Lucene.Net.Support.LongBuffer.Allocate(b.Capacity);
            b2.Put(b);
            b2.Flip();
            b.Position = (2);
            b2.Position = (2);
            if (!b.equals(b2))
            {
                for (int i = 2; i < b.Limit; i++)
                {
                    long x = b.Get(i);
                    long y = b2.Get(i);
                    if (x != y)
                        output.WriteLine("[" + i + "] " + x + " != " + y);
                }
                fail("Identical buffers not equal", b, b2);
            }
            if (b.CompareTo(b2) != 0)
                fail("Comparison to identical buffer != 0", b, b2);

            b.Limit = (b.Limit + 1);
            b.Position = (b.Limit - 1);
            b.Put((long)99);
            b.Rewind();
            b2.Rewind();
            if (b.Equals(b2))
                fail("Non-identical buffers equal", b, b2);
            if (b.CompareTo(b2) <= 0)
                fail("Comparison to shorter buffer <= 0", b, b2);
            b.Limit = (b.Limit - 1);

            b.Put(2, (long)42);
            if (b.equals(b2))
                fail("Non-identical buffers equal", b, b2);
            if (b.CompareTo(b2) <= 0)
                fail("Comparison to lesser buffer <= 0", b, b2);

            // Check equals and compareTo with interesting values
            foreach (long x in VALUES)
            {
                LongBuffer xb = Lucene.Net.Support.LongBuffer.Wrap(new long[] { x });
                if (xb.CompareTo(xb) != 0)
                {
                    fail("compareTo not reflexive", xb, xb, x, x);
                }
                if (!xb.equals(xb))
                {
                    fail("equals not reflexive", xb, xb, x, x);
                }
                foreach (long y in VALUES)
                {
                    LongBuffer yb = Lucene.Net.Support.LongBuffer.Wrap(new long[] { y });
                    if (xb.CompareTo(yb) != -yb.CompareTo(xb))
                    {
                        fail("compareTo not anti-symmetric",
                             xb, yb, x, y);
                    }
                    if ((xb.CompareTo(yb) == 0) != xb.equals(yb))
                    {
                        fail("compareTo inconsistent with equals",
                             xb, yb, x, y);
                    }
                    // from Long.compare(x, y)
                    if (xb.CompareTo(yb) != ((x < y) ? -1 : ((x == y) ? 0 : 1)))
                    {

                        fail("Incorrect results for LongBuffer.compareTo",
                             xb, yb, x, y);
                    }
                    if (xb.equals(yb) != ((x == y) || (x != x) && (y != y)))
                    {
                        fail("Incorrect results for LongBuffer.equals",
                             xb, yb, x, y);
                    }
                }
            }

            // Sub, dup

            relPut(b);
            relGet(b.Duplicate());
            b.Position = (13);
            relGet(b.Duplicate(), 13);
            relGet(b.Duplicate().Slice(), 13);
            relGet(b.Slice(), 13);
            relGet(b.Slice().Duplicate(), 13);

            // Slice

            b.Position = (5);
            LongBuffer sb = b.Slice();
            checkSlice(b, sb);
            b.Position = (0);
            LongBuffer sb2 = sb.Slice();
            checkSlice(sb, sb2);

            if (!sb.equals(sb2))
                fail("Sliced slices do not match", sb, sb2);
            if ((sb.HasArray) && (sb.ArrayOffset != sb2.ArrayOffset))
                fail("Array offsets do not match: "
                     + sb.ArrayOffset + " != " + sb2.ArrayOffset, sb, sb2);


            // Read-only views

            b.Rewind();

            // LUCENENET: AsReadOnlyBuffer() not implemented
            tryCatch(b, typeof(NotImplementedException), () =>
            {
                b.AsReadOnlyBuffer();
            });

            // LUCENENET: AsReadOnlyBuffer() not implemented
            //LongBuffer rb = b.AsReadOnlyBuffer();
            //if (!b.Equals(rb))
            //    fail("Buffer not equal to read-only view", b, rb);
            //Show(level + 1, rb);

            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
            //{
            //    relPut(rb);
            //});

            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
            //{
            //    absPut(rb);
            //});

            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
            //{
            //    bulkPutArray(rb);
            //});

            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
            //{
            //    bulkPutBuffer(rb);
            //});

            //// put(LongBuffer) should not change source position
            //LongBuffer src = LongBuffer.Allocate(1);
            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
            //{
            //    rb.Put(src);
            //});
            //ck(src, src.Position, 0);

            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
            //{
            //    rb.Compact();
            //});


            //if (rb.GetType().Name.StartsWith("Heap"))
            //{

            //    tryCatch(b, typeof(ReadOnlyBufferException), () =>
            //    {
            //        var x = rb.Array;
            //    });

            //    tryCatch(b, typeof(ReadOnlyBufferException), () =>
            //    {
            //        var x = rb.ArrayOffset;
            //    });

            //    if (rb.HasArray)
            //        fail("Read-only heap buffer's backing array is accessible",
            //             rb);

            //}

            // Bulk puts from read-only buffers

            b.Clear();
            //rb.Rewind();
            //b.Put(rb);

            relPut(b);                       // Required by testViews

        }