projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix typo
[spider.git]
/
perl
/
Chain.pm
diff --git
a/perl/Chain.pm
b/perl/Chain.pm
index cb3a2be83feaf27eabf182ae5be8b84e058aea27..60266c755716d84d3aa625c90ad2b8a25e84b671 100644
(file)
--- a/
perl/Chain.pm
+++ b/
perl/Chain.pm
@@
-2,16
+2,20
@@
package Chain;
use strict;
use Carp;
use strict;
use Carp;
-
-use vars qw($VERSION $docheck);
-$VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r};
+use vars qw($VERSION $BRANCH);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
+$main::build += $VERSION;
+$main::branch += $BRANCH;
use constant NEXT => 0;
use constant PREV => 1;
use constant OBJ => 2;
use constant NEXT => 0;
use constant PREV => 1;
use constant OBJ => 2;
-$docheck = 1;
+use vars qw($docheck);
+
+$docheck = 0;
sub _check
{
sub _check
{
@@
-30,10
+34,11
@@
sub setcheck
# constructor
sub new
{
# constructor
sub new
{
- my $name = shift;
- my $ref = shift;
+ my $pkg = shift;
+ my $name = ref $pkg || $pkg;
+
my $self = [];
my $self = [];
- push @$self, $self, $self,
$ref
;
+ push @$self, $self, $self,
@_
;
return bless $self, $name;
}
return bless $self, $name;
}
@@
-44,7
+49,7
@@
sub ins
$docheck && _check($p);
$docheck && _check($p);
- my $q = ref $ref && $ref->isa('Chain') ? $ref :
new Chain $ref
;
+ my $q = ref $ref && $ref->isa('Chain') ? $ref :
Chain->new($ref)
;
$q->[PREV] = $p->[PREV];
$q->[NEXT] = $p;
$p->[PREV]->[NEXT] = $q;
$q->[PREV] = $p->[PREV];
$q->[NEXT] = $p;
$p->[PREV]->[NEXT] = $q;
@@
-68,9
+73,10
@@
sub del
$docheck && _check($p);
$docheck && _check($p);
- $p->[PREV]->[NEXT] = $p->[NEXT];
+
my $q =
$p->[PREV]->[NEXT] = $p->[NEXT];
$p->[NEXT]->[PREV] = $p->[PREV];
$p->[NEXT]->[PREV] = $p->[PREV];
- return $p->[PREV];
+ $p->[NEXT] = $p->[PREV] = undef;
+ return $q;
}
# Is this chain empty?
}
# Is this chain empty?
@@
-104,7
+110,7
@@
sub prev
$docheck && _check($base);
$docheck && _check($base);
- return $base->[
NEXT
] == $base ? undef : $base->[PREV] unless $p;
+ return $base->[
PREV
] == $base ? undef : $base->[PREV] unless $p;
$docheck && _check($p);
$docheck && _check($p);
@@
-150,6
+156,13
@@
sub count
return $count;
}
return $count;
}
+sub close
+{
+ my $base = shift;
+ $base->flush;
+ $base->[PREV] = $base->[NEXT] = undef;
+}
+
1;
__END__
# Below is the stub of documentation for your module. You better edit it!
1;
__END__
# Below is the stub of documentation for your module. You better edit it!
@@
-161,9
+174,9
@@
Chain - Double linked circular chain handler
=head1 SYNOPSIS
use Chain;
=head1 SYNOPSIS
use Chain;
- $base = new Chain;
- $p->ins($ref);
- $p->add($ref);
+ $base = new Chain
[$obj]
;
+ $p->ins($ref
[,$obj]
);
+ $p->add($ref
[,$obj]
);
$ref = $p->obj or $p->obj($ref);
$q = $base->next($p);
$q = $base->prev($p);
$ref = $p->obj or $p->obj($ref);
$q = $base->next($p);
$q = $base->prev($p);