Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CerHashtable.cs
Go to the documentation of this file.
1
using
System.Collections
;
2
using
System.Threading
;
3
4
namespace
System.Reflection
;
5
6
internal
struct
CerHashtable
<K, V> where K : class
7
{
8
private
sealed
class
Table
9
{
10
internal
K[]
m_keys
;
11
12
internal
V[]
m_values
;
13
14
internal
int
m_count
;
15
16
internal
Table
(
int
size)
17
{
18
size =
HashHelpers
.
GetPrime
(size);
19
m_keys
=
new
K[size];
20
m_values
=
new
V[size];
21
}
22
23
internal
void
Insert
(K
key
, V
value
)
24
{
25
int
num =
CerHashtable<K, V>
.
GetHashCodeHelper
(
key
);
26
if
(num < 0)
27
{
28
num = ~num;
29
}
30
K[]
keys
=
m_keys
;
31
int
num2 = num %
keys
.Length;
32
while
(
true
)
33
{
34
K val =
keys
[num2];
35
if
(val ==
null
)
36
{
37
break
;
38
}
39
num2++;
40
if
(num2 >=
keys
.Length)
41
{
42
num2 -=
keys
.Length;
43
}
44
}
45
m_count
++;
46
m_values
[num2] =
value
;
47
Volatile
.
Write
(ref
keys
[num2],
key
);
48
}
49
}
50
51
private
Table
m_Table
;
52
53
internal
V
this
[K
key
]
54
{
55
get
56
{
57
Table
table =
Volatile
.
Read
(ref
m_Table
);
58
if
(table ==
null
)
59
{
60
return
default
(V);
61
}
62
int
num =
GetHashCodeHelper
(
key
);
63
if
(num < 0)
64
{
65
num = ~num;
66
}
67
K[]
keys
= table.
m_keys
;
68
int
num2 = num %
keys
.Length;
69
while
(
true
)
70
{
71
K val =
Volatile
.
Read
(ref
keys
[num2]);
72
if
(val ==
null
)
73
{
74
break
;
75
}
76
if
(val.Equals(
key
))
77
{
78
return
table.
m_values
[num2];
79
}
80
num2++;
81
if
(num2 >=
keys
.Length)
82
{
83
num2 -=
keys
.Length;
84
}
85
}
86
return
default
(V);
87
}
88
set
89
{
90
Table
table =
m_Table
;
91
if
(table !=
null
)
92
{
93
int
num = 2 * (table.m_count + 1);
94
if
(num >= table.
m_keys
.Length)
95
{
96
Rehash
(num);
97
}
98
}
99
else
100
{
101
Rehash
(7);
102
}
103
m_Table
.
Insert
(
key
,
value
);
104
}
105
}
106
107
private
static
int
GetHashCodeHelper
(K
key
)
108
{
109
if
(!(
key
is
string
text
))
110
{
111
return
key
.GetHashCode();
112
}
113
return
text
.GetNonRandomizedHashCode();
114
}
115
116
private
void
Rehash
(
int
newSize
)
117
{
118
Table
table =
new
Table
(
newSize
);
119
Table
table2 =
m_Table
;
120
if
(table2 !=
null
)
121
{
122
K[]
keys
= table2.
m_keys
;
123
V[]
values
= table2.
m_values
;
124
for
(
int
i = 0; i <
keys
.Length; i++)
125
{
126
K val =
keys
[i];
127
if
(val !=
null
)
128
{
129
table.
Insert
(val,
values
[i]);
130
}
131
}
132
}
133
Volatile
.
Write
(ref
m_Table
, table);
134
}
135
}
System.Collections.HashHelpers.GetPrime
static int GetPrime(int min)
Definition
HashHelpers.cs:52
System.Collections.HashHelpers
Definition
HashHelpers.cs:6
System.Reflection.CerHashtable.Table.m_values
V[] m_values
Definition
CerHashtable.cs:12
System.Reflection.CerHashtable.Table.m_keys
K[] m_keys
Definition
CerHashtable.cs:10
System.Reflection.CerHashtable.Table.m_count
int m_count
Definition
CerHashtable.cs:14
System.Reflection.CerHashtable.Table.Table
Table(int size)
Definition
CerHashtable.cs:16
System.Reflection.CerHashtable.Table.Insert
void Insert(K key, V value)
Definition
CerHashtable.cs:23
System.Reflection.CerHashtable.Table
Definition
CerHashtable.cs:9
System.Threading.Volatile.Read
static bool Read(ref bool location)
Definition
Volatile.cs:67
System.Threading.Volatile.Write
static void Write(ref bool location, bool value)
Definition
Volatile.cs:74
System.Threading.Volatile
Definition
Volatile.cs:9
System.Collections
Definition
BlockingCollection.cs:8
System.Reflection
Definition
ICustomTypeProvider.cs:1
System.Threading
Definition
TaskToApm.cs:3
System.ExceptionArgument.keys
@ keys
System.ExceptionArgument.text
@ text
System.ExceptionArgument.value
@ value
System.ExceptionArgument.key
@ key
System.ExceptionArgument.newSize
@ newSize
System.ExceptionArgument.values
@ values
System.Reflection.CerHashtable.m_Table
Table m_Table
Definition
CerHashtable.cs:51
System.Reflection.CerHashtable.GetHashCodeHelper
static int GetHashCodeHelper(K key)
Definition
CerHashtable.cs:107
System.Reflection.CerHashtable.Rehash
void Rehash(int newSize)
Definition
CerHashtable.cs:116
System.Reflection.CerHashtable
Definition
CerHashtable.cs:7
source
System.Private.CoreLib
System.Reflection
CerHashtable.cs
Generated by
1.10.0