[Mono-list] System.Drawing.Drawing2D

Lloyd Dupont lloyd@galador.net
Sat, 25 Aug 2001 01:54:50 +0200


> > why not something like
> > public unsafe override int GetHashCode()
> > {
> > fixed(float * fp = m) {
> > int * ip = (int *) fp;
> > return ip[0] ^ ip[1] ^ ip[2] ^ ip[3];
> > }
> > }
> 
> I think we should avoid unsafe code blocks in the Mono libraries.

though your argument is good i think my way is better, as a lot of real
matrix and different matrix could return same hashcode with a hash like
(int)(m0*m1*m2*m3).
so let me think.....

why not something like this : ? (which is safe)
-------------------------------------------
// at the top
using System.Runtime.InteropServices;

// in your class
    [StructLayout(LayoutKind.Explicit)]
    internal struct BitConverter {
	[FieldOffset(0)] public float f;
	[FieldOffset(0)] public int i;
    }
    public override int GetHashCode()
    {
        BitConverter b;
        // compiler is not smart
        b.i = 0;
        int h=0;
        for(int i=0; i<4; i++) {
            b.f = m[i];
            h ^= m.i;
	}
        return h;
    }