Re: Adding functions to generic package



On 2005-05-29, Matthew Heaney <matthewjheaney@xxxxxxxxxxxxx> wrote:
> Preben Randhol <randhol+valid_for_reply_from_news@xxxxxxx> writes:
>
>> On 2005-05-28, Matthew Heaney <matthewjheaney@xxxxxxxxxxxxx> wrote:
>> > What do Randomize and Move do? If you have a tentative implementation,
>> > then post it (or just mail it to me) and we can figure what is the best
>> > option for you.
>>
>> It should be called Randomize_Container and be equivelent to the
>> Reverse_Container procedure except that it makes the order of the
>> elements random. I guess this doesn't seem to make sense for a List,
>> but I need it for a program that is asking questions from a list.
>
>
>
>
>
>> What Move does it to move element number 2 to number 4.
>
> How is that different from Splice?

I see now. By glancing at the procedure name I thought Splice meant that
one joined say two containers (as I read the first Splice and then
skipped the rest). Didn't think it was moving an element. I
didn't read the adb file for documentation. I'll have a look now and
change the code.

> This is going to be way too expensive, since Move is implemented in
> terms of integer indexes. You definitely want to implement Randomize in
> terms of iterators, not indexes.

Yes I can agree with you on that. And since I can use Splice I don't need
to make a new Move. I think I'm also going to make a Find where Position
is Natural in stead of Iterator_Type.

> Get_Random_Iterator returns an iterator (J) in the range [I, Back):

Not sure I understand this. Wouldn't this mean that the randomisation
only will be able to put element further back in the list?

> This should perform much better than the algorithm you posted.

Yes I'll have a look and replace my quick and dirty procedure.

Preben
.