Replace hashCode with checksum
Hash codes are not collision free, so what we actually need is a checksum.
This commit is contained in:
@@ -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_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user