/// <summary> /// 创建字典测试 /// </summary> private static void createDictionary() { try { removeCount = 0; AutoCSer.Random random = AutoCSer.Random.Default; int keyIndex = keyCount; time.Restart(); for (int nextCount = count; nextCount > keyIndex; --nextCount) { int index = (int)((uint)random.Next() & (keyCount - 1)), key = keys[index]; if (index < keyIndex) { if (!dictionary.TryAdd(ref key, key)) { isError = true; Console.WriteLine("ERROR"); return; } if (dictionary.Count != keyCount - keyIndex + 1) { isError = true; Console.WriteLine("ERROR"); return; } keys[index] = keys[--keyIndex]; keys[keyIndex] = key; } else { if (!dictionary.Remove(ref key)) { isError = true; Console.WriteLine("ERROR"); return; } if (dictionary.Count != keyCount - keyIndex - 1) { isError = true; Console.WriteLine("ERROR"); return; } keys[index] = keys[keyIndex]; ++removeCount; keys[keyIndex++] = key; } } while (keyIndex != 0) { int index = (int)((uint)random.Next() % keyIndex), key = keys[index]; if (!dictionary.TryAdd(ref key, key)) { isError = true; Console.WriteLine("ERROR"); return; } if (dictionary.Count != keyCount - keyIndex + 1) { isError = true; Console.WriteLine("ERROR"); return; } keys[index] = keys[--keyIndex]; keys[keyIndex] = key; } time.Stop(); if (dictionary.Count != keyCount) { isError = true; Console.WriteLine("ERROR"); return; } for (int index = keyCount; index != 0;) { --index; if (dictionary.At(index).Key != index) { isError = true; Console.WriteLine("ERROR"); return; } } } finally { wait.Set(); } }