Gnus development mailing list
 help / color / mirror / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Ranges
Date: Thu, 08 Jan 2004 16:52:04 -0500	[thread overview]
Message-ID: <4nn08yhzwb.fsf@collins.bwh.harvard.edu> (raw)
In-Reply-To: <m31xqcfptu.fsf@quimbies.gnus.org> (Lars Magne Ingebrigtsen's message of "Wed, 07 Jan 2004 03:35:41 +0100")

On Wed, 07 Jan 2004, larsi@gnus.org wrote:

> Ted Zlatanov <tzz@lifelogs.com> writes:
> 
>>> Inversion list Range list  Full list 
>>> (2 5 7 8)      ((2 . 4) 7) (2 3 4 7)
>>
>> Right.  Inversion lists are as compact as ranges, but have some
>> nicer features - insertion and deletion of items from the inversion
>> list is, I think, simpler and faster code than ranges.
> 
> In this example, it's one cons cell more.  :-)

For short ranges (less than 4 items per interval, I think), it's
better to use explicit article numbers than almost anything else.  The
example was not very good to show why inversion lists should be used.

I'll show the sequence in a more real-life situation, and see if you
think inversion lists may be useful.  I'll use a list of 1000 items
that can be on or off.

start with () = all items are off; below is the running state as 1 or
0; also I include the range representations

set items 5, 20, 80-100 on
(5 6 20 21 80 101)
 1100111000111000 

range: (5 20 21 (80 . 100))

set items 100-1000 on
(5 6 20 21 80 100 100 101 101 1001); consolidate to
 110011100011100001111000011110000

(5 6 20 21 80 1001)
 11001110001110000

range: (5 20 21 (80 . 1000))

set items 21-79 on
(5 6 20 21 21 80 80 1001); consolidate to
 11001110001110001110000

(5 6 20 1001)
 11001110000

range: (5 (20 . 1000))

set items 50, 500, 999 off

(5 6 20 50 51 500 501 999 1000 1001)
 1100111000111000011110000111110000

range: (5 (20 . 49) (51 . 499) (501 . 1000))

So yes, this is far less intuitive than ranges.  I think, however,
that it may be faster for operations.  If you think it's worthwhile, I
can try adding gnus-range.el functions that use inversion lists and we
can benchmark them.

For a start, here's the gnus-member-of-invlist function, much simpler
than gnus-member-of-range:

(defun gnus-member-of-invlist (number list)
  (let (state)
    (while (and list
		(>= number (car list)))
      (setq state (not state))
      (setq list (cdr list)))
    state))

I found that it was slower to search this way:

(benchmark-run-compiled 50000 (gnus-member-of-invlist 800 '(5 6 20 50 51 500 501 999 1000 1001)))
(2.5340199999999995 10 3.791519999999963)
(benchmark-run-compiled 50000 (gnus-member-of-range 800 '(5 (20 . 49) (51 . 499) (501 . 1000))))
(0.4903200000000001 10 4.371743000000038)

I may have missed something in the gnus-member-of-invlist
implementation, I'm not sure.  I'm not well-versed in the internal
Emacs implementation of lists, so maybe there's a better way of
storing the inversion list.  Vectors may work - with the advantages
of binary searching and an easy distinction from ranges, which can
still be stores as lists.

The code for the other gnus-range.el functions will also be
significantly shorter using inversion lists, though I'm not sure if
they will be faster - I'd need to benchmark.

Ted



  reply	other threads:[~2004-01-08 21:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-05  4:45 Ranges Lars Magne Ingebrigtsen
2004-01-05  6:49 ` Ranges Zack Weinberg
2004-01-05 10:57   ` Ranges Per Abrahamsen
2004-01-05  7:13 ` Ranges Steve Youngs
2004-01-05  7:51   ` Ranges Lars Magne Ingebrigtsen
2004-01-05 11:01 ` Ranges Kim Minh Kaplan
2004-01-05 11:19   ` Ranges Lars Magne Ingebrigtsen
2004-01-06  8:44     ` Ranges Kim Minh Kaplan
2004-01-05 19:01 ` Ranges Ted Zlatanov
2004-01-06  4:58   ` Ranges Lars Magne Ingebrigtsen
2004-01-06  5:26     ` Ranges Paul Jarc
2004-01-06  6:44       ` Ranges Ted Zlatanov
2004-01-07  2:35         ` Ranges Lars Magne Ingebrigtsen
2004-01-08 21:52           ` Ted Zlatanov [this message]
2004-01-10 18:43             ` Ranges Dan Christensen
2004-01-12 21:13               ` Ranges Ted Zlatanov
2004-01-12 21:28           ` Ranges Paul Jarc
2004-01-20 23:53             ` Ranges Ted Zlatanov
2004-01-21  7:15               ` Ranges Paul Jarc
2004-01-21 15:19                 ` Ranges Ted Zlatanov
2004-01-05 21:39 ` Ranges Kai Grossjohann
2004-01-06  5:00   ` Ranges Lars Magne Ingebrigtsen
2004-01-06  6:34     ` Ranges Steve Youngs
2004-01-10 16:13 ` Ranges Gaute B Strokkenes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4nn08yhzwb.fsf@collins.bwh.harvard.edu \
    --to=tzz@lifelogs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).