Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
014aa88d
Commit
014aa88d
authored
7 years ago
by
nanocryk
Browse files
Options
Downloads
Plain Diff
Merge branch '39-rustywot-get_paths-is-stuck-in-an-infinite-loop' into 'dev'
Resolve "RustyWot : get_paths is stuck in an infinite loop !" Closes
#39
See merge request
!29
parents
20dc0a62
bcc296f5
No related branches found
No related tags found
1 merge request
!29
Resolve "RustyWot : get_paths is stuck in an infinite loop !"
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Cargo.lock
+1
-1
1 addition, 1 deletion
Cargo.lock
wotb/Cargo.toml
+1
-1
1 addition, 1 deletion
wotb/Cargo.toml
wotb/lib.rs
+34
-0
34 additions, 0 deletions
wotb/lib.rs
wotb/rusty.rs
+60
-26
60 additions, 26 deletions
wotb/rusty.rs
with
96 additions
and
28 deletions
Cargo.lock
+
1
−
1
View file @
014aa88d
...
...
@@ -107,7 +107,7 @@ dependencies = [
[[package]]
name = "duniter-wotb"
version = "0.7.
0
"
version = "0.7.
1
"
dependencies = [
"bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
...
...
This diff is collapsed.
Click to expand it.
wotb/Cargo.toml
+
1
−
1
View file @
014aa88d
[package]
name
=
"duniter-wotb"
version
=
"0.7.
0
"
version
=
"0.7.
1
"
authors
=
[
"nanocryk <nanocryk@duniter.org>"
,
"elois <elois@duniter.org>"
]
description
=
"Makes Web of Trust computations for the Duniter project."
repository
=
"https://git.duniter.org/nodes/rust/duniter-rs"
...
...
This diff is collapsed.
Click to expand it.
wotb/lib.rs
+
34
−
0
View file @
014aa88d
...
...
@@ -828,5 +828,39 @@ mod tests {
outdistanced
:
false
,
},)
);
// Test centralities computation in g1_genesis wot
let
wot_size
=
wot3
.size
();
let
members_count
=
wot3
.get_enabled
()
.len
()
as
u64
;
assert_eq!
(
members_count
,
59
);
let
oriented_couples_count
:
u64
=
members_count
*
(
members_count
-
1
);
let
mut
centralities
=
vec!
[
0
;
wot_size
];
for
i
in
0
..
wot_size
{
for
j
in
0
..
wot_size
{
let
paths
=
wot3
.get_paths
(
NodeId
(
i
),
NodeId
(
j
),
5
);
let
mut
intermediate_members
:
Vec
<
NodeId
>
=
Vec
::
new
();
for
path
in
paths
{
if
path
.len
()
>
2
{
for
node_id
in
&
path
[
1
..
path
.len
()
-
1
]
{
if
!
intermediate_members
.contains
(
node_id
)
{
intermediate_members
.push
(
*
node_id
);
}
}
}
}
let
centralities_copy
=
centralities
.clone
();
for
node_id
in
intermediate_members
{
let
centrality
=
&
centralities_copy
[
node_id
.0
];
if
let
Some
(
tmp
)
=
centralities
.get_mut
(
node_id
.0
)
{
*
tmp
=
*
centrality
+
1
;
}
}
}
}
let
mut
relative_centralities
=
Vec
::
with_capacity
(
wot_size
);
for
centrality
in
centralities
{
relative_centralities
.push
((
centrality
*
100_000
/
oriented_couples_count
)
as
usize
);
}
assert_eq!
(
relative_centralities
.len
(),
59
);
}
}
This diff is collapsed.
Click to expand it.
wotb/rusty.rs
+
60
−
26
View file @
014aa88d
...
...
@@ -219,34 +219,68 @@ impl WebOfTrust for RustyWebOfTrust {
}
fn
get_paths
(
&
self
,
from
:
NodeId
,
to
:
NodeId
,
k_max
:
u32
)
->
Vec
<
Vec
<
NodeId
>>
{
if
from
==
to
{
vec!
[
vec!
[
to
]]
}
else
if
k_max
>
0
{
self
.nodes
[
to
.0
]
.links_source
.par_iter
()
.map
(|
&
source
|
self
.get_paths
(
from
,
source
,
k_max
-
1
))
.map
(|
paths
|
{
paths
.iter
()
.map
(|
path
|
{
let
mut
path
=
path
.clone
();
path
.push
(
to
);
path
})
.collect
::
<
Vec
<
Vec
<
NodeId
>>>
()
})
.reduce
(
||
vec!
[],
|
mut
acc
,
mut
paths
|
{
acc
.append
(
&
mut
paths
);
acc
},
)
// 1. We explore the k_max area around `to`, and only remember backward
// links of the smallest distance.
// Stores for each node its distance to `to` node and its backward links.
// By default all nodes are out of range (`k_max + 1`) and links are known.
let
mut
graph
:
Vec
<
(
u32
,
Vec
<
usize
>
)
>
=
self
.nodes
.iter
()
.map
(|
_
|
(
k_max
+
1
,
vec!
[]))
.collect
();
// `to` node is at distance 0, and have no backward links.
graph
[
to
.0
]
=
(
0
,
vec!
[]);
// Explored zone border.
let
mut
border
=
HashSet
::
new
();
border
.insert
(
to
.0
);
for
distance
in
1
..
(
k_max
+
1
)
{
let
mut
next_border
=
HashSet
::
new
();
for
node
in
border
{
for
source
in
&
self
.nodes
[
node
]
.links_source
{
if
graph
[
source
.0
]
.0
>
distance
{
// shorter path, we replace
graph
[
source
.0
]
=
(
distance
,
vec!
[
node
]);
next_border
.insert
(
source
.0
);
}
else
if
graph
[
source
.0
]
.0
==
distance
{
// same length, we combine
graph
[
source
.0
]
.1
.push
(
node
);
next_border
.insert
(
source
.0
);
}
}
}
border
=
next_border
;
}
// 2. If `from` is found, we follow the backward links and build paths.
// For each path, we look at the last element sources and build new paths with them.
let
mut
paths
=
vec!
[
vec!
[
from
]];
for
_
in
1
..
(
k_max
+
1
)
{
let
mut
new_paths
=
vec!
[];
for
path
in
&
paths
{
let
node
=
path
.last
()
.unwrap
();
if
node
==
&
to
{
// If path is complete, we keep it.
new_paths
.push
(
path
.clone
())
}
else
{
vec!
[]
// If not complete we comlete paths
let
sources
=
&
graph
[
node
.0
];
for
source
in
&
sources
.1
{
let
mut
new_path
=
path
.clone
();
new_path
.push
(
NodeId
(
*
source
));
new_paths
.push
(
new_path
);
}
}
}
paths
=
new_paths
;
}
paths
}
fn
compute_distance
(
&
self
,
params
:
WotDistanceParameters
)
->
Option
<
WotDistance
>
{
let
WotDistanceParameters
{
...
...
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