Пример #1
0
 /// <summary>
 /// 连接数组
 /// </summary>
 /// <typeparam name="arrayType">目标数组类型</typeparam>
 /// <param name="getValue">数据获取器</param>
 /// <returns>目标数组</returns>
 public subArray <arrayType> Concat <arrayType>(Func <valueType, subArray <arrayType> > getValue)
 {
     if (getValue == null)
     {
         log.Error.Throw(log.exceptionType.Null);
     }
     if (length != 0)
     {
         subArray <arrayType> values = new subArray <arrayType>();
         if (startIndex == 0)
         {
             int index = length;
             foreach (valueType value in array)
             {
                 values.Add(getValue(value));
                 if (--index == 0)
                 {
                     break;
                 }
             }
         }
         else
         {
             int index = startIndex, endIndex = startIndex + length;
             do
             {
                 values.Add(getValue(array[index]));
             }while (++index != endIndex);
         }
         return(values);
     }
     return(default(subArray <arrayType>));
 }
Пример #2
0
        internal unsafe void FromCookie(ref subArray <byte> data)
        {
            if (data.length == 64)
            {
                fixed(byte *dataFixed = data.array)
                {
                    byte *start = dataFixed + data.startIndex;

                    bit32 = number.ParseHex32(start);
                    bit0  = number.ParseHex32(start + 8);

                    bit96 = number.ParseHex32(start + 16);
                    bit64 = number.ParseHex32(start + 24);

                    bit160 = number.ParseHex32(start + 32);
                    bit128 = number.ParseHex32(start + 40);

                    bit224 = number.ParseHex32(start + 48);
                    bit192 = number.ParseHex32(start + 56);
                }

                return;
            }
            Low   = 1;
            Ticks = 0;
        }
Пример #3
0
        /// <summary>
        /// 分割字符串
        /// </summary>
        /// <param name="value">原字符串</param>
        /// <param name="startIndex">起始位置</param>
        /// <param name="length">分割字符串长度</param>
        /// <param name="split">分割符</param>
        /// <returns>字符子串集合</returns>
        public unsafe static subArray <subString> split(this string value, int startIndex, int length, char split)
        {
            array.range range = new array.range(value.length(), startIndex, length);
            if (range.GetCount != length)
            {
                fastCSharp.log.Error.Throw(log.exceptionType.IndexOutOfRange);
            }
            subArray <subString> values = default(subArray <subString>);

            if (value != null)
            {
                fixed(char *valueFixed = value)
                {
                    char *last = valueFixed + range.SkipCount, end = last + range.GetCount;

                    for (char *start = last; start != end;)
                    {
                        if (*start == split)
                        {
                            values.Add(subString.Unsafe(value, (int)(last - valueFixed), (int)(start - last)));
                            last = ++start;
                        }
                        else
                        {
                            ++start;
                        }
                    }
                    values.Add(subString.Unsafe(value, (int)(last - valueFixed), (int)(end - last)));
                }
            }
            return(values);
        }
Пример #4
0
 /// <summary>
 /// 数据排序分组数量
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="array">数据数组</param>
 /// <param name="getValue">数据获取器</param>
 /// <returns>目标数据集合数量</returns>
 public unsafe static int sortGroupCount <valueType>
     (this subArray <valueType> array, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getValue)
 {
     if (array.Count != 0)
     {
         if (getValue == null)
         {
             log.Error.Throw(log.exceptionType.Null);
         }
         valueType[] sortArray = arrayExtension.getSort(array.UnsafeArray, getValue, array.StartIndex, array.Count);
         /*Type[0]*/
         ulong /*Type[0]*/ key = getValue(sortArray[0]);
         int count             = 0;
         for (int index = 1; index != sortArray.Length; ++index)
         {
             /*Type[0]*/
             ulong /*Type[0]*/ nextKey = getValue(sortArray[index]);
             if (key != nextKey)
             {
                 ++count;
                 key = nextKey;
             }
         }
         return(count + 1);
     }
     return(0);
 }
