Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/NesTiler.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-10-27 22:57:24 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-10-27 22:57:24 +0300
commitc4cb1535c87ea2d44e61716af8058e769271b65e (patch)
tree68bfbee6d4f1d2057e4d54f6bceb83299dc20fe5 /NesTiler
parent37d459ac45432f546ec998a01c0d0c425a24947d (diff)
New hash function.
Diffstat (limited to 'NesTiler')
-rw-r--r--NesTiler/Palette.cs21
-rw-r--r--NesTiler/Tile.cs5
2 files changed, 16 insertions, 10 deletions
diff --git a/NesTiler/Palette.cs b/NesTiler/Palette.cs
index 44cb940..2f6ddf6 100644
--- a/NesTiler/Palette.cs
+++ b/NesTiler/Palette.cs
@@ -112,6 +112,20 @@ namespace com.clusterrr.Famicom.NesTiler
.Select(c => c!.Value)
.ToArray();
return Enumerable.SequenceEqual(colors1, colors2);
+ /*
+ if (other == null) return false;
+ var colors1 = colors.Where(c => c.HasValue)
+ .Select(c => c!.Value.ToArgb())
+ .OrderBy(c => c)
+ .ToArray();
+ var colors2 = new SKColor?[] { other[1], other[2], other[3] }
+ .Where(c => c.HasValue)
+ .Select(c => c!.Value.ToArgb())
+ .OrderBy(c => c)
+ .ToArray();
+ var r = Enumerable.SequenceEqual(colors1, colors2);
+ return r;
+ */
}
public bool Contains(Palette other)
@@ -139,11 +153,6 @@ namespace com.clusterrr.Famicom.NesTiler
public override string ToString() => string.Join(", ", colors.Where(c => c.HasValue).Select(c => ColorTranslator.ToHtml(c!.Value.ToColor())).OrderBy(c => c));
- public override int GetHashCode()
- {
- return ((this[1]?.Red ?? 0) + (this[2]?.Red ?? 0) + (this[3]?.Red ?? 0))
- | (((this[1]?.Green ?? 0) + (this[2]?.Green ?? 0) + (this[3]?.Green ?? 0)) << 10)
- | (((this[1]?.Blue ?? 0) + (this[2]?.Blue ?? 0) + (this[3]?.Blue ?? 0)) << 20);
- }
+ public override int GetHashCode() => (int)((this[1]?.ToArgb() ?? 0) + ((this[2]?.ToArgb() ?? 0) << 4) + ((this[3]?.ToArgb() ?? 0) << 8));
}
}
diff --git a/NesTiler/Tile.cs b/NesTiler/Tile.cs
index 57aca75..98739c0 100644
--- a/NesTiler/Tile.cs
+++ b/NesTiler/Tile.cs
@@ -9,7 +9,6 @@ namespace com.clusterrr.Famicom.NesTiler
public readonly byte[] Pixels;
public const int Width = 8;
public readonly int Height;
- private int? hash;
private byte[]? data = null;
public Tile(byte[] data, int height)
@@ -52,12 +51,10 @@ namespace com.clusterrr.Famicom.NesTiler
public override int GetHashCode()
{
- if (hash != null) return hash.Value;
var crc = new Crc32();
crc.Append(GetAsPatternData());
var hashBytes = crc.GetCurrentHash();
- hash = BitConverter.ToInt32(hashBytes, 0);
- return hash.Value;
+ return BitConverter.ToInt32(hashBytes, 0);
}
}
}