Re: how to create a ordered data structure which would efficiently return the element before and after it

2011-09-01 Thread Ken Wesson
On Thu, Sep 1, 2011 at 2:08 PM, Alan Malloy  wrote:
> Well, the two calls to subseq are unpleasant and possibly slow. I was
> thinking there's a way to write it as a single operation that returns
> three items, say (subseq s >= (dec 50)) to get the items before and
> after 50, but of course that doesn't work unless you know 49 is in
> there, and in that case why bother with subseq?
>
> It's a bit galling, because the sorted-set *knows* how to get to where
> 50 should be, and how to walk in either direction from there, but in
> order to walk in two different directions you have to walk down from
> the root twice. Maybe it'd be nice to have a (get-walker s 50) that
> you can later pass directions to, to walk through the set in whatever
> order.

A less-Clojury solution would be to have sorted-set implement List,
and provide something like get-walker that yields a ListIterator on
the specified element, or the next higher if any, or one past the end
otherwise, or whatever.

Of course a ListIterator is a mutable Java object.

A Clojury solution would be a function that traverses from the root
and then generates a return value equivalent to [(rsubseq s x) (subseq
s x)], except not performing two traversals to generate it. The caller
can destructure this and use the two seqs.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: how to create a ordered data structure which would efficiently return the element before and after it

2011-09-01 Thread Alan Malloy
Well, the two calls to subseq are unpleasant and possibly slow. I was
thinking there's a way to write it as a single operation that returns
three items, say (subseq s >= (dec 50)) to get the items before and
after 50, but of course that doesn't work unless you know 49 is in
there, and in that case why bother with subseq?

It's a bit galling, because the sorted-set *knows* how to get to where
50 should be, and how to walk in either direction from there, but in
order to walk in two different directions you have to walk down from
the root twice. Maybe it'd be nice to have a (get-walker s 50) that
you can later pass directions to, to walk through the set in whatever
order.


On Sep 1, 3:36 am, Sunil S Nandihalli 
wrote:
> Thanks Dave,
>  That did it. I did not know there was rsubseq .. :)
> Thanks
> Sunil.
>
>
>
>
>
>
>
> On Thu, Sep 1, 2011 at 4:04 PM, David Powell  wrote:
>
> > On Thu, Sep 1, 2011 at 11:13 AM, Sunil S Nandihalli <
> > sunil.nandiha...@gmail.com> wrote:
>
> >> Hi Everybody,
> >>  I would like to create a sorted-data-structure which would enable me to
> >> efficiently
>
> >> 1. insert new elements into it maintaining the sorted-nature of the data
> >> structure.
> >> 2. query as to which element is immediately before and after a value that
> >> I present. one can assume that the value that I present is guaranteed to be
> >> present in the data-structure.
>
> >> How can I do it? what should I be using to achieve this? I tried to see if
> >> finger-trees could help with my limited understanding with no success. This
> >> might be pretty basic .. but some how I seem to be missing something.
>
> > Is this what you want?
>
> > user=> (def s (sorted-set 38 42 123 598 23 10 1 88))
>
> > user=> (first (subseq s > 50))
> >  88
>
> > (first (rsubseq s < 50))
> > 42
>
> > --
> > Dave
>
> >  --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: how to create a ordered data structure which would efficiently return the element before and after it

2011-09-01 Thread Sunil S Nandihalli
Thanks Dave,
 That did it. I did not know there was rsubseq .. :)
Thanks
Sunil.

On Thu, Sep 1, 2011 at 4:04 PM, David Powell  wrote:

>
>
> On Thu, Sep 1, 2011 at 11:13 AM, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
>> Hi Everybody,
>>  I would like to create a sorted-data-structure which would enable me to
>> efficiently
>>
>> 1. insert new elements into it maintaining the sorted-nature of the data
>> structure.
>> 2. query as to which element is immediately before and after a value that
>> I present. one can assume that the value that I present is guaranteed to be
>> present in the data-structure.
>>
>> How can I do it? what should I be using to achieve this? I tried to see if
>> finger-trees could help with my limited understanding with no success. This
>> might be pretty basic .. but some how I seem to be missing something.
>>
>>
> Is this what you want?
>
> user=> (def s (sorted-set 38 42 123 598 23 10 1 88))
>
> user=> (first (subseq s > 50))
>  88
>
> (first (rsubseq s < 50))
> 42
>
> --
> Dave
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: how to create a ordered data structure which would efficiently return the element before and after it

2011-09-01 Thread David Powell
On Thu, Sep 1, 2011 at 11:13 AM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hi Everybody,
>  I would like to create a sorted-data-structure which would enable me to
> efficiently
>
> 1. insert new elements into it maintaining the sorted-nature of the data
> structure.
> 2. query as to which element is immediately before and after a value that I
> present. one can assume that the value that I present is guaranteed to be
> present in the data-structure.
>
> How can I do it? what should I be using to achieve this? I tried to see if
> finger-trees could help with my limited understanding with no success. This
> might be pretty basic .. but some how I seem to be missing something.
>
>
Is this what you want?

user=> (def s (sorted-set 38 42 123 598 23 10 1 88))

user=> (first (subseq s > 50))
88

(first (rsubseq s < 50))
42

-- 
Dave

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: how to create a ordered data structure which would efficiently return the element before and after it

2011-09-01 Thread Sunil S Nandihalli
I really feel sorted-set should have something to achieve what I want .. but
don't seem to find it..


On Thu, Sep 1, 2011 at 3:53 PM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> I seem to miss the c++ stl library where it would be trivial to do this!
> Sunil.
>
>
> On Thu, Sep 1, 2011 at 3:43 PM, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
>> Hi Everybody,
>>  I would like to create a sorted-data-structure which would enable me to
>> efficiently
>>
>> 1. insert new elements into it maintaining the sorted-nature of the data
>> structure.
>> 2. query as to which element is immediately before and after a value that
>> I present. one can assume that the value that I present is guaranteed to be
>> present in the data-structure.
>>
>> How can I do it? what should I be using to achieve this? I tried to see if
>> finger-trees could help with my limited understanding with no success. This
>> might be pretty basic .. but some how I seem to be missing something.
>>
>> Thanks in advance.
>> Sunil.
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: how to create a ordered data structure which would efficiently return the element before and after it

2011-09-01 Thread Sunil S Nandihalli
I seem to miss the c++ stl library where it would be trivial to do this!
Sunil.

On Thu, Sep 1, 2011 at 3:43 PM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hi Everybody,
>  I would like to create a sorted-data-structure which would enable me to
> efficiently
>
> 1. insert new elements into it maintaining the sorted-nature of the data
> structure.
> 2. query as to which element is immediately before and after a value that I
> present. one can assume that the value that I present is guaranteed to be
> present in the data-structure.
>
> How can I do it? what should I be using to achieve this? I tried to see if
> finger-trees could help with my limited understanding with no success. This
> might be pretty basic .. but some how I seem to be missing something.
>
> Thanks in advance.
> Sunil.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

how to create a ordered data structure which would efficiently return the element before and after it

2011-09-01 Thread Sunil S Nandihalli
Hi Everybody,
 I would like to create a sorted-data-structure which would enable me to
efficiently

1. insert new elements into it maintaining the sorted-nature of the data
structure.
2. query as to which element is immediately before and after a value that I
present. one can assume that the value that I present is guaranteed to be
present in the data-structure.

How can I do it? what should I be using to achieve this? I tried to see if
finger-trees could help with my limited understanding with no success. This
might be pretty basic .. but some how I seem to be missing something.

Thanks in advance.
Sunil.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en