/// <summary> /// 数组范围排序 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <param name="values">待排序数组</param> /// <param name="startIndex">起始位置</param> /// <param name="count">排序范围数据数量</param> /// <param name="getKey">排序键值获取器</param> /// <param name="skipCount">跳过数据数量</param> /// <param name="getCount">排序数据数量</param> /// <returns>排序后的数组</returns> public unsafe static valueType[] GetRangeSort/*Compare[0]*//*Compare[0]*/ <valueType> (valueType[] values, int startIndex, int count, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int skipCount, int getCount) { array.range range = new array.range(values.length(), startIndex, count); if ((count = range.GetCount) != 0) { array.range getRange = new array.range(count, skipCount, getCount); if ((getCount = getRange.GetCount) != 0) { if (getKey == null) { log.Error.Throw(log.exceptionType.Null); } unmanagedPool pool = fastCSharp.unmanagedPool.GetDefaultPool(count * sizeof(/*Type[2]*/ ulongSortIndex /*Type[2]*/)); pointer.size data = pool.Get(count * sizeof(/*Type[2]*/ ulongSortIndex /*Type[2]*/)); try { return(getRangeSort/*Compare[0]*//*Compare[0]*/ (values, range.SkipCount, count, getKey, getRange.SkipCount, getCount, (/*Type[2]*/ ulongSortIndex /*Type[2]*/ *)data.Data)); } finally { pool.Push(ref data); } } } return(nullValue <valueType> .Array); }
/// <summary> /// 增加数据 /// </summary> /// <param name="value">新增的数据</param> private void onInserted(valueType value) { int *intCounts = counts.Int; int identity = GetKey(value); if (identity >= size) { int newLength = int.MaxValue, oldLength = size; if ((identity & 0x40000000) == 0 && oldLength != 0x40000000) { for (newLength = oldLength << 1; newLength <= identity; newLength <<= 1) { ; } } values.ToSize(newLength); pointer.size newCounts = unmanaged.Get(newLength * sizeof(int), true); try { unsafer.memory.Copy(intCounts, newCounts.Int, size * sizeof(int)); unmanaged.Free(ref counts); counts = newCounts; size = newLength; newCounts.Null(); int index = oldLength, count = (intCounts = counts.Int)[--index]; for (int step = 1; (index -= step) != 0; step <<= 1) { count += intCounts[index]; } intCounts[oldLength] = count; } catch (Exception error) { log.Error.Add(error, null, true); } finally { unmanaged.Free(ref newCounts); } } valueType newValue = fastCSharp.emit.constructor <valueType> .New(); fastCSharp.emit.memberCopyer <modelType> .Copy(newValue, value, memberMap); setMemberCacheAndValue(newValue); values[identity] = newValue; for (uint index = (uint)identity, countStep = 1, length = (uint)size; index <= length; countStep <<= 1) { ++intCounts[index]; while ((index & countStep) == 0) { countStep <<= 1; } index += countStep; } ++Count; callOnInserted(newValue); }
/// <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 unsafe static valueType[] GetSort/*Compare[0]*//*Compare[0]*/ <valueType> (valueType[] values, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int startIndex, int count) { unmanagedPool pool = fastCSharp.unmanagedPool.GetDefaultPool(count * sizeof(/*Type[1]*/ ulongSortIndex /*Type[1]*/)); pointer.size data = pool.Get(count * sizeof(/*Type[1]*/ ulongSortIndex /*Type[1]*/)); try { return(getSort/*Compare[0]*//*Compare[0]*/ (values, getKey, startIndex, count, (/*Type[1]*/ ulongSortIndex /*Type[1]*/ *)data.Data)); } finally { pool.Push(ref data); } }
/// <summary> /// 排序取Top N /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <param name="values">待排序数组</param> /// <param name="getKey">排序键值获取器</param> /// <param name="count">排序数据数量</param> /// <returns>排序后的数据</returns> private unsafe static valueType[] getTop/*Compare[0]*//*Compare[0]*/ <valueType> (valueType[] values, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int count) { uint sqrtMod; int length = Math.Min(Math.Max(count << 2, count + (int)number.sqrt((uint)values.Length, out sqrtMod)), values.Length); unmanagedPool pool = fastCSharp.unmanagedPool.GetDefaultPool(length * sizeof(/*Type[2]*/ ulongSortIndex /*Type[2]*/)); pointer.size data = pool.Get(length * sizeof(/*Type[2]*/ ulongSortIndex /*Type[2]*/)); try { return(getTop/*Compare[0]*//*Compare[0]*/ (values, getKey, count, length, (/*Type[2]*/ ulongSortIndex /*Type[2]*/ *)data.Data)); } finally { pool.Push(ref data); } }
/// <summary> /// 重新加载数据 /// </summary> protected override void reset() { valueType[] values = SqlTool.Where(null, memberMap).getArray(); int maxIdentity = values.maxKey(value => GetKey(value), 0); if (memberGroup == 0) { SqlTool.Identity64 = maxIdentity + baseIdentity; } int length = maxIdentity >= identityArray.ArraySize ? 1 << ((uint)maxIdentity).bits() : identityArray.ArraySize; identityArray <valueType> newValues = new identityArray <valueType>(length); pointer.size newCounts = unmanaged.Get(length * sizeof(int), true); try { int *intCounts = newCounts.Int; foreach (valueType value in values) { setMemberCacheAndValue(value); int identity = GetKey(value); newValues[identity] = value; intCounts[identity] = 1; } for (int step = 2; step != length; step <<= 1) { for (int index = step, countStep = step >> 1; index != length; index += step) { intCounts[index] += intCounts[index - countStep]; } } unmanaged.Free(ref counts); this.values = newValues; counts = newCounts; size = length; Count = values.Length; newCounts.Null(); } catch (Exception error) { log.Error.Add(error, null, true); } finally { unmanaged.Free(ref newCounts); } }
/// <summary> /// 成员位图类型信息 /// </summary> /// <param name="type">类型</param> /// <param name="members">成员索引集合</param> /// <param name="fieldCount">字段成员数量</param> public type(Type type, fastCSharp.code.memberIndex[] members, int fieldCount) { Type = type; FieldCount = fieldCount; if ((MemberCount = members.Length) < 64) { MemberMapSize = MemberCount < 32 ? 4 : 8; } else { MemberMapSize = ((MemberCount + 63) >> 6) << 3; } nameIndexSearcher = fastCSharp.stateSearcher.charsSearcher.Create(members.getArray(value => value.Member.Name), true); if (MemberCount >= 64) { Pool = pool.GetPool(MemberMapSize); FieldSerializeSize = ((fieldCount + 31) >> 5) << 2; } }
private unsafe static bool parseRefund(xmlParser parser, ref refundResult value, ref pointer.size name) { return(value.parseRefund(parser, name.Char)); }
private unsafe static bool parseCoupon(xmlParser parser, ref orderResult value, ref pointer.size name) { return(value.parseCoupon(parser, name.Char)); }