Replace hashCode with checksum

Hash codes are not collision free, so what we
actually need is a checksum.
This commit is contained in:
tsauerwein
2014-11-06 15:08:34 +01:00
parent 581b372c6a
commit 509fbaee1c
6 changed files with 154 additions and 62 deletions
+15 -9
View File
@@ -1,8 +1,7 @@
goog.provide('ol.style.Fill');
goog.require('goog.string');
goog.require('ol.color');
goog.require('ol.structs.IHashable');
goog.require('ol.structs.IHasChecksum');
@@ -12,7 +11,7 @@ goog.require('ol.structs.IHashable');
*
* @constructor
* @param {olx.style.FillOptions=} opt_options Options.
* @implements {ol.structs.IHashable}
* @implements {ol.structs.IHasChecksum}
* @api
*/
ol.style.Fill = function(opt_options) {
@@ -24,6 +23,12 @@ ol.style.Fill = function(opt_options) {
* @type {ol.Color|string}
*/
this.color_ = goog.isDef(options.color) ? options.color : null;
/**
* @private
* @type {?ol.structs.Checksum}
*/
this.checksum_ = null;
};
@@ -44,17 +49,18 @@ ol.style.Fill.prototype.getColor = function() {
*/
ol.style.Fill.prototype.setColor = function(color) {
this.color_ = color;
this.checksum_ = null;
};
/**
* @inheritDoc
*/
ol.style.Fill.prototype.hashCode = function() {
var hash = 17;
ol.style.Fill.prototype.getChecksum = function() {
if (goog.isNull(this.checksum_)) {
this.checksum_ = 'f' + (!goog.isNull(this.color_) ?
ol.color.asString(this.color_) : '-');
}
hash = hash * 23 + (!goog.isNull(this.color_) ?
goog.string.hashCode(ol.color.asString(this.color_)) : 0);
return hash;
return this.checksum_;
};