[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ucar.multiarry.IntMap tail() method



> Pardon my mental block, but I've read over the material at:
>
> >
> > http://www.unidata.ucar.edu/packages/netcdf/java/docs/
> >     Package-ucar.multiarray.html
>
> and don't understand the purpose of the IntMap class' tail() method.
> This seems to imply a particular implementation (a chain?).  And that
> makes me think I really missed something.

Tom:

This is a good question, so I'm forwarding the answer to some
other folks in a pro-active attempt at education.

Users should never need to call tail() directly. EG, it maybe it should
be package private, not public.

You are correct in observing that the IntMap interface is less abstract
than the name and top level documentation imply.
The implementations need to work together in certain ways
and work in the MultiArrayProxy framework. Every IntMap inplementation that
works in this framework needs needs the tail() method.
Since IntMap is an interface and other may want to implement instances,
outside of this framework, the method ends up being public.

Each of the concrete IntMap implementations have a constructor
which takes another IntMap as an argument. This allows functional
composition of the form f(g(i)) in a mathematical sense.
The constructor which doesn't use this argument also forms
a functional composition behind the scenes, using an instance of
IntArrayAdapter. IntArrayAdapter converts int [], which is what the
users are used to  seeing (the index arg of a MultiArrayProxy)
into an IntMap.

The functional composition is implemented as an doubly linked list.
It is a what is referred to as an "internal" linked list, because the elements
of the list (instances if IntMap) have the 'next' and 'prev' fields in them,
as opposed to more flexible external linked lists which can contain
arbitrary objects. It turns out there are good reasons for using
an internal linked list here. The main one is that it hides complexity
from the ultimate user, folks who are constructing instances of
MultiArrayProxy.

> I wonder
> if you have a simple example, perhaps of a MultiArrayProxy that uses
> one of the implementors of IntMap?

If you look at the source,
each of the concrete IntMap implementations has a main() that
does this. MultiArrayProxy has a main() that uses chains several
IntMap's and forms a Proxy.

-glenn