line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::SomeUtils; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
161215
|
use 5.012000; |
|
3
|
|
|
|
|
43
|
|
4
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
70
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
119
|
|
6
|
3
|
|
|
3
|
|
16
|
use base qw(Exporter); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
491
|
|
7
|
3
|
|
|
3
|
|
1520
|
use Graph; |
|
3
|
|
|
|
|
277606
|
|
|
3
|
|
|
|
|
1526
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.20'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
12
|
|
|
|
|
|
|
graph_delete_vertices_fast |
13
|
|
|
|
|
|
|
graph_delete_vertex_fast |
14
|
|
|
|
|
|
|
graph_all_successors_and_self |
15
|
|
|
|
|
|
|
graph_all_predecessors_and_self |
16
|
|
|
|
|
|
|
graph_vertices_between |
17
|
|
|
|
|
|
|
graph_get_vertex_label |
18
|
|
|
|
|
|
|
graph_set_vertex_label |
19
|
|
|
|
|
|
|
graph_isolate_vertex |
20
|
|
|
|
|
|
|
graph_delete_vertices_except |
21
|
|
|
|
|
|
|
graph_truncate_to_vertices_between |
22
|
|
|
|
|
|
|
) ] ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw( |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub graph_get_vertex_label { |
30
|
1
|
|
|
1
|
1
|
1444
|
my ($g, $v) = @_; |
31
|
1
|
|
|
|
|
7
|
return $g->get_vertex_attribute($v, 'label'); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub graph_set_vertex_label { |
35
|
1
|
|
|
1
|
1
|
9663
|
my ($g, $v, $label) = @_; |
36
|
1
|
|
|
|
|
8
|
$g->set_vertex_attribute($v, 'label', $label); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub graph_delete_vertex_fast { |
40
|
767
|
|
|
767
|
1
|
3030
|
my $g = shift; |
41
|
767
|
|
|
|
|
1773
|
$g->expect_non_unionfind; |
42
|
767
|
|
|
|
|
4972
|
my $V = $g->[ Graph::_V ]; |
43
|
767
|
100
|
|
|
|
1736
|
return $g unless $V->has_path( @_ ); |
44
|
570
|
|
|
|
|
7277
|
$g->delete_edge($_[0], $_) for $g->successors($_[0]); |
45
|
570
|
|
|
|
|
709382
|
$g->delete_edge($_, $_[0]) for $g->predecessors($_[0]); |
46
|
570
|
|
|
|
|
309370
|
$V->del_path( @_ ); |
47
|
570
|
|
|
|
|
6545
|
$g->[ Graph::_G ]++; |
48
|
570
|
|
|
|
|
1481
|
return $g; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub graph_delete_vertices_fast { |
52
|
40
|
|
|
40
|
1
|
6892615
|
my $g = shift; |
53
|
40
|
|
|
|
|
287
|
graph_delete_vertex_fast($g, $_) for @_; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub graph_vertices_between { |
57
|
0
|
|
|
0
|
1
|
|
my ($g, $src, $dst) = @_; |
58
|
0
|
|
|
|
|
|
my %from_src; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$from_src{$_}++ for graph_all_successors_and_self($g, $src); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return grep { |
63
|
0
|
|
|
|
|
|
$from_src{$_} |
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} graph_all_predecessors_and_self($g, $dst); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub graph_all_successors_and_self { |
68
|
0
|
|
|
0
|
1
|
|
my ($g, $v) = @_; |
69
|
0
|
|
|
|
|
|
return ((grep { $_ ne $v } $g->all_successors($v)), $v); |
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub graph_all_predecessors_and_self { |
73
|
0
|
|
|
0
|
1
|
|
my ($g, $v) = @_; |
74
|
0
|
|
|
|
|
|
return ((grep { $_ ne $v } $g->all_predecessors($v)), $v); |
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub graph_isolate_vertex { |
78
|
0
|
|
|
0
|
1
|
|
my ($g, $vertex) = @_; |
79
|
0
|
|
|
|
|
|
$g->delete_edge($vertex, $_) for $g->successors($vertex); |
80
|
0
|
|
|
|
|
|
$g->delete_edge($_, $vertex) for $g->predecessors($vertex); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub graph_delete_vertices_except { |
84
|
0
|
|
|
0
|
1
|
|
my ($g, @vertices) = @_; |
85
|
0
|
|
|
|
|
|
my %keep = map { $_ => 1 } @vertices; |
|
0
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
graph_delete_vertices_fast($g, |
88
|
0
|
|
|
|
|
|
grep { not $keep{$_} } $g->vertices); |
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub graph_truncate_to_vertices_between { |
92
|
0
|
|
|
0
|
1
|
|
my ($g, $start, $final) = @_; |
93
|
0
|
|
|
|
|
|
graph_delete_vertices_except($g, |
94
|
|
|
|
|
|
|
graph_vertices_between($g, $start, $final)); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |