ConcurrentOneToManyQueue<TKey, TValue> 类
表示一个并发的一对多队列,用于维护具有相同键的多个值的关联关系。
继承成员
命名空间: Fantasy.DataStructure.Collection
程序集: Fantasy.Net.dll
语法
public class ConcurrentOneToManyQueue<TKey, TValue> : ConcurrentDictionary<TKey, Queue<TValue>>, IDictionary<TKey, Queue<TValue>>, ICollection<KeyValuePair<TKey, Queue<TValue>>>, IReadOnlyDictionary<TKey, Queue<TValue>>, IReadOnlyCollection<KeyValuePair<TKey, Queue<TValue>>>, IEnumerable<KeyValuePair<TKey, Queue<TValue>>>, IDictionary, ICollection, IEnumerable where TKey : notnull
类型参数
名称 | 描述 |
---|---|
TKey | 关键字的类型,不能为空。 |
TValue | 值的类型。 |
构造函数
| 编辑本文 查看源代码ConcurrentOneToManyQueue(int)
设置最大缓存数量
声明
public ConcurrentOneToManyQueue(int recyclingLimit = 0)
参数
类型 | 名称 | 描述 |
---|---|---|
int | recyclingLimit | 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC. 2:设置成0不控制数量,全部缓存 |
方法
| 编辑本文 查看源代码Clear()
清空当前类的数据,包括从基类继承的键值对字典中的数据以及自定义的队列池。
声明
protected void Clear()
Contains(TKey, TValue)
判断指定键的队列是否包含指定值。
声明
public bool Contains(TKey key, TValue value)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要搜索的键。 |
TValue | value | 要搜索的值。 |
返回
类型 | 描述 |
---|---|
bool | 如果队列包含值,则为 true;否则为 false。 |
Dequeue(TKey)
从指定键的队列中出队并返回一个值。
声明
public TValue Dequeue(TKey key)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要出队的键。 |
返回
类型 | 描述 |
---|---|
TValue | 出队的值,如果队列为空则为默认值。 |
Enqueue(TKey, TValue)
向指定键的队列中添加一个值。
声明
public void Enqueue(TKey key, TValue value)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要添加值的键。 |
TValue | value | 要添加的值。 |
RemoveKey(TKey)
从字典中移除指定键以及其关联的队列。
声明
public void RemoveKey(TKey key)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要移除的键。 |
TryDequeue(TKey, out TValue)
尝试从指定键的队列中出队一个值。
声明
public bool TryDequeue(TKey key, out TValue value)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要出队的键。 |
TValue | value | 出队的值,如果队列为空则为默认值。 |
返回
类型 | 描述 |
---|---|
bool | 如果成功出队,则为 true;否则为 false。 |