FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/runtime/perf_utils/FifoDictionary.cs at featured · attackgithub/pythonnet · GitHub
attackgithub
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
runtime
/
perf_utils
/
FifoDictionary.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (49 loc) · 1.65 KB
Breadcrumbs
pythonnet
/
src
/
runtime
/
perf_utils
/
FifoDictionary.cs
Copy path
File metadata and controls
62 lines (49 loc) · 1.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using
System
;
namespace
Python
.
Runtime
{
using
System
.
Collections
.
Generic
;
public
class
FifoDictionary
<
TKey
,
TValue
>
{
private
readonly
Dictionary
<
TKey
,
int
>
_innerDictionary
;
private
readonly
KeyValuePair
<
TKey
,
TValue
>
[
]
_fifoList
;
private
bool
_hasEmptySlots
=
true
;
public
FifoDictionary
(
int
capacity
)
{
if
(
capacity
<=
0
)
{
throw
new
ArgumentOutOfRangeException
(
nameof
(
capacity
)
,
"Capacity should be non-zero positive."
)
;
}
_innerDictionary
=
new
Dictionary
<
TKey
,
int
>
(
capacity
)
;
_fifoList
=
new
KeyValuePair
<
TKey
,
TValue
>
[
capacity
]
;
Capacity
=
capacity
;
}
public
bool
TryGetValue
(
TKey
key
,
out
TValue
value
)
{
int
index
;
if
(
_innerDictionary
.
TryGetValue
(
key
,
out
index
)
)
{
value
=
_fifoList
[
index
]
.
Value
;
return
true
;
}
value
=
default
(
TValue
)
;
return
false
;
}
public
void
AddUnsafe
(
TKey
key
,
TValue
value
)
{
if
(
!
_hasEmptySlots
)
{
_innerDictionary
.
Remove
(
_fifoList
[
NextSlotToAdd
]
.
Key
)
;
}
_innerDictionary
.
Add
(
key
,
NextSlotToAdd
)
;
_fifoList
[
NextSlotToAdd
]
=
new
KeyValuePair
<
TKey
,
TValue
>
(
key
,
value
)
;
NextSlotToAdd
++
;
if
(
NextSlotToAdd
>=
Capacity
)
{
_hasEmptySlots
=
false
;
NextSlotToAdd
=
0
;
}
}
public
int
NextSlotToAdd
{
get
;
private
set
;
}
public
int
Capacity
{
get
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL