From: Bardur A. <oca...@sc...> - 2004-06-02 22:06:38
|
On Wed, Jun 02, 2004 at 04:58:25PM -0500, Brian Hurt wrote: > On Wed, 2 Jun 2004, Bardur Arantsson wrote: > > > I just though of something else which might be useful both > > for internal use, but also for users of the library (well, > > me in any case ;)): What about introducing a > > "node-pointer" type (and "index" if you will) which could > > be used as a starting point/stopping point for iteration? > > > > Then one could do things like: > > > > let b = find_ix some_key1 map > > and e = find_ix some_key2 map > > in > > ExtMap.iter ~first:b ~last:e (fun ...) map > > Why not just make the first and last arguments keys? In other words: > ExtMap.iter ~first:some_key1 ~last:some_key2 (fun ...) map Well, the thing is that by using 'indexes' you can reuse the range 'boundary elements' in case you need to do two traversals with the same 'first' element, but a different 'last' element (or vice versa). The idea is that the actual key lookup happens when the 'index' is built, so you can avoid looking up the keys multiple times. Granted, lookup is only an O(logN) operation, but still... > > How usefull (to people other than you) would such functions be? Of course, I'm not qualified to answer that :) > They wouldn't be that complicated, but I'd be inclined to > make them a different function rather than using optional > arguments. The good thing about using optional arguments for this is that you essentially get 4 functions from 1: You can support ranges of the types [...,b] [a,...] [a,...,b] [...] with one function. (And yes, I *am* currently doing something which requires all four types of ranges for iteration :)). The interface quickly becomes very ugly if you don't use optional arguments in this sort of situation... -- Bardur Arantsson <ba...@im...> <ba...@sc...> - And the best part? I didn't learn a thing. |