Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8395821
in_memory.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
in_memory.py
View Options
# Copyright (C) 2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from
collections
import
defaultdict
from
typing
import
Any
,
Dict
,
Iterable
,
List
class
InMemory
:
"""InMemory implementation of the counters.
Naive implementation using a Dict[str, Set]"""
def
__init__
(
self
):
self
.
counters
=
defaultdict
(
set
)
def
check
(
self
):
return
"OK"
def
add
(
self
,
collection
:
str
,
keys
:
Iterable
[
Any
])
->
None
:
for
value
in
keys
:
self
.
counters
[
collection
]
.
add
(
value
)
def
get_count
(
self
,
collection
:
str
)
->
int
:
return
len
(
self
.
counters
.
get
(
collection
,
[]))
def
get_counts
(
self
,
collections
:
List
[
str
])
->
Dict
[
str
,
int
]:
return
{
coll
:
self
.
get_count
(
coll
)
for
coll
in
collections
}
def
get_counters
(
self
)
->
Iterable
[
str
]:
return
list
(
self
.
counters
.
keys
())
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Jun 4 2025, 7:45 PM (11 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3243084
Attached To
rDCNT Archive counters
Event Timeline
Log In to Comment