constucting a lookup table

Scott David Daniels scott.daniels at acm.org
Wed May 17 23:28:34 CEST 2006


mhodkin at comcast.net wrote:
> BTW, just for kicks to compare languages, how would one implement the
> same "lookup" table using C/C++?  It would be a good lesson in high
> level vs. lower level programming....
> 
Something vaguely like:

unsigned char hwdict[89 - 60][401 - 80];

int
setsize(int height, int weight, int size)
{
     int result; /* non-zero (old size) if changes an already set size */

     assert(60 <= height && height<= 88 && 80 <= weight && weight<= 400);
     result = hwdict[height - 60][weight - 80];
     hwdict[height - 60][weight - 80] = size;
     return result;
}

int
getsize(int height, int weight, int size)
{
     assert(60 <= height && height<= 88 && 80 <= weight && weight<= 400);
     return hwdict[height - 60][weight - 80];
}

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list