Ejemplo n.º 1
0
        /// <summary>
        /// Creates an array with content retrieved from the given <see cref="DataInput"/>. </summary>
        /// <param name="in">       A <see cref="DataInput"/>, positioned at the start of Packed64-content. </param>
        /// <param name="valueCount">  The number of elements. </param>
        /// <param name="bitsPerValue"> The number of bits available for any given value. </param>
        /// <exception cref="IOException"> If the values for the backing array could not
        ///                             be retrieved. </exception>
        public Packed64(int packedIntsVersion, DataInput @in, int valueCount, int bitsPerValue)
            : base(valueCount, bitsPerValue)
        {
            PackedInt32s.Format format = PackedInt32s.Format.PACKED;
            long byteCount             = format.ByteCount(packedIntsVersion, valueCount, bitsPerValue);             // to know how much to read
            int  longCount             = format.Int64Count(PackedInt32s.VERSION_CURRENT, valueCount, bitsPerValue); // to size the array

            blocks = new long[longCount];
            // read as many longs as we can
            for (int i = 0; i < byteCount / 8; ++i)
            {
                blocks[i] = @in.ReadInt64();
            }
            int remaining = (int)(byteCount % 8);

            if (remaining != 0)
            {
                // read the last bytes
                long lastLong = 0;
                for (int i = 0; i < remaining; ++i)
                {
                    lastLong |= (@in.ReadByte() & 0xFFL) << (56 - i * 8);
                }
                blocks[blocks.Length - 1] = lastLong;
            }
            maskRight         = (~0L << (BLOCK_SIZE - bitsPerValue)).TripleShift(BLOCK_SIZE - bitsPerValue);
            bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an array with the internal structures adjusted for the given
        /// limits and initialized to 0. </summary>
        /// <param name="valueCount">   The number of elements. </param>
        /// <param name="bitsPerValue"> The number of bits available for any given value. </param>
        public Packed64(int valueCount, int bitsPerValue)
            : base(valueCount, bitsPerValue)
        {
            PackedInt32s.Format format = PackedInt32s.Format.PACKED;
            int longCount = format.Int64Count(PackedInt32s.VERSION_CURRENT, valueCount, bitsPerValue);

            this.blocks       = new long[longCount];
            maskRight         = (~0L << (BLOCK_SIZE - bitsPerValue)).TripleShift(BLOCK_SIZE - bitsPerValue);
            bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an array with the internal structures adjusted for the given
        /// limits and initialized to 0. </summary>
        /// <param name="valueCount">   The number of elements. </param>
        /// <param name="bitsPerValue"> The number of bits available for any given value. </param>
        public Packed64(int valueCount, int bitsPerValue)
            : base(valueCount, bitsPerValue)
        {
            PackedInt32s.Format format = PackedInt32s.Format.PACKED;
            int longCount = format.Int64Count(PackedInt32s.VERSION_CURRENT, valueCount, bitsPerValue);

            this.blocks = new long[longCount];
            //            MaskRight = ~0L << (int)((uint)(BLOCK_SIZE - bitsPerValue) >> (BLOCK_SIZE - bitsPerValue));    //original
            //            MaskRight = (uint)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue);          //mod

            /*var a = ~0L << (int)((uint)(BLOCK_SIZE - bitsPerValue) >> (BLOCK_SIZE - bitsPerValue));    //original
             * var b = (uint)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue);          //mod
             * if (Debugging.AssertsEnabled) Debugging.Assert(a == b, "a: " + a, ", b: " + b);*/

            maskRight = (long)((ulong)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue));    //mod

            //if (Debugging.AssertsEnabled) Debugging.Assert((long)((ulong)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue)) == (uint)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue));

            bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
        }