Пример #5
0
 /// <summary>
 /// 数据排序分组
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="array">数据数组</param>
 /// <param name="getValue">数据获取器</param>
 /// <returns>目标数据集合</returns>
 public unsafe static subArray <subArray <valueType> > sortGroup <valueType>
     (this subArray <valueType> array, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getValue)
 {
     if (array.Count != 0)
     {
         if (getValue == null)
         {
             log.Error.Throw(log.exceptionType.Null);
         }
         valueType[]            sortArray = arrayExtension.getSort(array.UnsafeArray, getValue, array.StartIndex, array.Count);
         subArray <valueType>[] values    = new subArray <valueType> [sortArray.Length];
         /*Type[0]*/
         ulong /*Type[0]*/ key = getValue(sortArray[0]);
         int startIndex = 0, valueIndex = 0;
         for (int index = 1; index != sortArray.Length; ++index)
         {
             /*Type[0]*/
             ulong /*Type[0]*/ nextKey = getValue(sortArray[index]);
             if (key != nextKey)
             {
                 values[valueIndex++].UnsafeSet(sortArray, startIndex, index - startIndex);
                 key        = nextKey;
                 startIndex = index;
             }
         }
         values[valueIndex++].UnsafeSet(sortArray, startIndex, sortArray.Length - startIndex);
         return(subArray <subArray <valueType> > .Unsafe(values, 0, valueIndex));
     }
     return(default(subArray <subArray <valueType> >));
 }
Пример #6
0
        /// <summary>
        /// 分割字符串并返回数值集合(不检查数字合法性)
        /// </summary>
        /// <param name="ints">原字符串</param>
        /// <param name="split">分割符</param>
        /// <returns>数值集合</returns>
        public unsafe static subArray <int> splitIntNoCheck(this string ints, char split)
        {
            subArray <int> values = new subArray <int>();

            if (ints != null && ints.Length != 0)
            {
                fixed(char *intPoint = ints)
                {
                    int intValue = 0;

                    for (char *next = intPoint, end = intPoint + ints.Length; next != end; ++next)
                    {
                        if (*next == split)
                        {
                            values.Add(intValue);
                            intValue = 0;
                        }
                        else
                        {
                            intValue *= 10;
                            intValue += *next;
                            intValue -= '0';
                        }
                    }
                    values.Add(intValue);
                }
            }
            return(values);
        }
Пример #7
0
 /// <summary>
 /// 数组枚举器
 /// </summary>
 /// <param name="value">数组子串</param>
 public array(subArray <valueType> value)
 {
     values       = value.array;
     startIndex   = value.startIndex;
     endIndex     = value.EndIndex;
     currentIndex = startIndex - 1;
 }
Пример #8
0
 public void Add(ref subArray <valueType> values)
 {
     if (values.length != 0)
     {
         add(values.array, values.startIndex, values.length);
     }
 }
Пример #9
0
 public static valueType[] getSort/*Compare[0]*//*Compare[0]*/ <valueType>(this subArray <valueType> array, Func <valueType, /*Type[0]*/ double /*Type[0]*/> getKey)
 {
     if (array.Count > 1)
     {
         return(fastCSharp.algorithm.quickSort.GetSort/*Compare[0]*//*Compare[0]*/ (array.UnsafeArray, getKey, array.StartIndex, array.Count));
     }
     return(array.Count == 0 ? nullValue <valueType> .Array : new valueType[] { array.UnsafeArray[array.StartIndex] });
 }
Пример #10
0
 public static subArray </*Type[0]*/ ulong /*Type[0]*/> getRangeSort/*Compare[0]*//*Compare[0]*/
     (this subArray </*Type[0]*/ ulong /*Type[0]*/> array, int skipCount, int getCount)
 {
     if (array.Count != 0)
     {
         return(fastCSharp.algorithm.quickSort.GetRangeSort/*Compare[0]*//*Compare[0]*/ (array.UnsafeArray, array.StartIndex, array.Count, skipCount, getCount));
     }
     return(default(subArray </*Type[0]*/ ulong /*Type[0]*/>));
 }
