X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FRingBuf.pm;h=8a2a836182925c49cc7674517636fd81508bace6;hb=431c8a14cdecd0ec455b6619380687dbe84e2a35;hp=82b534e41d2081887c4cee814cade8dee0a4286a;hpb=9cc26cc7a73efb7679d3e8e819ba0019307f8607;p=spider.git diff --git a/perl/RingBuf.pm b/perl/RingBuf.pm index 82b534e4..8a2a8361 100644 --- a/perl/RingBuf.pm +++ b/perl/RingBuf.pm @@ -3,25 +3,26 @@ # # Copyright (c) - 1998 Dirk Koopman G1TLH # -# $Id$ +# # use strict; package RingBuf; -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; - sub new { 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 @@ -30,10 +31,7 @@ sub write $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];