/// <summary> /// 根据关键字获取字典,不存在时创建字典 /// </summary> /// <param name="key"></param> /// <returns></returns> internal Dictionary <keyType, valueType> GetOrCreateDictionary(keyType key) { int index = key.GetHashCode() & 0xff; Dictionary <keyType, valueType> dictionary = dictionarys[index]; if (dictionary == null) { dictionarys[index] = dictionary = DictionaryCreator <keyType> .Create <valueType>(); } return(dictionary); }
static EqualityComparer() { comparers = DictionaryCreator.CreateOnly <Type, object>(); comparers.Add(typeof(byte), Byte = new byteComparer()); comparers.Add(typeof(short), Short = new shortComparer()); comparers.Add(typeof(int), Int = new intComparer()); comparers.Add(typeof(char), Char = new charComparer()); comparers.Add(typeof(ulong), ULong = new ulongComparer()); comparers.Add(typeof(Pointer), Pointer = new pointerComparer()); comparers.Add(typeof(SubString), SubString = new subStringComparer()); comparers.Add(typeof(HashBytes), HashBytes = new hashBytesComparer()); comparers.Add(typeof(HashString), HashString = new hashStringComparer()); comparers.Add(typeof(sessionId), SessionId = new sessionIdComparer()); }
/// <summary> /// 是否需要清除数组 /// </summary> /// <param name="type">类型</param> /// <returns>需要清除数组</returns> public static bool IsClearArray(Type type) { if (type.IsPointer) { return(false); } if (type.IsClass || type.IsInterface) { return(true); } if (type.IsEnum) { return(false); } if (type.IsValueType) { bool isClear; Monitor.Enter(isClearArrayLock); try { if (isClearArrayCache != null) { if (isClearArrayCache.TryGetValue(type, out isClear)) { return(isClear); } } else { isClearArrayCache = DictionaryCreator <HashType> .Create <bool>(); } isClearArrayCache.Add(type, true); isClearArrayCache[type] = isClear = isClearArray(type, isClearArrayCache); } finally { Monitor.Exit(isClearArrayLock); } return(isClear); } return(true); }
/// <summary> /// 先进先出优先队列 /// </summary> /// <param name="dictionaryCapacity">字典初始化容器尺寸</param> public FifoPriorityQueue(int dictionaryCapacity = 0) { dictionary = dictionaryCapacity <= 0 ? DictionaryCreator <keyType> .Create <Node>() : DictionaryCreator <keyType> .Create <Node>(dictionaryCapacity); }