In my application I using SKPoinI as a key to store some small objects in Dictionary. SkiaSharp already used in this project for drawing and not need to be referred to only to allow SKPointI to be used as a key.
At first look, it's a good and simple solution, but I not sure because as I presume that the SkiaSharp library primarily optimized for graphics.
Maybe better create a structure that has two Int32 as coordinates and implementation of IEqitable, or create combined Int64 via BitConverter to be used as the key
key = BitConverter.ToInt64(BitConverter.GetBytes(x).Concat(BitConverter.GetBytes(y)).ToArray)
and get x and y from a key with code like:
With BitConverter.GetBytes(key)
x = BitConverter.ToInt32(.Take(4).ToArray)
y = BitConverter.ToInt32(.Skip(4).ToArray)
End With
What way is better if the application will add objects only once on the initial stage and then accesses them frequently?
I already using the key for 3D-storage:
Public Structure Adr3D
Implements IEquatable(Of Adr3D)
#Region "Public Constructors"
Public Sub New(x As Integer, y As Integer, z As Integer)
Me.X = x
Me.Y = y
Me.Z = z
End Sub
#End Region
#Region "Public Properties"
Public ReadOnly Property X As Integer
Public ReadOnly Property Y As Integer
Public ReadOnly Property Z As Integer
#End Region
#Region "Public Methods"
Public Shared Operator <>(left As Adr3D, right As Adr3D) As Boolean
Return Not left.Equals(right)
End Operator
Public Shared Operator =(left As Adr3D, right As Adr3D) As Boolean
Return left.Equals(right)
End Operator
Public Overrides Function Equals(obj As Object) As Boolean
Return TypeOf obj Is Adr3D AndAlso Equals(DirectCast(obj, Adr3D))
End Function
Public Overloads Function Equals(other As Adr3D) As Boolean Implements IEquatable(Of Adr3D).Equals
Return X = other.X AndAlso Y = other.Y AndAlso Z = other.Z
End Function
Public Overrides Function GetHashCode() As Integer
Return HashCode.Combine(X, Y, Z)
End Function
Public Overrides Function ToString() As String
Return $"{{X = {X}, Y = {Y}, Z = {Z}}}"
End Function
#End Region
End Structure
In fact, it is not a question of "How to implement?", but "What is more efficient?"
Thanks for any advice!