Пример #11
0
 public static valueType[] getRangeSort/*Compare[0]*//*Compare[0]*/ <valueType>
     (this subArray <valueType> array, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int skipCount, int getCount)
 {
     if (array.Count != 0)
     {
         return(fastCSharp.algorithm.quickSort.GetRangeSort/*Compare[0]*//*Compare[0]*/
                    (array.UnsafeArray, array.StartIndex, array.Count, getKey, skipCount, getCount));
     }
     return(nullValue <valueType> .Array);
 }
Пример #12
0
        /// <summary>
        /// 写数据
        /// </summary>
        /// <param name="data">数据</param>
        public void Write(ref subArray <byte> data)
        {
            int count = data.length;

            if (count != 0)
            {
                prepLength(count);
                Buffer.BlockCopy(data.array, data.startIndex, array, Length, count);
                Length += count;
            }
        }
Пример #13
0
 public unsafe static void joinString(this subArray <int> array, charStream stream, char join, bool isNull = false)
 {
     if (array.length == 0)
     {
         if (isNull)
         {
             fastCSharp.web.ajax.WriteNull(stream);
         }
         return;
     }
     fastCSharp.emit.numberToCharStream <int> .NumberJoinChar(stream, array.array, array.startIndex, array.length, join, isNull);
 }
Пример #14
0
        /// <summary>
        /// 分页排序
        /// </summary>
        /// <param name="array">数组子串</param>
        /// <param name="pageSize">分页尺寸</param>
        /// <param name="currentPage">页号</param>
        /// <returns>分页排序数据</returns>
        public static subArray </*Type[0]*/ ulong /*Type[0]*/> getPageSort/*Compare[0]*//*Compare[0]*/
            (this subArray </*Type[0]*/ ulong /*Type[0]*/> array, int pageSize, int currentPage)
        {
            array.page page     = new array.page(array.Count, pageSize, currentPage);
            int        getCount = page.CurrentPageSize;

            if (getCount != 0)
            {
                return(fastCSharp.algorithm.quickSort.GetRangeSort/*Compare[0]*//*Compare[0]*/ (array.UnsafeArray, array.StartIndex, array.Count, page.SkipCount, getCount));
            }
            return(default(subArray </*Type[0]*/ ulong /*Type[0]*/>));
        }
Пример #15
0
 public unsafe static string deSerialize(this subArray <byte> data)
 {
     if (data.array != null)
     {
         if (data.length != 0)
         {
             fixed(byte *dataFixed = data.array) return(UnsafeDeSerialize(dataFixed + data.startIndex, -data.length));
         }
         return(string.Empty);
     }
     return(null);
 }
Пример #16
0
        public unsafe bool IsMatchLess(ref subArray <byte> values)
        {
            if (values.Count != 0)
            {
                fixed(byte *valueFixed = values.UnsafeArray)
                {
                    byte *start = valueFixed + values.StartIndex;

                    return(isMatchLess(start, start + values.Count));
                }
            }
            return(false);
        }
Пример #17
0
 /// <summary>
 /// 字节数组比较
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns>是否相等</returns>
 public unsafe static bool equal(this subArray <byte> left, ref subArray <byte> right)
 {
     if (left.array == null)
     {
         return(right.array == null);
     }
     if (left.length == right.length)
     {
         fixed(byte *leftFixed = left.array, rightFixed = right.array)
         {
             return(unsafer.memory.Equal(leftFixed + left.startIndex, rightFixed + right.startIndex, left.length));
         }
     }
     return(false);
 }
Пример #18
0
        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="data">数据</param>
        public void Write(ref subArray <byte> data)
        {
            int count = data.length;

            if (count != 0)
            {
                prepLength(count);
                fixed(byte *dataFixed = data.array)
                {
                    fastCSharp.unsafer.memory.Copy(dataFixed + data.startIndex, this.data.Byte + length, count);
                }

                length += count;
            }
        }
Пример #19
0
 /// <summary>
 /// 字节数组HASH
 /// </summary>
 /// <param name="data">字节数组</param>
 public unsafe hashBytes(ref subArray <byte> data)
 {
     this.data = data;
     if (data.length == 0)
     {
         hashCode = 0;
     }
     else
     {
         fixed(byte *dataFixed = data.array)
         {
             hashCode = algorithm.hashCode.GetHashCode(dataFixed + data.startIndex, data.length) ^ random.Hash;
         }
     }
 }
Пример #20
0
        ///// <summary>
        ///// 判断时间是否相等
        ///// </summary>
        ///// <param name="date"></param>
        ///// <param name="dataArray"></param>
        ///// <returns></returns>
        //[MethodImpl((MethodImplOptions)fastCSharp.pub.MethodImplOptionsAggressiveInlining)]
        //internal unsafe static int ByteEquals(DateTime date, subArray<byte> dataArray)
        //{
        //    return UniversalByteEquals(date.toUniversalTime(), dataArray);
        //}
        /// <summary>
        /// 判断时间是否相等
        /// </summary>
        /// <param name="date"></param>
        /// <param name="dataArray"></param>
        /// <returns></returns>
        internal unsafe static int UniversalByteEquals(DateTime date, subArray <byte> dataArray)
        {
            fixed(byte *dataFixed = dataArray.array)
            {
                byte *data = dataFixed + dataArray.startIndex;

                if (((*(int *)data ^ weekData.Int[(int)date.DayOfWeek]) | (*(data + sizeof(int) * 7) ^ (byte)'T')) != 0)
                {
                    return(1);
                }
                int value = date.Day, value10 = (value * (int)number.Div10_16Mul) >> number.Div10_16Shift;

                if (*(int *)(data + sizeof(int)) != ((' ' + (value10 << 8) + ((value - value10 * 10) << 16) + (' ' << 24)) | 0x303000))
                {
                    return(1);
                }
                value = date.Year;
                if (*(int *)(data + sizeof(int) * 2) != monthData.Int[date.Month - 1])
                {
                    return(1);
                }
                value10 = (value * (int)number.Div10_16Mul) >> number.Div10_16Shift;
                int value100  = (value10 * (int)number.Div10_16Mul) >> number.Div10_16Shift;
                int value1000 = (value100 * (int)number.Div10_16Mul) >> number.Div10_16Shift;

                if (*(int *)(data + sizeof(int) * 3) != ((value1000 + ((value100 - value1000 * 10) << 8) + ((value10 - value100 * 10) << 16) + ((value - value10 * 10) << 24)) | 0x30303030))
                {
                    return(1);
                }


                value100   = (int)(date.Ticks % DayTiks / (1000 * 10000));
                value1000  = (int)(((ulong)value100 * Div60_32Mul) >> Div60_32Shift);
                value100  -= value1000 * 60;
                value      = (value1000 * (int)Div60_16Mul) >> Div60_16Shift;
                value1000 -= value * 60;

                value10 = (value * (int)number.Div10_16Mul) >> number.Div10_16Shift;
                if (*(int *)(data + sizeof(int) * 4) != ((' ' + (value10 << 8) + ((value - value10 * 10) << 16) + (':' << 24)) | 0x303000))
                {
                    return(1);
                }
                value10 = (value1000 * (int)number.Div10_16Mul) >> number.Div10_16Shift;
                value   = (value100 * (int)number.Div10_16Mul) >> number.Div10_16Shift;
                return((*(int *)(data + sizeof(int) * 5) ^ ((value10 + ((value1000 - value10 * 10) << 8) + (':' << 16) + (value << 24)) | 0x30003030))
                       | (*(int *)(data + sizeof(int) * 6) ^ ((value100 - value * 10) + '0') + (' ' << 8) + ('G' << 16) + ('M' << 24)));
            }
        }
Пример #21
0
 /// <summary>
 /// 数据去重
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="array">数据数组</param>
 /// <param name="getValue">数据获取器</param>
 /// <returns>目标数据集合</returns>
 public unsafe static subArray </*Type[0]*/ ulong /*Type[0]*/> distinct <valueType>
     (this subArray <valueType> array, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getValue)
 {
     if (array.Count != 0)
     {
         if (getValue == null)
         {
             log.Error.Throw(log.exceptionType.Null);
         }
         /*Type[0]*/
         ulong /*Type[0]*/[] newValues = array.getArray(getValue);
         arrayExtension.sort(newValues, 0, newValues.Length);
         return(newValues.distinct());
     }
     return(default(subArray </*Type[0]*/ ulong /*Type[0]*/>));
 }
