projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add 1702 prefix cty.dat data
[spider.git]
/
perl
/
RingBuf.pm
diff --git
a/perl/RingBuf.pm
b/perl/RingBuf.pm
index 82b534e41d2081887c4cee814cade8dee0a4286a..b55c19aae908c7a74c5fdea3339bfac97557f7a2 100644
(file)
--- a/
perl/RingBuf.pm
+++ b/
perl/RingBuf.pm
@@
-21,7
+21,14
@@
sub new
{
my $pkg = shift;
my $size = shift;
{
my $pkg = shift;
my $size = shift;
- return bless [$size, 0, 0, 0, 0, []], (ref $pkg || $pkg);
+
+ # 0 - size
+ # 1 - lth
+ # 2 - end
+ # 3 - start
+ # 4 - pos
+ # 5 - buffer []
+ return bless [$size+1, 0, 0, 0, 0, []], (ref $pkg || $pkg);
}
sub write
}
sub write
@@
-30,10
+37,7
@@
sub write
$self->[5]->[$self->[2]++] = shift;
$self->[2] = 0 if $self->[2] >= $self->[0];
$self->[5]->[$self->[2]++] = shift;
$self->[2] = 0 if $self->[2] >= $self->[0];
- if ($self->[1] < $self->[0]) {
- $self->[1] = ++$self->[1];
- }
- $self->[2] = $self->[2];
+ $self->[1]++ if $self->[1] < $self->[0];
if ($self->[1] == $self->[0] && $self->[2] == $self->[3]) {
$self->[3] = $self->[2]+1;
$self->[3] = 0 if $self->[3] >= $self->[0];
if ($self->[1] == $self->[0] && $self->[2] == $self->[3]) {
$self->[3] = $self->[2]+1;
$self->[3] = 0 if $self->[3] >= $self->[0];