Created
June 17, 2015 16:28
-
-
Save arturaz/07f5969a7114231b3b82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Fast, allocation free equality comparer for blittable structs with an underlying size of 64 bits or less. | |
/// </summary> | |
public class Blittable64EqComparer<T> : Smooth.Collections.EqComparer<T> { | |
public override bool Equals(T t1, T t2) { | |
Converter converter; | |
converter.value = 0; | |
converter.t = t1; | |
var v1 = converter.value; | |
converter.t = t2; | |
return v1 == converter.value; | |
} | |
public override int GetHashCode(T t) { | |
Converter converter; | |
converter.value = 0; | |
converter.t = t; | |
return converter.value.GetHashCode(); | |
} | |
[StructLayout(LayoutKind.Explicit)] | |
internal struct Converter | |
{ | |
[FieldOffset(0)] | |
public T t; | |
[FieldOffset(0)] | |
public Int64 value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment