caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* map implementation question
@ 2006-08-04 20:08 Brian Hurt
  2006-08-17 11:37 ` [Caml-list] " Xavier Leroy
  0 siblings, 1 reply; 4+ messages in thread
From: Brian Hurt @ 2006-08-04 20:08 UTC (permalink / raw)
  To: caml-list

I was just looking at the map.ml implementation, and noticed that the 
logic for when to do a rotation was:

>       if hl > hr + 2 then begin


Isn't this supposed to be:

    if hl >= hr + 2 then begin

?  The latter will cause more rotations, but keep the tree more 
balanced.  The worst-case access of the >= version is log base 3/2, 
while the > is log base 4/3, which means that the >= will be about 41% 
(log(3/2)/log(4/3) ~ 1.41).  Both are correct in that they return the 
right answer and are still O(log(N)) performance, it's a question of 
performance of looking up an element in the tree vr.s the cost of 
inserting an element into the tree.

Was there a reason it was done this way, or is this a (minor) bug?

Brian


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-08-17 18:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-04 20:08 map implementation question Brian Hurt
2006-08-17 11:37 ` [Caml-list] " Xavier Leroy
2006-08-17 16:25   ` j h woodyatt
2006-08-17 18:54   ` Shawn

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).