Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Insert()

void System.Collections.Hashtable.Insert ( object key,
object nvalue,
bool add )
inlineprivateinherited

Definition at line 935 of file Hashtable.cs.

936 {
937 if (key == null)
938 {
939 throw new ArgumentNullException("key", SR.ArgumentNull_Key);
940 }
941 if (_count >= _loadsize)
942 {
943 expand();
944 }
945 else if (_occupancy > _loadsize && _count > 100)
946 {
947 rehash();
948 }
949 uint seed;
950 uint incr;
951 uint num = InitHash(key, _buckets.Length, out seed, out incr);
952 int num2 = 0;
953 int num3 = -1;
954 int num4 = (int)(seed % (uint)_buckets.Length);
955 do
956 {
957 if (num3 == -1 && _buckets[num4].key == _buckets && _buckets[num4].hash_coll < 0)
958 {
959 num3 = num4;
960 }
961 if (_buckets[num4].key == null || (_buckets[num4].key == _buckets && (_buckets[num4].hash_coll & 0x80000000u) == 0L))
962 {
963 if (num3 != -1)
964 {
965 num4 = num3;
966 }
967 _isWriterInProgress = true;
969 _buckets[num4].key = key;
970 _buckets[num4].hash_coll |= (int)num;
971 _count++;
973 _isWriterInProgress = false;
974 return;
975 }
976 if ((_buckets[num4].hash_coll & 0x7FFFFFFF) == num && KeyEquals(_buckets[num4].key, key))
977 {
978 if (add)
979 {
980 throw new ArgumentException(SR.Format(SR.Argument_AddingDuplicate__, _buckets[num4].key, key));
981 }
982 _isWriterInProgress = true;
985 _isWriterInProgress = false;
986 return;
987 }
988 if (num3 == -1 && _buckets[num4].hash_coll >= 0)
989 {
990 _buckets[num4].hash_coll |= int.MinValue;
991 _occupancy++;
992 }
993 num4 = (int)((num4 + incr) % (uint)_buckets.Length);
994 }
995 while (++num2 < _buckets.Length);
996 if (num3 != -1)
997 {
998 _isWriterInProgress = true;
1000 _buckets[num3].key = key;
1001 _buckets[num3].hash_coll |= (int)num;
1002 _count++;
1003 UpdateVersion();
1004 _isWriterInProgress = false;
1005 return;
1006 }
1007 throw new InvalidOperationException(SR.InvalidOperation_HashInsertFailed);
1008 }
uint InitHash(object key, int hashsize, out uint seed, out uint incr)
Definition Hashtable.cs:669
volatile bool _isWriterInProgress
Definition Hashtable.cs:407
virtual bool KeyEquals(object? item, object key)
Definition Hashtable.cs:918

References System.Collections.Hashtable._buckets, System.Collections.Hashtable._count, System.Collections.Hashtable._isWriterInProgress, System.Collections.Hashtable._loadsize, System.Collections.Hashtable._occupancy, System.SR.Argument_AddingDuplicate__, System.SR.ArgumentNull_Key, System.Runtime.Serialization.Dictionary, System.Collections.Hashtable.expand(), System.SR.Format(), System.Collections.Hashtable.bucket.hash_coll, System.Collections.Hashtable.InitHash(), System.SR.InvalidOperation_HashInsertFailed, System.Collections.Hashtable.bucket.key, System.key, System.Collections.Hashtable.KeyEquals(), System.L, System.Collections.Hashtable.rehash(), System.Collections.Hashtable.UpdateVersion(), and System.Collections.Hashtable.bucket.val.