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

◆ AddIfNotPresent()

bool System.Collections.Generic.HashSet< T >.AddIfNotPresent ( T value,
out int location )
inlineprivate

Definition at line 892 of file HashSet.cs.

893 {
894 if (_buckets == null)
895 {
896 Initialize(0);
897 }
899 IEqualityComparer<T> comparer = _comparer;
900 uint num = 0u;
901 ref int reference = ref Unsafe.NullRef<int>();
902 int num2;
903 if (comparer == null)
904 {
905 num2 = value?.GetHashCode() ?? 0;
907 int num3 = reference - 1;
908 if (typeof(T).IsValueType)
909 {
910 while (num3 >= 0)
911 {
913 if (reference2.HashCode == num2 && EqualityComparer<T>.Default.Equals(reference2.Value, value))
914 {
915 location = num3;
916 return false;
917 }
918 num3 = reference2.Next;
919 num++;
920 if (num > (uint)entries.Length)
921 {
922 ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
923 }
924 }
925 }
926 else
927 {
928 EqualityComparer<T> @default = EqualityComparer<T>.Default;
929 while (num3 >= 0)
930 {
932 if (reference3.HashCode == num2 && @default.Equals(reference3.Value, value))
933 {
934 location = num3;
935 return false;
936 }
937 num3 = reference3.Next;
938 num++;
939 if (num > (uint)entries.Length)
940 {
941 ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
942 }
943 }
944 }
945 }
946 else
947 {
948 num2 = ((value != null) ? comparer.GetHashCode(value) : 0);
950 int num4 = reference - 1;
951 while (num4 >= 0)
952 {
954 if (reference4.HashCode == num2 && comparer.Equals(reference4.Value, value))
955 {
956 location = num4;
957 return false;
958 }
959 num4 = reference4.Next;
960 num++;
961 if (num > (uint)entries.Length)
962 {
963 ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
964 }
965 }
966 }
967 int num5;
968 if (_freeCount > 0)
969 {
970 num5 = _freeList;
971 _freeCount--;
972 _freeList = -3 - entries[_freeList].Next;
973 }
974 else
975 {
976 int count = _count;
977 if (count == entries.Length)
978 {
979 Resize();
981 }
982 num5 = count;
983 _count = count + 1;
985 }
990 reference = num5 + 1;
991 _version++;
992 location = num5;
993 if (!typeof(T).IsValueType && num > 100 && comparer is NonRandomizedStringEqualityComparer)
994 {
997 }
998 return true;
999 }
IEqualityComparer< T > _comparer
Definition HashSet.cs:105
ref int GetBucketRef(int hashCode)
Definition HashSet.cs:321

References System.Collections.Generic.HashSet< T >._buckets, System.Collections.Generic.HashSet< T >._comparer, System.Collections.Generic.HashSet< T >._count, System.Collections.Generic.HashSet< T >._entries, System.Collections.Generic.HashSet< T >._freeCount, System.Collections.Generic.HashSet< T >._freeList, System.Collections.Generic.HashSet< T >._version, System.comparer, System.count, System.Runtime.Serialization.Dictionary, System.Collections.Generic.HashSet< T >.FindItemIndex(), System.Collections.Generic.HashSet< T >.GetBucketRef(), System.Collections.Generic.HashSet< T >.Initialize(), System.Collections.Generic.HashSet< T >.Resize(), System.ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported(), and System.value.

Referenced by System.Collections.Generic.HashSet< T >.Add(), System.Collections.Generic.HashSet< T >.ConstructFrom(), System.Collections.Generic.HashSet< T >.OnDeserialization(), System.Collections.Generic.HashSet< T >.SymmetricExceptWithEnumerable(), System.Collections.Generic.HashSet< T >.SymmetricExceptWithUniqueHashSet(), and System.Collections.Generic.HashSet< T >.UnionWith().