예제 #1
0
        /// <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);
        }
예제 #2
0
 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());
 }
예제 #3
0
 /// <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);
 }
예제 #4
0
 /// <summary>
 /// 先进先出优先队列
 /// </summary>
 /// <param name="dictionaryCapacity">字典初始化容器尺寸</param>
 public FifoPriorityQueue(int dictionaryCapacity = 0)
 {
     dictionary = dictionaryCapacity <= 0 ? DictionaryCreator <keyType> .Create <Node>() : DictionaryCreator <keyType> .Create <Node>(dictionaryCapacity);
 }