Algorithm-VectorClocks
view release on metacpan or search on metacpan
lib/Algorithm/VectorClocks.pm view on Meta::CPAN
=back
=head2 $vc->serialize
Returns a serialized form of $vc,
which is intended to be exchanged with the other servers.
This module overloads a string conversion operator,
and the following code does the same thing:
"$vc"
=head2 $vc->increment
Increments its own clock in $vc, and returns the object itself.
This module overloads an increment operator,
and the following code does the same thing:
$vc++;
=head2 $vc->merge($other_vc)
Merges $other_vc into $vc itself, and returns the object itself.
This module overloads an assignment forms of additional operator,
and the following code does the same thing:
$vc += $other_vc;
=head2 $vc->equal($other_vc)
Returns true if $vc equals $other_vc.
This module overloads a comparison operator,
and the following code does the same thing:
$vc == $other_vc;
$vc eq $other_vc;
=head2 $vc->not_equal($other_vc)
Returns true unless $vc equals $other_vc.
This module overloads a comparison operator,
and the following code does the same thing:
$vc != $other_vc;
$vc ne $other_vc;
=head2 $vc->clocks
Returns the vector of clocks.
=head2 order_vector_clocks({ $id => $vc, ... })
Returns the list of server IDs in order (the latest comes first).
The arguments can be a HASH reference of server IDs and their vector clocks.
If some vector clocks are same or independently updated (cannot be ordered),
they are packed into single element as an array reference.
In the following example, vector clocks of A and C are independent with each other,
and B is older than them:
@res = order_vector_clocks({ A => $vc_a, B => $vc_b, C => $vc_c });
$res[0][0]; # is 'A' or 'C'
$res[0][1]; # is 'A' or 'C'
$res[1]; # is 'B'
=head1 INTERNAL METHODS
=head2 _pack_independent_vector_clocks
Packs independent clocks into a single element in a array.
=head2 are_independent($vc, ...)
Returns true if any pair of $vc's are independent with each other.
=head2 $vc->_is_independent($other_vc)
Returns true if $vc and $other_vc are independent with each other.
=head2 $vc->_compare($other_vc)
Compares $vc with $other_vc,
which can be an Algorithm::VectorClock object or a serialied one.
Returns a negative value if $vc is a cause of $other_vc.
Returns a positive value if $vc is an effect of $other_vc.
Returns zero if $vc and $other_vc are same or independent.
=head2 _list_ids(@vcs)
=head1 SEE ALSO
Friedemann Mattern, "Virtual Time and Global States of Distributed Systems," Proc. Workshop on Parallel and Distributed Algorithms, 1989.
=head1 AUTHOR
Takeru INOUE C<< <takeru.inoue _ gmail.com> >>
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2008, Takeru INOUE C<< <takeru.inoue _ gmail.com> >>. All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
=head1 DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
( run in 1.572 second using v1.01-cache-2.11-cpan-140bd7fdf52 )