admin 管理员组

文章数量: 1086019


2023年12月22日发(作者:asp运行环境搭建)

freeCount = 0;

version++; }

} ():从 Dictionary 中移除所指定的键的值。 public bool Remove(TKey key) { if(key == null) { rgumentNullException(); }

if (buckets != null) {

int hashCode = hCode(key) & 0x7FFFFFFF;

int bucket = hashCode % ; int last = -1;

for (int i = buckets[bucket]; i >= 0; last = i, i = entries[i].next) { if (entries[i].hashCode == hashCode && (entries[i].key, key)) { if (last < 0) { buckets[bucket] = entries[i].next;

} else {

entries[last].next = entries[i].next;

} entries[i].hashCode = -1;

entries[i].next = freeList; entries[i].key = default(TKey); entries[i].value = default(TValue); freeList = i;

freeCount++; version++;

return true;

} }

} return false; } merator():返回循环访问 Dictionary 的枚举器。 public Enumerator GetEnumerator() { return new Enumerator(this, uePair);

} [Serializable]

public struct Enumerator: IEnumerator>, IDictionaryEnumerator

{

private Dictionary dictionary; private int version;

private int index; private KeyValuePair current; private int getEnumeratorRetType; // What should t return? internal const int DictEntry = 1; internal const int KeyValuePair = 2;

internal Enumerator(Dictionary dictionary, int getEnumeratorRetType) { nary = dictionary;

version = n; index = 0; meratorRetType = getEnumeratorRetType; current = new KeyValuePair();

} public bool MoveNext() {

if (version != n) { nvalidOperationException(dOperation_EnumFailedVersion);

} // Use unsigned comparison since we set index to +1 when the enumeration ends. // +1 could be negative if is ue

while ((uint)index < (uint)) { if (s[index].hashCode >= 0) {

current = new KeyValuePair(s[index].key, s[index].value);

index++; return true;

} index++; } index = + 1; current = new KeyValuePair();

/// 要添加的键/值 public void Add(KeyValuePair item) { var key = ; var value = ; _mUsingWriteLock(() => _(key, value)); } ///

/// 如果值不存在,则添加该值。 返回如果值已添加,则为true /// /// 检查的关键,添加 /// 如果键不存在,则添加的值 public bool AddIfNotExists(TKey key, TValue value) { bool rVal = false; _mUsingWriteLock(() => { // 如果不存在,则添加它 if (!_nsKey(key)) { // 添加该值并设置标志 _(key, value); rVal = true; } }); return rVal; } /// /// 如果键不存在,则添加值列表。 /// /// 要检查的键,添加 /// 如果键不存在,则添加的值 public void AddIfNotExists(IEnumerable keys, TValue defaultValue) { _mUsingWriteLock(() => { foreach (TKey key in keys) { // 如果不存在,则添加它 if (!_nsKey(key)) _(key, defaultValue); } }); } public bool AddIfNotExistsElseUpdate(TKey key, TValue value) { var rVal = false; _mUsingWriteLock(() => { // 如果不存在,则添加它 if (!_nsKey(key)) { // 添加该值并设置标志 _(key, value); rVal = true; } else _mDictionary[key] = value; }); return rVal; } /// /// 如果键存在,则更新键的值。 /// /// /// public bool UpdateValueIfKeyExists(TKey key, TValue newValue) { bool rVal = false; _mUsingWriteLock(() => { // 如果我们有密钥,然后更新它 if (!_nsKey(key)) return; _mDictionary[key] = newValue; rVal = true; });


本文标签: 添加 存在 运行 环境 设置