Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P548
Masterwork From Distant Lands
Active
Public
Actions
Authored by
seirl
on Oct 14 2019, 1:52 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
package
org.softwareheritage.graph
;
import
org.softwareheritage.graph.algo.Traversal
;
import
java.io.OutputStream
;
import
java.io.IOException
;
import
java.util.Scanner
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.RejectedExecutionHandler
;
import
java.util.concurrent.ExecutorService
;
public
class
TestDistribution
{
Graph
graph
;
public
void
load_graph
(
String
graphBasename
)
throws
IOException
{
System
.
err
.
println
(
"Loading graph "
+
graphBasename
+
" ..."
);
this
.
graph
=
new
Graph
(
graphBasename
);
System
.
err
.
println
(
"Graph loaded."
);
}
public
static
void
main
(
String
[]
args
)
{
if
(
args
.
length
!=
1
)
{
System
.
out
.
println
(
"Usage: TestParallel GRAPH_BASENAME"
);
System
.
exit
(
1
);
}
TestDistribution
tp
=
new
TestDistribution
();
try
{
tp
.
load_graph
(
args
[
0
]);
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Could not load graph: "
+
e
);
System
.
exit
(
2
);
}
RejectedExecutionHandler
handler
=
new
ThreadPoolExecutor
.
CallerRunsPolicy
();
ExecutorService
service
=
new
ThreadPoolExecutor
(
128
,
128
,
0
L
,
TimeUnit
.
MILLISECONDS
,
new
LinkedBlockingQueue
<
Runnable
>(
1024
),
handler
);
Scanner
input
=
new
Scanner
(
System
.
in
);
while
(
input
.
hasNextLong
())
{
service
.
submit
(
new
CalculationJob
(
tp
.
graph
,
input
.
nextLong
()));
}
}
public
static
class
CalculationJob
implements
Runnable
{
Graph
graph
;
long
node
;
public
CalculationJob
(
Graph
graph
,
long
node
)
{
this
.
graph
=
graph
.
copy
();
this
.
node
=
node
;
}
public
void
run
()
{
Traversal
t
=
new
Traversal
(
this
.
graph
,
"backward"
,
"cnt:dir,dir:rev"
);
int
[]
count
=
{
0
};
t
.
leavesVisitor
(
this
.
node
,
(
node
)
->
{
count
[
0
]++;
});
System
.
out
.
println
(
""
+
count
[
0
]);
}
}
}
Event Timeline
seirl
edited the content of this paste.
(Show Details)
Oct 14 2019, 1:52 PM
2019-10-14 13:52:22 (UTC+2)
seirl
changed the title of this paste from untitled to
Masterwork From Distant Lands
.
seirl
updated the paste's language from
autodetect
to
java
.
Oct 14 2019, 1:52 PM
2019-10-14 13:52:38 (UTC+2)
seirl
changed the visibility from "All Users" to "Public (No Login Required)".
Oct 15 2019, 11:23 PM
2019-10-15 23:23:58 (UTC+2)
Log In to Comment