Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P739
(An Untitled Masterwork)
Active
Public
Actions
Authored by
seirl
on Aug 12 2020, 2:42 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
package
org.softwareheritage.graph.backend
;
import
it.unimi.dsi.big.webgraph.labelling.ArcLabelledImmutableGraph
;
import
it.unimi.dsi.big.webgraph.labelling.ArcLabelledNodeIterator
;
import
it.unimi.dsi.big.webgraph.labelling.BitStreamArcLabelledImmutableGraph
;
import
it.unimi.dsi.fastutil.io.BinIO
;
import
it.unimi.dsi.util.PermutedFrontCodedStringList
;
import
java.io.*
;
public
class
ReadLabelledGraph
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
ClassNotFoundException
{
String
graphPath
=
args
[
0
];
ArcLabelledImmutableGraph
graph
=
BitStreamArcLabelledImmutableGraph
.
loadOffline
(
graphPath
+
"-labelled"
);
NodeIdMap
nodeMap
=
new
NodeIdMap
(
graphPath
,
graph
.
numNodes
());
PermutedFrontCodedStringList
labelMap
=
(
PermutedFrontCodedStringList
)
BinIO
.
loadObject
(
graphPath
+
"-labels.fcl"
);
ArcLabelledNodeIterator
it
=
graph
.
nodeIterator
();
while
(
it
.
hasNext
())
{
long
srcNode
=
it
.
nextLong
();
ArcLabelledNodeIterator
.
LabelledArcIterator
s
=
it
.
successors
();
long
dstNode
;
while
((
dstNode
=
s
.
nextLong
())
>=
0
)
{
int
label
=
(
int
)
s
.
label
().
get
();
int
missing
=
(
1
<<
s
.
label
().
fixedWidth
())
-
1
;
if
(
label
==
missing
)
label
=
-
1
;
System
.
out
.
format
(
"%s %s %s\n"
,
nodeMap
.
getSwhPID
(
srcNode
),
nodeMap
.
getSwhPID
(
dstNode
),
((
label
>
-
1
)
?
labelMap
.
get
(
label
)
:
""
)
);
}
}
}
}
Event Timeline
seirl
created this paste.
Aug 12 2020, 2:42 PM
2020-08-12 14:42:09 (UTC+2)
Log In to Comment