Good point. I'll use this version. Hmmm... maybe I should add a unit test
for skip as well...
-Amit
On 10/4/05, Brian Hurt <bh...@sp...> wrote:
>
>
>
> On Tue, 4 Oct 2005, Amit Dubey wrote:
>
> > Looking at Dllist.skip, this looks like a bug. A better implementation
> of
> > skip might be:
> >
> > let skip node idx =3D
> > let rec loop idx n =3D
> > if idx =3D=3D 0 then
> > n
> > else if idx>0 then
> > loop (idx -1) n.next
> > else
> > loop (idx + 1) n.prev
> > in
> > loop idx node
> >
> > (The current version doesn't use n.prev for negative arguments). If
> there
> > are no complains, I'll make this change.
>
> I'm wondering if it might not be better to split the two loops, to avoid
> taking repeated branchs:
>
> let skip node idx =3D
> let rec floop idx n =3D
> if idx =3D=3D 0 then
> n
> else
> floop (idx-1) n.next
> in
> let rec bloop idx n =3D
> if idx =3D=3D 0 then
> n
> else
> bloop (idx-1) n.prev
> in
> if idx =3D=3D 0 then
> n
> else if idx > 0 then
> floop (idx-1) n.next
> else
> bloop ((-idx)-1) n.prev
> ;;
>
> Brian
>
>
|