Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Jon Harrop" <jon@ffconsultancy.com>
To: "'Jean-Christophe Filliâtre'" <Jean-Christophe.Filliatre@lri.fr>,
	"Caml List" <caml-list@inria.fr>
Subject: RE: [Caml-list] Priority queues, reloaded
Date: Sat, 9 Jul 2011 10:02:27 +0100	[thread overview]
Message-ID: <028b01cc3e16$ee050210$ca0f0630$@ffconsultancy.com> (raw)
In-Reply-To: <4E0CC220.8010706@lri.fr>

Jean-Christophe Filliâtre wrote:
> Wow, that's impressive! But I guess you didn't need to implement the
remove
> operation on red-black trees :-) That's a real pain.

Is Kahrs' so bad:

delete :: Ord a => a -> RB a -> RB a
delete x t =
	case del t of {T _ a y b -> T B a y b; _ -> E}
	where
	del E = E
	del (T _ a y b)
	    | x<y = delformLeft a y b
	    | x>y = delformRight a y b
            | otherwise = app a b
	delformLeft a@(T B _ _ _) y b = balleft (del a) y b
	delformLeft a y b = T R (del a) y b
	delformRight a y b@(T B _ _ _) = balright a y (del b)
	delformRight a y b = T R a y (del b)

balleft :: RB a -> a -> RB a -> RB a
balleft (T R a x b) y c = T R (T B a x b) y c
balleft bl x (T B a y b) = balance bl x (T R a y b)
balleft bl x (T R (T B a y b) z c) = T R (T B bl x a) y (balance b z (sub1
c))

balright :: RB a -> a -> RB a -> RB a
balright a x (T R b y c) = T R a x (T B b y c)
balright (T B a x b) y bl = balance (T R a x b) y bl
balright (T R a x (T B b y c)) z bl = T R (balance (sub1 a) x b) y (T B c z
bl)

sub1 :: RB a -> RB a
sub1 (T B a x b) = T R a x b
sub1 _ = error "invariance violation"

From:

  http://www.cs.kent.ac.uk/people/staff/smk/redblack/Untyped.hs

Anyone got this in OCaml?

Cheers,
Jon.




  reply	other threads:[~2011-07-09  9:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <sfid-j-20110630-131704-+2.76-1@multi.osbf.lua>
2011-06-30 17:13 ` Andrew
2011-06-30 17:26   ` Gabriel Scherer
2011-06-30 18:14     ` Jean-Christophe Filliâtre
2011-06-30 18:36     ` Jean-Christophe Filliâtre
2011-07-09  9:02       ` Jon Harrop [this message]
2011-07-09 19:22         ` Jean-Christophe Filliâtre
2011-07-10 18:04           ` Jon Harrop
2011-06-30 19:13     ` Andrew
2011-06-30 22:17     ` Wojciech Meyer
2011-07-02  1:49   ` Norman Ramsey
2011-07-09  9:05   ` Jon Harrop
     [not found] <848371343.3424870.1309454037170.JavaMail.root@zmbs3.inria.fr>
2011-06-30 18:03 ` Daniel de Rauglaudre
     [not found] <fa.V8myB/rA6OKILQg+GW40f8c1BGo@ifi.uio.no>
2011-07-02 12:24 ` Radu Grigore
2011-07-02 19:05   ` Andrew
2011-07-02 22:42   ` Radu Grigore
2011-07-10 17:55     ` Jon Harrop
2011-07-09 18:45 james woodyatt
     [not found] ` <14B0DF03-EF83-4568-AB34-6B51BCE4B574@recoil.org>
2011-07-09 18:56   ` james woodyatt

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='028b01cc3e16$ee050210$ca0f0630$@ffconsultancy.com' \
    --to=jon@ffconsultancy.com \
    --cc=Jean-Christophe.Filliatre@lri.fr \
    --cc=caml-list@inria.fr \
    /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