/// <summary> /// 获取匹配值集合 /// </summary> /// <param name="isValue">数据匹配器</param> /// <param name="map">匹配结果位图</param> /// <returns>匹配值集合</returns> private valueType[] getFindArray(Func <valueType, bool> isValue, MemoryMap map) { int count = 0, index = 0; foreach (valueType value in Array) { if (isValue(value)) { ++count; map.Set(index); } if (++index == Length) { break; } } if (count == 0) { return(NullValue <valueType> .Array); } valueType[] values = new valueType[count]; for (index = Length; count != 0; values[--count] = Array[index]) { while (map.Get(--index) == 0) { ; } } return(values); }
/// <summary> /// 获取匹配值集合 /// </summary> /// <param name="isValue">数据匹配器</param> /// <param name="map">匹配结果位图</param> /// <returns>匹配值集合</returns> private T[] getFindArray(Func <T, bool> isValue, MemoryMap map) { int count = 0, index = 0; foreach (T value in Array) { if (isValue(value)) { ++count; map.Set(index); } if (++index == Length) { break; } } if (count == 0) { return(EmptyArray <T> .Array); } T[] values = new T[count]; for (index = Length; count != 0; values[--count] = Array[index]) { while (map.Get(--index) == 0) { ; } } return(values); }
/// <summary> /// 唯一静态哈希 /// </summary> /// <param name="values">数据集合</param> /// <param name="size">哈希容器尺寸</param> public unsafe UniqueHashSet(valueType[] values, int size) { if (size < values.Length) { throw new IndexOutOfRangeException(size.toString() + " < " + values.Length.toString()); } if (size == 0) { throw new IndexOutOfRangeException(); } array = new valueType[size]; int count64 = (size + 63) >> 6; byte * isValue = stackalloc byte[count64 << 3]; MemoryMap map = new MemoryMap((ulong *)isValue, count64); foreach (valueType value in values) { int index = value.GetHashCode(); if ((uint)index >= size) { throw new IndexOutOfRangeException(index.toString() + " >= " + size.toString()); } if (map.Get(index) != 0) { throw new IndexOutOfRangeException(index.toString() + " is exists"); } map.Set(index); array[index] = value; } }
/// <summary> /// 唯一静态哈希字典 /// </summary> /// <param name="values">数据集合</param> /// <param name="count">数据数量</param> /// <param name="size">哈希容器尺寸</param> private unsafe void fromArray(KeyValue<keyType, valueType>[] values, int count, int size) { int count64 = (size + 63) >> 6; byte* isValue = stackalloc byte[count64 << 3]; MemoryMap map = new MemoryMap((ulong*)isValue, count64); do { KeyValue<keyType, valueType> value = values[--count]; int index = value.Key.GetHashCode(); if ((uint)index >= size) throw new IndexOutOfRangeException(index.toString() + " >= " + size.toString()); if (map.Get(index) != 0) throw new IndexOutOfRangeException(index.toString() + " is exists"); map.Set(index); array[index] = value; } while (count != 0); }