caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
To: Simon Cruanes <>,
Subject: Re: [Caml-list] Choosing a random element in a Map or a Set
Date: Thu, 18 Mar 2021 18:06:44 +0100
Message-ID: <> (raw)
In-Reply-To: <YFNhxmn8RIuzsxsf@church>

Thanks Simon. This works beautifully and without having to write a
single additional line of code. A few modifications were enough.

That's the advantage of getting old: 30 years ago I would have jumped on
my keyboard, now I realize that somebody smarter than me has probably
already solved the problem, and I just ask and wait...  😁

Also thanks to all the other people who have answered my request. It's a
pleasure, and an honor, to be still part of this community.

Le 18/03/2021 à 15:20, Simon Cruanes a écrit :
> There are some balanced trees with a weight attached to each node.
> I have an implementation in containers-data
> [signature]( .
> There is a random_choose function that does the traversal and exploits
> the weight to pick left/right for each node.
> I implemented this years ago but the comments say:
>     Most of this comes from "implementing sets efficiently in a functional language", Stephen Adams.
>     The coefficients 5/2, 3/2 for balancing come from "balancing weight-balanced trees"

  reply	other threads:[~2021-03-18 17:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18  9:44 jean-marc.alliot
2021-03-18 10:06 ` François Pottier
2021-03-18 14:20   ` Simon Cruanes
2021-03-18 17:06     ` jean-marc.alliot [this message]
2021-03-18 11:10 ` Nicolas Barnier
2021-03-18 11:32   ` François Pottier
2021-03-19  1:32   ` Francois Berenger
2021-03-18 12:34 ` Ivan Gotovchits
2021-03-18 12:48 ` Ivan Gotovchits

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:

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

  git send-email \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

caml-list - the Caml user's mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror
	git clone --mirror

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 caml-list caml-list/ \
	public-inbox-index caml-list

Example config snippet for mirrors.
Newsgroup available over NNTP:

AGPL code for this site: git clone