Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Goshimmer_without_tipselection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COLLET Ismael
Goshimmer_without_tipselection
Commits
e9b8ce05
Unverified
Commit
e9b8ce05
authored
4 years ago
by
capossele
Browse files
Options
Downloads
Patches
Plain Diff
Fix graph pkg linter warnings
parent
a61c8b0b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/graph/graph.go
+34
-31
34 additions, 31 deletions
packages/graph/graph.go
packages/graph/list.go
+3
-3
3 additions, 3 deletions
packages/graph/list.go
with
37 additions
and
34 deletions
packages/graph/graph.go
+
34
−
31
View file @
e9b8ce05
...
...
@@ -5,51 +5,54 @@ import (
"sync"
)
type
nodeI
d
int32
type
nodeI
D
int32
type
S
ymbolTable
map
[
string
]
nodeI
d
type
s
ymbolTable
map
[
string
]
nodeI
D
func
(
s
S
ymbolTable
)
getI
d
(
name
string
)
nodeI
d
{
func
(
s
s
ymbolTable
)
getI
D
(
name
string
)
nodeI
D
{
id
,
ok
:=
s
[
name
]
if
!
ok
{
id
=
nodeI
d
(
len
(
s
))
id
=
nodeI
D
(
len
(
s
))
s
[
name
]
=
id
}
return
id
}
// Graph contains nodes and a symbolTable of a graph.
type
Graph
struct
{
S
ymbolTable
N
odes
s
ymbolTable
n
odes
}
// New returns a graph.
func
New
(
IDs
[]
string
)
*
Graph
{
g
:=
&
Graph
{
S
ymbolTable
:
make
(
S
ymbolTable
,
len
(
IDs
)),
N
odes
:
make
(
N
odes
,
len
(
IDs
)),
s
ymbolTable
:
make
(
s
ymbolTable
,
len
(
IDs
)),
n
odes
:
make
(
n
odes
,
len
(
IDs
)),
}
for
index
,
id
:=
range
IDs
{
g
.
N
odes
[
index
]
.
ID
=
nodeI
d
(
index
)
g
.
S
ymbolTable
[
id
]
=
nodeI
d
(
index
)
g
.
n
odes
[
index
]
.
ID
=
nodeI
D
(
index
)
g
.
s
ymbolTable
[
id
]
=
nodeI
D
(
index
)
}
return
g
}
// AddEdge adds an edge to the given graph.
func
(
g
*
Graph
)
AddEdge
(
a
,
b
string
)
{
aid
:=
g
.
S
ymbolTable
.
getI
d
(
a
)
bid
:=
g
.
S
ymbolTable
.
getI
d
(
b
)
aid
:=
g
.
s
ymbolTable
.
getI
D
(
a
)
bid
:=
g
.
s
ymbolTable
.
getI
D
(
b
)
g
.
N
odes
.
AddEdge
(
aid
,
bid
)
g
.
n
odes
.
AddEdge
(
aid
,
bid
)
}
type
N
ode
struct
{
ID
nodeI
d
type
n
ode
struct
{
ID
nodeI
D
// adjacent edges
Adj
[]
nodeI
d
Adj
[]
nodeI
D
}
func
(
n
*
N
ode
)
add
(
adjNode
*
N
ode
)
{
func
(
n
*
n
ode
)
add
(
adjNode
*
n
ode
)
{
for
_
,
id
:=
range
n
.
Adj
{
if
id
==
adjNode
.
ID
{
return
...
...
@@ -58,13 +61,13 @@ func (n *Node) add(adjNode *Node) {
n
.
Adj
=
append
(
n
.
Adj
,
adjNode
.
ID
)
}
type
N
odes
[]
N
ode
type
n
odes
[]
n
ode
func
(
nl
N
odes
)
get
(
id
nodeI
d
)
*
N
ode
{
func
(
nl
n
odes
)
get
(
id
nodeI
D
)
*
n
ode
{
return
&
nl
[
id
]
}
func
(
nl
N
odes
)
AddEdge
(
a
,
b
nodeI
d
)
{
func
(
nl
n
odes
)
AddEdge
(
a
,
b
nodeI
D
)
{
an
:=
nl
.
get
(
a
)
bn
:=
nl
.
get
(
b
)
...
...
@@ -72,24 +75,24 @@ func (nl Nodes) AddEdge(a, b nodeId) {
bn
.
add
(
an
)
}
//
d
iameter is the maximum length of a shortest path in the network
func
(
nl
N
odes
)
Diameter
()
int
{
//
D
iameter is the maximum length of a shortest path in the network
func
(
nl
n
odes
)
Diameter
()
int
{
cpus
:=
runtime
.
NumCPU
()
numNodes
:=
len
(
nl
)
nodesPerC
pu
:=
numNodes
/
cpus
nodesPerC
PU
:=
numNodes
/
cpus
results
:=
make
([]
int
,
cpus
)
wg
:=
&
sync
.
WaitGroup
{}
wg
.
Add
(
cpus
)
start
:=
0
for
cpu
:=
0
;
cpu
<
cpus
;
cpu
++
{
end
:=
start
+
nodesPerC
pu
end
:=
start
+
nodesPerC
PU
if
cpu
==
cpus
-
1
{
end
=
numNodes
}
go
func
(
cpu
int
,
start
,
end
nodeI
d
)
{
go
func
(
cpu
int
,
start
,
end
nodeI
D
)
{
defer
wg
.
Done
()
var
diameter
int
q
:=
&
list
{}
...
...
@@ -100,14 +103,14 @@ func (nl Nodes) Diameter() int {
depths
[
i
]
=
-
1
}
df
:=
nl
.
longestShortestPath
(
nodeI
d
(
id
),
q
,
depths
)
df
:=
nl
.
longestShortestPath
(
nodeI
D
(
id
),
q
,
depths
)
if
df
>
diameter
{
diameter
=
df
}
}
results
[
cpu
]
=
diameter
}(
cpu
,
nodeI
d
(
start
),
nodeI
d
(
end
))
start
+=
nodesPerC
pu
}(
cpu
,
nodeI
D
(
start
),
nodeI
D
(
end
))
start
+=
nodesPerC
PU
}
wg
.
Wait
()
...
...
@@ -124,9 +127,9 @@ func (nl Nodes) Diameter() int {
// bfs tracking data
type
bfsNode
int16
func
(
n
odes
N
odes
)
longestShortestPath
(
start
nodeI
d
,
q
*
list
,
depths
[]
bfsNode
)
int
{
func
(
n
l
n
odes
)
longestShortestPath
(
start
nodeI
D
,
q
*
list
,
depths
[]
bfsNode
)
int
{
n
:=
n
odes
.
get
(
start
)
n
:=
n
l
.
get
(
start
)
depths
[
n
.
ID
]
=
0
q
.
pushBack
(
n
)
...
...
@@ -140,7 +143,7 @@ func (nodes Nodes) longestShortestPath(start nodeId, q *list, depths []bfsNode)
for
_
,
id
:=
range
n
.
Adj
{
if
depths
[
id
]
==
-
1
{
depths
[
id
]
=
depths
[
n
.
ID
]
+
1
q
.
pushBack
(
n
odes
.
get
(
id
))
q
.
pushBack
(
n
l
.
get
(
id
))
}
}
}
...
...
This diff is collapsed.
Click to expand it.
packages/graph/list.go
+
3
−
3
View file @
e9b8ce05
...
...
@@ -2,7 +2,7 @@ package graph
type
listElt
struct
{
next
*
listElt
node
*
N
ode
node
*
n
ode
}
type
list
struct
{
...
...
@@ -12,7 +12,7 @@ type list struct {
free
*
listElt
}
func
(
l
*
list
)
getHead
()
*
N
ode
{
func
(
l
*
list
)
getHead
()
*
n
ode
{
elt
:=
l
.
head
if
elt
==
nil
{
return
nil
...
...
@@ -32,7 +32,7 @@ func (l *list) getHead() *Node {
return
n
}
func
(
l
*
list
)
pushBack
(
n
*
N
ode
)
{
func
(
l
*
list
)
pushBack
(
n
*
n
ode
)
{
// Get a free listElt to use to point to this node
elt
:=
l
.
free
if
elt
==
nil
{
...
...
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