Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Commits
2c02dcce
Commit
2c02dcce
authored
5 years ago
by
angloth
Browse files
Options
Downloads
Patches
Plain Diff
Add new types for graph id type and graph id number
parent
47b8658e
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
Integrated ID system, traversing and som signal tests
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
b_asic/graph_id.py
+16
-10
16 additions, 10 deletions
b_asic/graph_id.py
with
16 additions
and
10 deletions
b_asic/graph_id.py
+
16
−
10
View file @
2c02dcce
...
...
@@ -4,37 +4,43 @@ TODO: More info
"""
from
collections
import
defaultdict
from
typing
import
Union
,
DefaultDict
from
typing
import
NewType
,
Union
,
DefaultDict
GraphIDType
=
NewType
(
"
GraphIDType
"
,
str
)
GraphIDNumber
=
NewType
(
"
GraphIDNumber
"
,
int
)
class
GraphIDGenerator
:
"""
A class that generates Graph IDs for objects.
"""
_next_id_number
:
DefaultDict
(
str
,
int
)
_next_id_number
:
DefaultDict
(
GraphIDType
,
GraphIDNumber
)
def
__init__
(
self
):
self
.
_next_id_number
=
defaultdict
(
lambda
:
1
)
# Initalises every key element to 1
self
.
_next_id_number
=
defaultdict
(
lambda
:
1
)
# Initalises every key element to 1
def
get_next_id
(
self
,
graph_id_type
:
str
):
def
get_next_id
(
self
,
graph_id_type
:
GraphIDType
):
"""
Retrns the next graph id for a certain graph id type.
"""
graph_id
=
GraphID
(
graph_id_type
,
self
.
_next_id_number
[
graph_id_type
])
self
.
_next_id_number
[
graph_id_type
]
+=
1
# Incre
ment
the current number
self
.
_next_id_number
[
graph_id_type
]
+=
1
# Incre
ase
the current
id
number
return
graph_id
class
GraphID
:
"""
Graph ID class that handles the id of an object in a graph.
Graph ID class that saves the id of for a graph object.
The ID consists of an id_type that is saved as a string and an
id_number that is saved as an integer.
"""
graph_id_type
:
str
graph_id_number
:
int
graph_id_type
:
GraphIDType
graph_id_number
:
GraphIDNumber
def
__init__
(
self
,
graph_id_type
:
str
,
graph_id_number
:
int
):
def
__init__
(
self
,
graph_id_type
:
GraphIDType
,
graph_id_number
:
GraphIDNumber
):
self
.
graph_id_type
=
graph_id_type
self
.
graph_id_number
=
graph_id_number
...
...
@@ -51,7 +57,7 @@ class GraphID:
return
hash
(
str
(
self
))
def
__eq__
(
self
,
other
:
g
raphID
)
->
bool
:
def
__eq__
(
self
,
other
:
G
raphID
)
->
bool
:
return
self
.
graph_id_type
==
other
.
graph_id_type
and
\
self
.
graph_id_number
==
other
.
graph_id_number
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment