From 0d10dfe4718dc6875a20fc7c0c3d0b8b982cf3d8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 7 Jul 2017 23:12:21 -0400 Subject: update sharpcifs --- .../IO/SharpCifs/Util/Sharpen/ConcurrentHashMap.cs | 243 ++++++++++----------- 1 file changed, 116 insertions(+), 127 deletions(-) (limited to 'Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/ConcurrentHashMap.cs') diff --git a/Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/ConcurrentHashMap.cs b/Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/ConcurrentHashMap.cs index c719446e8a..7f464ad362 100644 --- a/Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/ConcurrentHashMap.cs +++ b/Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/ConcurrentHashMap.cs @@ -3,131 +3,120 @@ using System.Collections.Generic; namespace SharpCifs.Util.Sharpen { internal class ConcurrentHashMap : AbstractMap, IConcurrentMap - { - private Dictionary _table; - - public ConcurrentHashMap() - { - _table = new Dictionary(); - } - - public ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) - { - _table = new Dictionary(initialCapacity); - } - - public override void Clear() - { - lock (_table) - { - _table = new Dictionary(); - } - } - - public override bool ContainsKey(object name) - { - return _table.ContainsKey((T)name); - } - - public override ICollection> EntrySet() - { - return this; - } - - public override TU Get(object key) - { - TU local; - _table.TryGetValue((T)key, out local); - return local; - } - - protected override IEnumerator> InternalGetEnumerator() - { - return _table.GetEnumerator(); - } - - public override bool IsEmpty() - { - return _table.Count == 0; - } - - public override TU Put(T key, TU value) - { - lock (_table) - { - TU old = Get(key); - Dictionary newTable = new Dictionary(_table); - newTable[key] = value; - _table = newTable; - return old; - } - } - - public TU PutIfAbsent(T key, TU value) - { - lock (_table) - { - if (!ContainsKey(key)) - { - Dictionary newTable = new Dictionary(_table); - newTable[key] = value; - _table = newTable; - return value; - } - return Get(key); - } - } - - public override TU Remove(object key) - { - lock (_table) - { - TU old = Get((T)key); - Dictionary newTable = new Dictionary(_table); - newTable.Remove((T)key); - _table = newTable; - return old; - } - } - - public bool Remove(object key, object value) - { - lock (_table) - { - if (ContainsKey(key) && value.Equals(Get(key))) - { - Dictionary newTable = new Dictionary(_table); - newTable.Remove((T)key); - _table = newTable; - return true; - } - return false; - } - } - - public bool Replace(T key, TU oldValue, TU newValue) - { - lock (_table) - { - if (ContainsKey(key) && oldValue.Equals(Get(key))) - { - Dictionary newTable = new Dictionary(_table); - newTable[key] = newValue; - _table = newTable; - return true; - } - return false; - } - } - - public override IEnumerable Keys - { - get { return _table.Keys; } - } - - public override IEnumerable Values - { - get { return _table.Values; } - } - } + { + private Dictionary _table; + + public ConcurrentHashMap () + { + _table = new Dictionary (); + } + + public ConcurrentHashMap (int initialCapacity, float loadFactor, int concurrencyLevel) + { + _table = new Dictionary (initialCapacity); + } + + public override void Clear () + { + lock (_table) { + _table = new Dictionary (); + } + } + + public override bool ContainsKey (object name) + { + return _table.ContainsKey ((T)name); + } + + public override ICollection> EntrySet () + { + return this; + } + + public override TU Get (object key) + { + TU local; + _table.TryGetValue ((T)key, out local); + return local; + } + + protected override IEnumerator> InternalGetEnumerator () + { + return _table.GetEnumerator (); + } + + public override bool IsEmpty () + { + return _table.Count == 0; + } + + public override TU Put (T key, TU value) + { + lock (_table) { + TU old = Get (key); + Dictionary newTable = new Dictionary (_table); + newTable[key] = value; + _table = newTable; + return old; + } + } + + public TU PutIfAbsent (T key, TU value) + { + lock (_table) { + if (!ContainsKey (key)) { + Dictionary newTable = new Dictionary (_table); + newTable[key] = value; + _table = newTable; + return value; + } + return Get (key); + } + } + + public override TU Remove (object key) + { + lock (_table) { + TU old = Get ((T)key); + Dictionary newTable = new Dictionary (_table); + newTable.Remove ((T)key); + _table = newTable; + return old; + } + } + + public bool Remove (object key, object value) + { + lock (_table) { + if (ContainsKey (key) && value.Equals (Get (key))) { + Dictionary newTable = new Dictionary (_table); + newTable.Remove ((T)key); + _table = newTable; + return true; + } + return false; + } + } + + public bool Replace (T key, TU oldValue, TU newValue) + { + lock (_table) { + if (ContainsKey (key) && oldValue.Equals (Get (key))) { + Dictionary newTable = new Dictionary (_table); + newTable[key] = newValue; + _table = newTable; + return true; + } + return false; + } + } + + public override IEnumerable Keys { + get { return _table.Keys; } + } + + public override IEnumerable Values { + get { return _table.Values; } + } + } } -- cgit v1.2.3