Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
news
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sartika Aritonang
news
Commits
a7330000
Commit
a7330000
authored
May 29, 2020
by
Sartika Aritonang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
6368daf6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
structs.py
stbi/Lib/site-packages/pip/_vendor/resolvelib/structs.py
+68
-0
No files found.
stbi/Lib/site-packages/pip/_vendor/resolvelib/structs.py
0 → 100644
View file @
a7330000
class
DirectedGraph
(
object
):
"""A graph structure with directed edges.
"""
def
__init__
(
self
):
self
.
_vertices
=
set
()
self
.
_forwards
=
{}
# <key> -> Set[<key>]
self
.
_backwards
=
{}
# <key> -> Set[<key>]
def
__iter__
(
self
):
return
iter
(
self
.
_vertices
)
def
__len__
(
self
):
return
len
(
self
.
_vertices
)
def
__contains__
(
self
,
key
):
return
key
in
self
.
_vertices
def
copy
(
self
):
"""Return a shallow copy of this graph.
"""
other
=
DirectedGraph
()
other
.
_vertices
=
set
(
self
.
_vertices
)
other
.
_forwards
=
{
k
:
set
(
v
)
for
k
,
v
in
self
.
_forwards
.
items
()}
other
.
_backwards
=
{
k
:
set
(
v
)
for
k
,
v
in
self
.
_backwards
.
items
()}
return
other
def
add
(
self
,
key
):
"""Add a new vertex to the graph.
"""
if
key
in
self
.
_vertices
:
raise
ValueError
(
"vertex exists"
)
self
.
_vertices
.
add
(
key
)
self
.
_forwards
[
key
]
=
set
()
self
.
_backwards
[
key
]
=
set
()
def
remove
(
self
,
key
):
"""Remove a vertex from the graph, disconnecting all edges from/to it.
"""
self
.
_vertices
.
remove
(
key
)
for
f
in
self
.
_forwards
.
pop
(
key
):
self
.
_backwards
[
f
]
.
remove
(
key
)
for
t
in
self
.
_backwards
.
pop
(
key
):
self
.
_forwards
[
t
]
.
remove
(
key
)
def
connected
(
self
,
f
,
t
):
return
f
in
self
.
_backwards
[
t
]
and
t
in
self
.
_forwards
[
f
]
def
connect
(
self
,
f
,
t
):
"""Connect two existing vertices.
Nothing happens if the vertices are already connected.
"""
if
t
not
in
self
.
_vertices
:
raise
KeyError
(
t
)
self
.
_forwards
[
f
]
.
add
(
t
)
self
.
_backwards
[
t
]
.
add
(
f
)
def
iter_edges
(
self
):
for
f
,
children
in
self
.
_forwards
.
items
():
for
t
in
children
:
yield
f
,
t
def
iter_children
(
self
,
key
):
return
iter
(
self
.
_forwards
[
key
])
def
iter_parents
(
self
,
key
):
return
iter
(
self
.
_backwards
[
key
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment