Alessandro Pini ([EMAIL PROTECTED]) wrote:
> >- Open Your Mind -<
>
>Quoting from Brian Hawley's message (08-Jul-00 01:31:18).
>
>b> This either means resorting the list after every
>b> insert, using an incremental insertion sort, or making
>b> sure the data is inserted in order.
>
>Hmmm. :->
>You mean something like this invented example?
>
> >> probe data
> == [15 98 60 52 10 2]
>
> >> insert/sorted/compare data 15 :method
> == [98 60 52 15 10 2]
I mentioned three methods. Since we were talking about
working with key/value pairs...
table: [1 "1" 2 "2" 5 "5"]
key: 4 value: "4"
Resorting the list after every insert:
>> sort/skip append table reduce [key value] 2
Hey, at least the sort is in native code. Depending
on the method, it could be optimal when the table
is already mostly sorted (read: Not quicksort).
Incremental insertion sort (linear search):
>> while [
any [(tail? table) (key >= first table)]
] [table: skip table 2]
table: head insert table reduce [key value]
Binary search would be faster for large tables, but
it's a little more complicated.
Making sure the input is sorted in the first place:
(sort input here)
>> append table reduce [key value]
Doesn't work very well when you can't sort the input
in the first place.
Does that help?
Brian Hawley