Пример #22
0
        /// <summary>
        /// 数据转换成单向动态数组
        /// </summary>
        /// <returns>单向动态数组</returns>
        public unsafe subArray <valueType> GetList()
        {
            subArray <valueType> values = new subArray <valueType>(array.Length);

            fixed(range *indexFixed = indexs)
            {
                for (range *index = indexFixed + indexs.Length; index != indexFixed;)
                {
                    for (range range = *--index; range.StartIndex != range.EndIndex; ++range.StartIndex)
                    {
                        values.UnsafeAdd(array[range.StartIndex]);
                    }
                }
            }

            return(values);
        }
Пример #23
0
        /// <summary>
        /// 获取匹配的数据集合
        /// </summary>
        /// <typeparam name="listType">目标数据类型</typeparam>
        /// <param name="getValue">数据转换器</param>
        /// <returns>匹配的数据集合</returns>
        protected unsafe subArray <listType> getList <listType>(Func <valueType, listType> getValue)
        {
            subArray <listType> values = new subArray <listType>(array.Length);

            fixed(range *indexFixed = indexs)
            {
                for (range *index = indexFixed + indexs.Length; index != indexFixed;)
                {
                    for (range range = *--index; range.StartIndex != range.EndIndex; ++range.StartIndex)
                    {
                        values.UnsafeAdd(getValue(array[range.StartIndex]));
                    }
                }
            }

            return(values);
        }
Пример #24
0
        /// <summary>
        /// 比较字节数组是否相等
        /// </summary>
        /// <param name="other">用于HASH的字节数组</param>
        /// <returns>是否相等</returns>
        public unsafe bool Equals(subArray <byte> other)
        {
            if (data.array == null)
            {
                return(other.array == null);
            }
            if (other.array != null && data.length == other.length)
            {
                if (data.array == other.array && data.startIndex == other.startIndex)
                    return(true);

                fixed(byte *dataFixed = data.array, otherDataFixed = other.array)
                {
                    return(unsafer.memory.Equal(dataFixed + data.startIndex, otherDataFixed + other.startIndex, data.length));
                }
            }
            return(false);
        }
Пример #25
0
        /// <summary>
        /// 连接字符串集合
        /// </summary>
        /// <param name="values">字符串集合</param>
        /// <param name="join">字符连接</param>
        /// <returns>连接后的字符串</returns>
        public unsafe static string joinString(this subArray <string> values, char join)
        {
            if (values.array != null)
            {
                if (values.length > 1)
                {
                    string[] array  = values.array;
                    int      length = 0;
                    for (int index = values.startIndex, endIndex = index + values.length; index != endIndex; ++index)
                    {
                        string value = array[index];
                        if (value != null)
                        {
                            length += value.Length;
                        }
                    }
                    string newValue = fastCSharp.String.FastAllocateString(length + values.length - 1);
                    fixed(char *valueFixed = newValue)
                    {
                        char *write = valueFixed;

                        for (int index = values.startIndex, endIndex = index + values.length; index != endIndex; ++index)
                        {
                            string value = array[index];
                            if (value != null)
                            {
                                unsafer.String.Copy(value, write);
                                write += value.Length;
                            }
                            *write++ = join;
                        }
                    }

                    return(newValue);
                }
                else if (values.length == 1)
                {
                    return(values.array[values.startIndex] ?? string.Empty);
                }
                return(string.Empty);
            }
            return(null);
        }
