Skip to content

Commit 35ccf12

Browse files
committed
Add hashCode function to SimpleBitmap for creating hash of pixel image data
1 parent b4cb845 commit 35ccf12

File tree

1 file changed

+12
-0
lines changed
  • korge-gradle-plugin/src/main/kotlin/korlibs/korge/gradle/texpacker

1 file changed

+12
-0
lines changed

korge-gradle-plugin/src/main/kotlin/korlibs/korge/gradle/texpacker/SimpleBitmap.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,16 @@ class SimpleBitmap(val width: Int, val height: Int, val data: IntArray = IntArra
139139
}
140140
return out
141141
}
142+
143+
/**
144+
* Get hash code of SimpleBitmap object based on its pixel data.
145+
*/
146+
override fun hashCode(): Int {
147+
// Using two prime numbers (17, 31) here for hash code calculation in order to distribute hash codes uniformly and reduce collisions
148+
var hash = 17
149+
for (pixel in data) {
150+
hash = hash * 31 + pixel
151+
}
152+
return hash
153+
}
142154
}

0 commit comments

Comments
 (0)