[racket] Implementing an equal? method for a class

From: Neil Toronto (neil.toronto at gmail.com)
Date: Sun Jul 29 19:31:20 EDT 2012

On 07/29/2012 04:19 PM, Danny Yoo wrote:
> On Sun, Jul 29, 2012 at 6:07 PM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>>
>> For 81 slots, I'd actually use a (define b (make-vector 81 0)) instead and use an access polynomial. I am almost certain that it is faster.

Probably so. It allocates less and has better cache behavior when 
accessing elements in row-major order.

> I'm unfamiliar with the term 'access polynomial'.  Would it be
> accurate to say that it's a function f:
>
>     f: (number number -> number)
>
> such as
>
>      (define COLUMN-LENGTH 9)
>      (define (f row col) (+ (* row COLUMN-LENGTH) col))
>
> allows us to treat the flat vector as if it were a two-dimensional
> structure, by translating (row,col) into offsets?

That's it. I've never heard it called an "access polynomial" before, 
though that's exactly what it is.

When I merge the `math' collection for 5.4, such decisions will mostly 
be moot. It has an Array type, which does that for you in any number of 
dimensions.

Neil ⊥


Posted on the users mailing list.