コード例 #1
0
ファイル: DynamicArrayStore.cs プロジェクト: Neo4Net/Neo4Net
        private static sbyte[] CreateBitCompactedArray(ShortArray type, object array, int offsetBytes)
        {
            Type componentType        = array.GetType().GetElementType();
            bool isPrimitiveByteArray = componentType.Equals(Byte.TYPE);
            bool isByteArray          = componentType.Equals(typeof(Byte)) || isPrimitiveByteArray;
            int  arrayLength          = Array.getLength(array);
            int  requiredBits         = isByteArray ? (sizeof(sbyte) * 8) : type.calculateRequiredBitsForArray(array, arrayLength);
            int  totalBits            = requiredBits * arrayLength;
            int  bitsUsedInLastByte   = totalBits % 8;

            bitsUsedInLastByte = bitsUsedInLastByte == 0 ? 8 : bitsUsedInLastByte;
            if (isByteArray)
            {
                return(CreateBitCompactedByteArray(type, isPrimitiveByteArray, array, bitsUsedInLastByte, requiredBits, offsetBytes));
            }
            else
            {
                int numberOfBytes = (totalBits - 1) / 8 + 1;
                numberOfBytes += NUMBER_HEADER_SIZE;                         // type + rest + requiredBits header. TODO no need to use full bytes
                Bits bits = Bits.bits(numberOfBytes);
                bits.Put(( sbyte )type.intValue());
                bits.Put(( sbyte )bitsUsedInLastByte);
                bits.Put(( sbyte )requiredBits);
                type.writeAll(array, arrayLength, requiredBits, bits);
                return(bits.AsBytes(offsetBytes));
            }
        }
コード例 #2
0
ファイル: DynamicArrayStore.cs プロジェクト: Neo4Net/Neo4Net
        private static sbyte[] CreateUncompactedArray(ShortArray type, object array, int offsetBytes)
        {
            int arrayLength     = Array.getLength(array);
            int bytesPerElement = type.maxBits / 8;

            sbyte[] bytes = new sbyte[NUMBER_HEADER_SIZE + bytesPerElement * arrayLength + offsetBytes];
            bytes[offsetBytes + 0] = ( sbyte )type.intValue();
            bytes[offsetBytes + 1] = ( sbyte )8;
            bytes[offsetBytes + 2] = ( sbyte )type.maxBits;
            type.writeAll(array, bytes, NUMBER_HEADER_SIZE + offsetBytes);
            return(bytes);
        }