Пример #26
0
        /// <summary>
        /// 数据去重
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="array">数据数组</param>
        /// <param name="getValue">数据获取器</param>
        /// <returns>目标数据集合</returns>
        public unsafe static valueType[] distinct <valueType>
            (this subArray </*Type[0]*/ ulong /*Type[0]*/> array, Func </*Type[0]*/ ulong /*Type[0]*/, valueType> getValue)
        {
            if (array.Count != 0)
            {
                if (getValue == null)
                {
                    log.Error.Throw(log.exceptionType.Null);
                }
                arrayExtension.sort(array.UnsafeArray, array.StartIndex, array.Count);
                fixed(/*Type[0]*/ ulong /*Type[0]*/ *valueFixed = array.UnsafeArray)
                {
                    /*Type[0]*/
                    ulong /*Type[0]*/ *start = valueFixed + array.StartIndex, end = start + array.Count;
                    /*Type[0]*/
                    ulong /*Type[0]*/ value = *start;
                    int count = 1;

                    while (++start != end)
                    {
                        if (*start != value)
                        {
                            ++count;
                            value = *start;
                        }
                    }
                    valueType[] values = new valueType[count];
                    values[0] = getValue(value = *(start = valueFixed + array.StartIndex));
                    count     = 1;
                    while (++start != end)
                    {
                        if (*start != value)
                        {
                            values[count++] = getValue(value = *start);
                        }
                    }
                    return(values);
                }
            }
            return(nullValue <valueType> .Array);
        }
Пример #27
0
 /// <summary>
 /// 查找符合条件的记录集合
 /// </summary>
 /// <typeparam name="valueType">值类型</typeparam>
 /// <param name="values">值集合</param>
 /// <param name="isValue">判断记录是否符合条件的委托</param>
 /// <returns>符合条件的记录集合</returns>
 public static subArray <valueType> getFind <valueType>
     (this IEnumerable <valueType> values, Func <valueType, bool> isValue)
 {
     if (values != null)
     {
         if (isValue == null)
         {
             log.Error.Throw(log.exceptionType.Null);
         }
         subArray <valueType> value = new subArray <valueType>();
         foreach (valueType nextValue in values)
         {
             if (isValue(nextValue))
             {
                 value.Add(nextValue);
             }
         }
         return(value);
     }
     return(default(subArray <valueType>));
 }
Пример #28
0
        /// <summary>
        /// 获取匹配的数据集合
        /// </summary>
        /// <param name="isValue">数据匹配器</param>
        /// <returns>匹配的数据集合</returns>
        protected unsafe subArray <valueType> getList(Func <valueType, bool> isValue)
        {
            subArray <valueType> values = new subArray <valueType>(array.Length);

            fixed(range *indexFixed = indexs)
            {
                for (range *index = indexFixed + indexs.Length; index != indexFixed;)
                {
                    for (range range = *--index; range.StartIndex != range.EndIndex; ++range.StartIndex)
                    {
                        valueType value = array[range.StartIndex];
                        if (isValue(value))
                        {
                            values.UnsafeAdd(value);
                        }
                    }
                }
            }

            return(values);
        }
Пример #29
0
        /// <summary>
        /// 获取对象数组
        /// </summary>
        /// <returns></returns>
        public subArray <valueType> GetArray()
        {
            int count = poolIndex;

            if (count != 0)
            {
                subArray <valueType> values = new subArray <valueType>(count);
                foreach (valueType value in pool)
                {
                    if (value != null)
                    {
                        values.UnsafeAdd(value);
                    }
                    if (--count == 0)
                    {
                        break;
                    }
                }
                return(values);
            }
            return(default(subArray <valueType>));
        }
Пример #30
0
        /// <summary>
        /// 数据去重
        /// </summary>
        /// <param name="array">数据数组</param>
        /// <returns>目标数据集合</returns>
        public unsafe static subArray </*Type[0]*/ ulong /*Type[0]*/> distinct(this subArray </*Type[0]*/ ulong /*Type[0]*/> array)
        {
            if (array.Count > 1)
            {
                arrayExtension.sort(array.UnsafeArray, array.StartIndex, array.Count);
                fixed(/*Type[0]*/ ulong /*Type[0]*/ *valueFixed = array.UnsafeArray)
                {
                    /*Type[0]*/
                    ulong /*Type[0]*/ *write = valueFixed + array.StartIndex, start = write + 1, end = write + array.Count;

                    do
                    {
                        if (*start != *write)
                        {
                            *++write = *start;
                        }
                    }while (++start != end);
                    return(subArray </*Type[0]*/ ulong /*Type[0]*/> .Unsafe(array.UnsafeArray, array.StartIndex, (int)(write - valueFixed) + 1 - array.StartIndex));
                }
            }
            return(array);
        }