All of lore.kernel.org
 help / color / mirror / Atom feed
From: Herbert Poetzl <herbert@13thfloor.at>
To: Werner Almesberger <wa@almesberger.net>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: barriers vs. reads
Date: Thu, 24 Jun 2004 10:00:08 +0200	[thread overview]
Message-ID: <20040624080008.GA22997@MAIL.13thfloor.at> (raw)
In-Reply-To: <20040624003944.B21586@almesberger.net>

On Thu, Jun 24, 2004 at 12:39:44AM -0300, Werner Almesberger wrote:
> I wrote:
> > BTW, regarding overlapping requests, I wonder if there's a data
> > structure that gives O(log requests) or such lookups for ranges.
> 
> Seem that I've found one that is maybe 2-4 times as expensive as a
> single tree. It works as follows: if we have a set of ranges (a,b)
> and want to see if any of them overlap with a range (x,y), we
> compare the indices of the matches (or almost-matches).
> 
>   num_overlaps = |{a : a < y}| - |{b : b <= x}|
> 
> "{a : a < y}" is "the set of all a where a < y". "|...|" is the
> number of elements in a set.
> 
> We could obtain such indices by counting the number of nodes in
> each branch of the tree. That's O(1) for all regular tree
> operations, and O(log n) for the sum. The index is the size of
> all the trees under left branches we haven't taken, plus the
> number of nodes we've left through the right branch. If there are
> multiple equal entries, we must find the first one.
> 
> One problem: I did this mostly by instinct. It seems to work
> perfectly, but I can't quite explain why :-(

hmm ... there are eight cases how ranges can interact ...

    a     b     		        		a	  b
    |     |			        		|	  |
 1) +-----+       +---------+	       2) +-----+	+---------+
                  |         |	          |	|
		  x         y	          x	y

    a             b		        		a	  b
    |      	  |		        		|	  |
 3) +-------------+---------+	       4) +-------------+---------+
                  |         |	          |		|
		  x         y	          x		y


    a                 b    	        	a		  b
    |                 | 	        	|		  |
 5) +-------------+===+-----+	       6) +-----+========+--------+
                  |         |	          |		 |
		  x         y	          x		 y
	
    a			    b	        	a	 b
    |			    |	        	|	 |
 7) +-----+========+--------+	       8) +-----+========+--------+
          |        |		          |			  |
	  x        y		          x			  y
	

by verifying those eight cases for correctness, you
can conclude, that the sum of N such cases will give
the correct number of overlaps (with a given test
range); verification itself is simple:

case     a<y    b<=x    |{a:a<y}| - |{b:b<= x}|
------+-------+-------+-------------------------
 1)   |  YES  |  YES  |  0
 2)   |  NO   |  NO   |  0
 3)   |  YES  |  YES  |  0
 4)   |  NO   |  NO   |  0
------+-------+-------+-----
 5)   |  YES  |  NO   |  1
 6)   |  YES  |  NO   |  1
 7)   |  YES  |  NO   |  1
 8)   |  YES  |  NO   |  1

HTH,
Herbert

> I put a dirty little program to simulate this on
> http://abiss.sourceforge.net/t.tar.gz
> 
> - Werner
> 
> -- 
>   _________________________________________________________________________
>  / Werner Almesberger, Buenos Aires, Argentina         wa@almesberger.net /
> /_http://www.almesberger.net/____________________________________________/
> -
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2004-06-24  8:00 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-24  0:48 barriers vs. reads Werner Almesberger
2004-06-24  3:39 ` Werner Almesberger
2004-06-24  8:00   ` Herbert Poetzl [this message]
2004-06-24 12:16     ` Werner Almesberger
2004-06-24 13:36   ` Jamie Lokier
2004-06-24 17:02     ` Werner Almesberger
2004-06-24 16:39 ` Steve Lord
2004-06-24 17:00 ` barriers vs. reads - O_DIRECT Bryan Henderson
2004-06-24 17:46   ` Werner Almesberger
2004-06-24 18:50     ` Jamie Lokier
2004-06-24 20:55       ` Werner Almesberger
2004-06-24 22:42         ` Jamie Lokier
2004-06-25  3:21           ` Werner Almesberger
2004-06-25  3:57           ` Guy
2004-06-25  4:52             ` Werner Almesberger
2004-06-25  0:11     ` Bryan Henderson
2004-06-25  2:42       ` Werner Almesberger
2004-06-25 15:59         ` barriers vs. reads - O_DIRECT aio Bryan Henderson
2004-06-25 16:31         ` barriers vs. reads - O_DIRECT Bryan Henderson
  -- strict thread matches above, loose matches on Subject: below --
2004-06-22  3:53 barriers vs. reads Werner Almesberger
2004-06-22  7:39 ` Jens Axboe
2004-06-22  7:50   ` Werner Almesberger
2004-06-22  7:55     ` Jens Axboe
2004-06-22  8:34       ` Werner Almesberger
2004-06-22 10:08         ` Jens Axboe
2004-06-22 11:28       ` Jamie Lokier
2004-06-22 11:32         ` Jens Axboe
2004-06-22 17:12           ` Bryan Henderson
2004-06-22 20:53             ` Jens Axboe
2004-06-23 16:41               ` Bryan Henderson
2004-06-23 16:52                 ` Jens Axboe
2004-06-23 16:53                 ` Jamie Lokier
2004-06-23 21:08                   ` Bryan Henderson
2004-06-23 23:23                   ` Werner Almesberger
2004-06-24 13:43                     ` Jamie Lokier
2004-06-24 14:32                       ` Christoph Hellwig
2004-06-24 17:05                       ` Werner Almesberger
2004-06-22 18:53           ` Werner Almesberger
2004-06-22 19:57             ` Jamie Lokier
2004-06-22 23:13               ` Werner Almesberger
2004-06-22 20:57             ` Jens Axboe
2004-06-22 23:10               ` Werner Almesberger
2004-06-23  0:14                 ` Jamie Lokier
2004-06-23  6:27                 ` Jens Axboe
2004-06-22 18:45         ` Werner Almesberger
2004-06-22 19:07           ` Guy

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=20040624080008.GA22997@MAIL.13thfloor.at \
    --to=herbert@13thfloor.at \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=wa@almesberger.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.