File: BFS.pm

package info (click to toggle)
libgraph-perl 1%3A0.96-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,316 kB
  • ctags: 938
  • sloc: perl: 6,094; sh: 8; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package Graph::Traversal::BFS;

use strict;

use Graph::Traversal;
use base 'Graph::Traversal';

sub current {
    my $self = shift;
    $self->{ order }->[ 0 ];
}

sub see {
    my $self = shift;
    shift @{ $self->{ order } };
}

*bfs = \&Graph::Traversal::postorder;

1;
__END__
=pod

=head1 NAME

Graph::Traversal::BFS - breadth-first traversal of graphs

=head1 SYNOPSIS

    use Graph;
    my $g = Graph->new;
    $g->add_edge(...);
    use Graph::Traversal::BFS;
    my $b = Graph::Traversal::BFS->new($g, %opt);
    $b->bfs; # Do the traversal.

=head1 DESCRIPTION

With this class one can traverse a Graph in breadth-first order.

The callback parameters %opt are explained in L<Graph::Traversal>.

=head2 Methods

The following methods are available:

=over 4

=item bfs

Traverse the graph in breadth-first order.  Returns all vertices
traversed in post-order.

=back

=head1 SEE ALSO

L<Graph::Traversal>, L<Graph::Traversal::DFS>, L<Graph>.

=cut