Browse thread
[Caml-list] Map + Set
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Brian Hurt <bhurt@s...> |
| Subject: | Re: [Caml-list] Map + Set |
On Mon, 26 Jul 2004, Martin Jambon wrote:
> > > > val find: (elt -> int) -> t -> elt
> ^^^^^^^^^^^^
> This is a little unsafe, isn't it? What if you don't respect the ordering
> of your set?
Then the function throws Not_found when it shouldn't.
If you already have the object you're looking for, why are you looking for
it? Either that or you're using a set to really implement a map- use a
map instead.
> I think Brian and Matthieu are talking about 2 different things:
> (1) Martin and Brian were talking of an O(log n) find just like mem.
> (2) Matthieu and others are talking of a search using an
> arbitrary predicate just like List.find, in O(n) steps.
>
What's the advantage of doing the search in O(n) time when you can do it
in O(log n) time?
A function that finds *all* elements that fit a certain criteria I can
understand- but that's pretty easy to implement with fold.
--
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
- Gene Spafford
Brian
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners