Orthogonal Arrays

BCS ao at pathlink.com
Mon Nov 3 19:37:14 PST 2008


Reply to bmeck,

> I've been wondering how other people deal with this. Arrays that are
> distinct and separate but related. I've heard people say why aren't
> you using a structure of some kind, but in reality sometimes this is
> just not practical to restructure lots and lots of data and the way to
> get to data can be messy. For example, images can have multiple color
> planes (essentially a color plane can be considered a nth dimensional
> array which is generally byte[][3] for 256 colors with 1 byte each
> representing a pixel), because of having multiple of these planes is
> possible it could take a lot of moving to make a structure out of
> every color plane's pixel array and combine it will all the others.
> 
> I was hoping someone out there could point me at a way to treat
> multiple orthogonal arrays as a single structure (ie. if you have 2
> arrays $A with [name] and $B [with r,b,and g] members you could do $X
> = orthogonal!(A,B) then use X[i].name and also X[i].r) without
> restructuring things in memory.
> 

struct Orth(T...)
{
    T[] t; // uses some template to make a tuple of arrays

    cell opIndex(int i)
    {
       return cell(this, i);
    }
    struct cell
    {
        Orth!(T)* base;
        int i;
        mixin(BodyOf!(T)) ;// extract memebers of T's and build accessors.
    }
}





More information about the Digitalmars-d mailing list