Ejemplo n.º 1
0
 /// <summary>
 /// ASCII字节搜索器
 /// </summary>
 /// <param name="data">数据起始位置</param>
 internal AsciiSearcher(ref AutoCSer.Memory.Pointer data)
 {
     if (data.Data == null)
     {
         State     = charsAscii = null;
         tableType = 0;
     }
     else
     {
         int stateCount = *data.Int;
         State      = data.Byte + sizeof(int);
         charsAscii = State + stateCount * 3 * sizeof(int);
         if (stateCount < 256)
         {
             tableType = 0;
         }
         else if (stateCount < 65536)
         {
             tableType = 1;
         }
         else
         {
             tableType = 2;
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 名称查找器
 /// </summary>
 /// <param name="data">数据起始位置</param>
 internal StateSearcher(ref AutoCSer.Memory.Pointer data)
 {
     if (data.Data == null)
     {
         State     = charsAscii = charStart = charEnd = null;
         charIndex = 0;
         tableType = 0;
     }
     else
     {
         int stateCount = *data.Int;
         State      = data.Byte + sizeof(int);
         charsAscii = State + stateCount * 3 * sizeof(int);
         charStart  = charsAscii + 128 * sizeof(ushort);
         charIndex  = *(ushort *)charStart;
         charStart += sizeof(ushort) * 2;
         charEnd    = charStart + *(ushort *)(charStart - sizeof(ushort)) * sizeof(ushort);
         if (stateCount < 256)
         {
             tableType = 0;
         }
         else if (stateCount < 65536)
         {
             tableType = 1;
         }
         else
         {
             tableType = 2;
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 超时计数
 /// </summary>
 /// <param name="maxSeconds">最大超时秒数,必须大于 0</param>
 internal TimeoutCount(int maxSeconds)
 {
     if (maxSeconds > 0)
     {
         Counts = AutoCSer.Memory.Unmanaged.GetPointer8((maxSeconds + 2) << 2, true);
         Counts.CurrentIndex = Counts.ByteSize >> 2;
         AutoCSer.Threading.SecondTimer.SecondNodeLink.PushNotNull(this);
     }
 }
Ejemplo n.º 4
0
        static EnumULongDeSerialize()
        {
            enumInts = AutoCSer.Memory.Unmanaged.GetStaticPointer(enumValues.Length * sizeof(ulong), false);
            ulong *data = enumInts.ULong;

            foreach (T value in enumValues)
            {
                *(ulong *)data++ = AutoCSer.Metadata.EnumGenericType <T, ulong> .ToInt(value);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 数组排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="startIndex">起始位置</param>
        /// <param name="count">排序数据数量</param>
        /// <returns>排序后的数组</returns>
        public static valueType[] GetSortDesc <valueType>(valueType[] values, Func <valueType, ulong> getKey, int startIndex, int count)
        {
            int length = count * sizeof(ULongSortIndex);

            AutoCSer.Memory.UnmanagedPool pool = AutoCSer.Memory.UnmanagedPool.GetPool(length);
            AutoCSer.Memory.Pointer       data = pool.GetMinSize(length);
            try
            {
                return(getSortDesc(values, getKey, startIndex, count, (ULongSortIndex *)data.Data));
            }
            finally { pool.Push(ref data); }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 排序取Top N
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="count">排序数据数量</param>
        /// <returns>排序后的数据</returns>
        private static valueType[] getTopDesc <valueType>(valueType[] values, Func <valueType, ulong> getKey, int count)
        {
            uint sqrtMod;
            int  length = Math.Min(Math.Max(count << 2, count + (int)AutoCSer.Extensions.NumberExtension.sqrt((uint)values.Length, out sqrtMod)), values.Length), size = length * sizeof(ULongSortIndex);

            AutoCSer.Memory.UnmanagedPool pool = AutoCSer.Memory.UnmanagedPool.GetPool(size);
            AutoCSer.Memory.Pointer       data = pool.GetMinSize(size);
            try
            {
                return(getTopDesc(values, getKey, count, length, (ULongSortIndex *)data.Data));
            }
            finally { pool.Push(ref data); }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取字符串
        /// </summary>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public string GetString(Encoding encoding)
        {
            AutoCSer.Memory.Pointer memory = Memory;
            if (memory.ByteSize > 0)
            {
                int    size  = encoding.GetCharCount(memory.Byte, memory.ByteSize);
                string value = AutoCSer.Extensions.StringExtension.FastAllocateString(size);

                fixed(char *valueFixed = value) encoding.GetChars(memory.Byte, memory.ByteSize, valueFixed, size);

                return(value);
            }
            return(memory.Data == null ? null : string.Empty);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 数组范围排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <typeparam name="returnType">返回数据类型</typeparam>
        /// <param name="array">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="skipCount">跳过数据数量</param>
        /// <param name="getCount">排序数据数量</param>
        /// <param name="getValue">获取返回数据</param>
        /// <returns>排序后的数组</returns>
        internal static returnType[] UnsafeGetRangeSortDesc <valueType, returnType>(valueType[] array, Func <valueType, ulong> getKey, int skipCount, int getCount, Func <valueType, returnType> getValue)
        {
            if (getCount == 0)
            {
                return(EmptyArray <returnType> .Array);
            }
            int size = array.Length * sizeof(ULongSortIndex);

            AutoCSer.Memory.UnmanagedPool pool = AutoCSer.Memory.UnmanagedPool.GetPool(size);
            AutoCSer.Memory.Pointer       data = pool.GetMinSize(size);
            try
            {
                return(getRangeSortDesc(array, getKey, skipCount, getCount, getValue, (ULongSortIndex *)data.Data));
            }
            finally { pool.Push(ref data); }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 获取匹配数组
        /// </summary>
        /// <param name="array">数组数据</param>
        /// <param name="isValue">数据匹配器</param>
        /// <returns>匹配数组</returns>
        public static ulong[] getFindArray(this SubArray <ulong> array, Func <ulong, bool> isValue)
        {
            if (array.Length == 0)
            {
                return(EmptyArray <ulong> .Array);
            }
            int length = ((array.Length + 63) >> 6) << 3;

            AutoCSer.Memory.UnmanagedPool pool = AutoCSer.Memory.UnmanagedPool.GetPool(length);
            AutoCSer.Memory.Pointer       data = pool.GetMinSize(length);
            try
            {
                AutoCSer.Memory.Common.Clear(data.ULong, length >> 3);
                return(FixedArray.GetFindArray(array.Array, array.Start, array.Length, isValue, new MemoryMap(data.Data)));
            }
            finally { pool.Push(ref data); }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 数组子串排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="array">待排序数组子串</param>
        /// <param name="getKey">排序键</param>
        /// <param name="index">起始位置</param>
        /// <param name="count">数量</param>
        /// <returns>排序后的数组</returns>
        internal static valueType[] GetSortDesc <valueType>(valueType[] array, Func <valueType, ulong> getKey, int index, int count)
        {
            if (count >= AutoCSer.Algorithm.RadixSort.SortSize64)
            {
                int size = (count << 1) * sizeof(AutoCSer.Algorithm.ULongSortIndex);

                AutoCSer.Memory.UnmanagedPool pool = AutoCSer.Memory.UnmanagedPool.GetPool(size);
                AutoCSer.Memory.Pointer       data = pool.GetMinSize(size);
                try
                {
                    AutoCSer.Algorithm.ULongSortIndex *indexFixed = (AutoCSer.Algorithm.ULongSortIndex *)data.Data;
                    AutoCSer.Algorithm.ULongSortIndex.Create(indexFixed, array, getKey, index, count);
                    AutoCSer.Algorithm.RadixSort.SortDesc(indexFixed, indexFixed + count, count);
                    return(AutoCSer.Algorithm.ULongSortIndex.Create(indexFixed, array, count));
                }
                finally { pool.Push(ref data); }
            }
            return(AutoCSer.Algorithm.FixedArrayQuickSort.GetSortDesc(array, getKey, index, count));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// ASCII字节搜索器
        /// </summary>
        /// <param name="data">数据起始位置</param>
        public DomainSearcher(ref AutoCSer.Memory.Pointer data)
        {
            int stateCount = *data.Int;

            State = data.Byte + sizeof(int);
            bytes = State + stateCount * 3 * sizeof(int);
            if (stateCount < 256)
            {
                tableType = 0;
            }
            else if (stateCount < 65536)
            {
                tableType = 1;
            }
            else
            {
                tableType = 2;
            }
        }
Ejemplo n.º 12
0
 private unsafe static bool parseRefund(AutoCSer.XmlDeSerializer parser, ref RefundResult value, ref AutoCSer.Memory.Pointer name)
 {
     return(value.parseRefund(parser, name.Char));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 创建位图
        /// </summary>
        /// <param name="globalColors">全局颜色列表</param>
        /// <returns>位图,失败返回null</returns>
        public unsafe Bitmap CreateBitmap(Color[] globalColors)
        {
            if (Width == 0 || Height == 0 || LzwSize == 0 || LzwSize > 8)
            {
                return(null);
            }
            int colorSize = Width * Height;

            AutoCSer.Memory.Pointer colorIndexs = Writer.LzwEncodeTableBufferPool.GetMinSize(colorSize);
            try
            {
                int length = lzwDecode(Decoder.BlocksToByte(ref LzwDatas), colorIndexs.Byte, LzwSize);
                if (length == colorSize)
                {
                    Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
                    try
                    {
                        BitmapData bitmapData  = bitmap.LockBits(new Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
                        byte *     bitmapFixed = (byte *)bitmapData.Scan0;
                        int        bitMapSpace = bitmapData.Stride - (Width << 1) - Width;
                        if (globalColors == null)
                        {
                            globalColors = Colors;
                        }
                        if (globalColors != null)
                        {
                            fixed(Color *colorFixed = globalColors)
                            {
                                ImageFillBitmap fillBitmap = new ImageFillBitmap {
                                    CurrentIndex = colorIndexs.Byte, Colors = colorFixed, Width = Width
                                };

                                if (InterlaceFlag == 0)
                                {
                                    fillBitmap.FillColor(Height, bitmapFixed, bitMapSpace);
                                }
                                else
                                {
                                    int bitmapStride = bitMapSpace + (bitmapData.Stride << 3) - bitmapData.Stride;
                                    fillBitmap.FillColor((Height + 7) >> 3, bitmapFixed, bitmapStride);
                                    fillBitmap.FillColor((Height + 3) >> 3, bitmapFixed + (bitmapData.Stride << 2), bitmapStride);
                                    fillBitmap.FillColor((Height + 1) >> 2, bitmapFixed + (bitmapData.Stride << 1), bitmapStride -= bitmapData.Stride << 2);
                                    fillBitmap.FillColor(Height >> 1, bitmapFixed + bitmapData.Stride, bitmapStride - (bitmapData.Stride << 1));
                                }
                            }
                        }
                        else
                        {
                            ImageFillBitmap fillBitmap = new ImageFillBitmap {
                                CurrentIndex = colorIndexs.Byte, Width = Width
                            };
                            if (InterlaceFlag == 0)
                            {
                                fillBitmap.FillIndex(Height, bitmapFixed, bitMapSpace);
                            }
                            else
                            {
                                int bitmapStride = bitMapSpace + (bitmapData.Stride << 3) - bitmapData.Stride;
                                fillBitmap.FillIndex((Height + 7) >> 3, bitmapFixed, bitmapStride);
                                fillBitmap.FillIndex((Height + 3) >> 3, bitmapFixed + (bitmapData.Stride << 2), bitmapStride);
                                fillBitmap.FillIndex((Height + 1) >> 2, bitmapFixed + (bitmapData.Stride << 1), bitmapStride -= bitmapData.Stride << 2);
                                fillBitmap.FillIndex(Height >> 1, bitmapFixed + bitmapData.Stride, bitmapStride - (bitmapData.Stride << 1));
                            }
                        }
                        bitmap.UnlockBits(bitmapData);
                        return(bitmap);
                    }
                    catch (Exception error)
                    {
                        bitmap.Dispose();
                        AutoCSer.LogHelper.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
                    }
                }
            }
            finally { Writer.LzwEncodeTableBufferPool.Push(ref colorIndexs); }
            return(null);
        }
Ejemplo n.º 14
0
 internal void Reset(void *data, int size)
 {
     AutoCSer.Memory.Pointer buffer = new AutoCSer.Memory.Pointer(data, size);
     Reset(ref buffer);
 }
Ejemplo n.º 15
0
 private unsafe static bool parseCoupon(AutoCSer.XmlDeSerializer parser, ref OrderResult value, ref AutoCSer.Memory.Pointer name)
 {
     return(value.parseCoupon(parser, name.Char));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// ASCII字节搜索器
 /// </summary>
 /// <param name="data">数据起始位置</param>
 internal AsciiSearcher(AutoCSer.Memory.Pointer data) : this(ref data) { }