Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.perl.misc > #8520

Re: Tree::Range 0.1 released

From Ivan Shmakov <oneingray@gmail.com>
Newsgroups comp.lang.perl.modules, comp.lang.perl.misc
Subject Re: Tree::Range 0.1 released
Date 2013-06-27 11:05 +0000
Organization Aioe.org NNTP Server
Message-ID <87a9mb95l0.fsf@violet.siamics.net> (permalink)
References <87ip1igchz.fsf@violet.siamics.net> <87a9mc9l80.fsf@violet.siamics.net> <oo3t9a-pe72.ln1@anubis.morrow.me.uk> <87ppv87z1j.fsf@violet.siamics.net> <3ggt9a-22b2.ln1@anubis.morrow.me.uk>

Cross-posted to 2 groups.

Show all headers | View raw


>>>>> Ben Morrow <ben@morrow.me.uk> writes:
>>>>> Quoth Ivan Shmakov <oneingray@gmail.com>:
>>>>> Ben Morrow <ben@morrow.me.uk> writes:

[...]

 >> Still, it's recommended by [1] (though feel free to file a bug
 >> report if you think it shouldn't be):

 >> [...] A registration is not a prerequisite for uploading.  It is
 >> just recommended for better searchability of the CPAN and to avoid
 >> namespace clashes.  [...]

 > See <https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/
 > master/lancaster-consensus.md#module-registration> (and indeed the
 > rest of that document).  While this is a 'new' agreement, in the Perl
 > world agreements and specs usually come after implementation, so it
 > is describing the way things currently work in practice.

	So, I guess [1] is going to be updated within a few months from
	now.  Thanks.

 >> [1] https://pause.perl.org/pause/authenquery?ACTION=apply_mod

[...]

 >>> However, it goes against convention to have a distribution called
 >>> Tree-Range that does not contain a module Tree::Range.  You should
 >>> consider either renaming Tree::Range::base

 >> Won't this go against the example set by Digest::base? (which I tend
 >> to think as a good enough to stick to.)

 > It's not a convention I've seen before, but there's nothing wrong
 > with it.  (It would be more usual to be ::Base, at least; the analogy
 > with base.pm is not really relevant any more.)

	AIUI, the "capital-case" names under Digest:: are reserved for
	the actual message digest algorithms.  For instance,
	Digest->new ("SHA-1") ends up in a call to Digest::SHA->new (1).

 >>> or at least providing a documentation-only Tree::Range explaining
 >>> why there isn't a module there.

 >> I guess I'd consider [it] for 0.2.  (Which I hope'll be the release
 >> fixing only the documentation and the metadata.)

 >> The other option would be to have Tree::Range->new () behave like
 >> Digest->new ().

 > Yeah, perhaps.  I haven't really got a sense of what this module's
 > useful for, so I can't comment.

	One of the possible uses of Tree::Range::RB specifically is to
	operate on .newsrc data.  Consider, e. g.:

### gxmj7tsetytsnbnp85yhxyjror.perl  -*- Perl -*-

### Ivan Shmakov, 2013

### Code:

use common::sense;

require Tree::Range::RB;

sub ranges_parse {
    my ($in, @ranges) = @_;
    foreach my $range (@ranges) {
        my ($a, $b)
            = ($range =~ /^([0-9]+)(?:-([0-9]+))?$/)
            or die ($range, ": is not a vaild range");
        $in->range_set ($a, 1 + ($b // $a), 1);
    }
    ## .
    $in;
}

my @comp_lang_perl_misc_s = qw {
    1-27551 27567 27575 27602-27606 27627-27629 27632 27634-27636
    27638-27996
    27998-28002 28004 28006-28008 28011-28013 28015-28027 28029 28032
    28036-28093
};

my $comp_lang_perl_misc
    = Tree::Range::RB->new ({ "cmp"     => sub { $_[0] <=> $_[1]; },
                              "equal-p" => sub { $_[0] eq  $_[1]; } });
ranges_parse ($comp_lang_perl_misc, @comp_lang_perl_misc_s);

{
    local ($,, $\)
        = (", ", "\n");

    ## check if 28007 was read? (i. e., what range 28007 belongs to?)
    print ($comp_lang_perl_misc->get_range (28007));
    ## => 1, 28006, 28009

    ## now the user has marked some more articles as read
    ranges_parse ($comp_lang_perl_misc, qw (28005 28009 28010));

    ## check if 28011 was read? (i. e., what range 28011 belongs to?)
    print ($comp_lang_perl_misc->get_range (28011));
    ## => 1, 28004, 28014

    ## note how the range was extended as the gaps were filled
}

### gxmj7tsetytsnbnp85yhxyjror.perl ends here

	Similarly, by utilizing the Tree::RB's own iterator, a simple
	and efficient serializer for this kind of data can be built.

-- 
FSF associate member #7257

Back to comp.lang.perl.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

a new Tree::Interval-like module on top of Tree::RB? Ivan Shmakov <oneingray@gmail.com> - 2013-06-13 17:13 +0000
  Tree::Range 0.1 released Ivan Shmakov <oneingray@gmail.com> - 2013-06-27 05:27 +0000
    Re: Tree::Range 0.1 released Ben Morrow <ben@morrow.me.uk> - 2013-06-27 07:47 +0100
      Re: Tree::Range 0.1 released Ivan Shmakov <oneingray@gmail.com> - 2013-06-27 08:12 +0000
        Re: Tree::Range 0.1 released Ben Morrow <ben@morrow.me.uk> - 2013-06-27 11:24 +0100
          Re: Tree::Range 0.1 released Ivan Shmakov <oneingray@gmail.com> - 2013-06-27 11:05 +0000
            Re: Tree::Range 0.1 released Ben Morrow <ben@morrow.me.uk> - 2013-06-27 12:50 +0100
              Re: Tree::Range 0.1 released Ivan Shmakov <oneingray@gmail.com> - 2013-06-27 13:11 +0000
                Benchmark-ing Tree::Range::RB? Ivan Shmakov <oneingray@gmail.com> - 2013-07-02 19:37 +0000

csiph-web