more jslinting

This commit is contained in:
Danny Yoo 2011-08-07 23:46:20 -04:00
parent 40c8d6b0aa
commit 2be2c72754
2 changed files with 95 additions and 102 deletions

View File

@ -1,5 +1,10 @@
/*jslint unparam: true, vars: true, white: true, newcap: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */
(function(baselib) { /*global Hashtable*/
(function (baselib) {
'use strict';
var exports = {}; var exports = {};
baselib.hashes = exports; baselib.hashes = exports;
@ -7,28 +12,28 @@
var _eqHashCodeCounter = 0; var _eqHashCodeCounter = 0;
var makeEqHashCode = function() { var makeEqHashCode = function () {
_eqHashCodeCounter++; _eqHashCodeCounter++;
return _eqHashCodeCounter; return _eqHashCodeCounter;
}; };
// getHashCode: any -> (or fixnum string) // getHashCode: any -> (or fixnum string)
// Given a value, produces a hashcode appropriate for eq. // Given a value, produces a hashcode appropriate for eq.
var getEqHashCode = function(x) { var getEqHashCode = function (x) {
if (typeof(x) === 'string') { if (typeof (x) === 'string') {
return x; return x;
} }
if (typeof(x) === 'number') { if (typeof (x) === 'number') {
return String(x); return String(x);
} }
if (x && !x._eqHashCode) { if (x && !x._eqHashCode) {
x._eqHashCode = makeEqHashCode(); x._eqHashCode = makeEqHashCode();
} }
if (x && x._eqHashCode) { if (x && x._eqHashCode) {
return x._eqHashCode; return x._eqHashCode;
} }
return 0; return 0;
}; };
@ -36,9 +41,9 @@
// http://www.timdown.co.uk/jshashtable/ // http://www.timdown.co.uk/jshashtable/
// //
// Defined to use the getEqHashCode defined in baselib_hash.js. // Defined to use the getEqHashCode defined in baselib_hash.js.
var makeLowLevelEqHash = function() { var makeLowLevelEqHash = function () {
return new Hashtable(function(x) { return getEqHashCode(x); }, return new Hashtable(function (x) { return getEqHashCode(x); },
function(x, y) { return x === y; }); function (x, y) { return x === y; });
}; };
@ -52,51 +57,51 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Eq Hashtables // Eq Hashtables
var EqHashTable = function(inputHash) { var EqHashTable = function (inputHash) {
this.hash = makeLowLevelEqHash(); this.hash = makeLowLevelEqHash();
this.mutable = true; this.mutable = true;
}; };
EqHashTable.prototype.toWrittenString = function(cache) { EqHashTable.prototype.toWrittenString = function (cache) {
var keys = this.hash.keys(); var keys = this.hash.keys();
var ret = []; var ret = [], i;
for (var i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
var keyStr = toWrittenString(keys[i], cache); var keyStr = baselib.format.toWrittenString(keys[i], cache);
var valStr = toWrittenString(this.hash.get(keys[i]), cache); var valStr = baselib.format.toWrittenString(this.hash.get(keys[i]), cache);
ret.push('(' + keyStr + ' . ' + valStr + ')'); ret.push('(' + keyStr + ' . ' + valStr + ')');
} }
return ('#hasheq(' + ret.join(' ') + ')'); return ('#hasheq(' + ret.join(' ') + ')');
}; };
EqHashTable.prototype.toDisplayedString = function(cache) { EqHashTable.prototype.toDisplayedString = function (cache) {
var keys = this.hash.keys(); var keys = this.hash.keys();
var ret = []; var ret = [], i;
for (var i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
var keyStr = toDisplayedString(keys[i], cache); var keyStr = baselib.format.toDisplayedString(keys[i], cache);
var valStr = toDisplayedString(this.hash.get(keys[i]), cache); var valStr = baselib.format.toDisplayedString(this.hash.get(keys[i]), cache);
ret.push('(' + keyStr + ' . ' + valStr + ')'); ret.push('(' + keyStr + ' . ' + valStr + ')');
} }
return ('#hasheq(' + ret.join(' ') + ')'); return ('#hasheq(' + ret.join(' ') + ')');
}; };
EqHashTable.prototype.equals = function(other, aUnionFind) { EqHashTable.prototype.equals = function (other, aUnionFind) {
if ( !(other instanceof EqHashTable) ) { if (!(other instanceof EqHashTable)) {
return false; return false;
} }
if (this.hash.keys().length != other.hash.keys().length) { if (this.hash.keys().length !== other.hash.keys().length) {
return false; return false;
} }
var keys = this.hash.keys(); var keys = this.hash.keys(), i;
for (var i = 0; i < keys.length; i++){ for (i = 0; i < keys.length; i++) {
if ( !(other.hash.containsKey(keys[i]) && if (!(other.hash.containsKey(keys[i]) &&
plt.baselib.equality.equals(this.hash.get(keys[i]), baselib.equality.equals(this.hash.get(keys[i]),
other.hash.get(keys[i]), other.hash.get(keys[i]),
aUnionFind)) ) { aUnionFind))) {
return false; return false;
} }
} }
return true; return true;
}; };
@ -105,55 +110,55 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Equal hash tables // Equal hash tables
var EqualHashTable = function(inputHash) { var EqualHashTable = function (inputHash) {
this.hash = new _Hashtable( this.hash = new Hashtable(
function(x) { function (x) {
return plt.baselib.format.toWrittenString(x); return baselib.format.toWrittenString(x);
}, },
function(x, y) { function (x, y) {
return plt.baselib.equality.equals(x, y, new plt.baselib.UnionFind()); return baselib.equality.equals(x, y, new baselib.UnionFind());
}); });
this.mutable = true; this.mutable = true;
}; };
EqualHashTable.prototype.toWrittenString = function(cache) { EqualHashTable.prototype.toWrittenString = function (cache) {
var keys = this.hash.keys(); var keys = this.hash.keys();
var ret = []; var ret = [], i;
for (var i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
var keyStr = plt.baselib.format.toWrittenString(keys[i], cache); var keyStr = baselib.format.toWrittenString(keys[i], cache);
var valStr = plt.baselib.format.toWrittenString(this.hash.get(keys[i]), cache); var valStr = baselib.format.toWrittenString(this.hash.get(keys[i]), cache);
ret.push('(' + keyStr + ' . ' + valStr + ')'); ret.push('(' + keyStr + ' . ' + valStr + ')');
} }
return ('#hash(' + ret.join(' ') + ')'); return ('#hash(' + ret.join(' ') + ')');
}; };
EqualHashTable.prototype.toDisplayedString = function(cache) { EqualHashTable.prototype.toDisplayedString = function (cache) {
var keys = this.hash.keys(); var keys = this.hash.keys();
var ret = []; var ret = [], i;
for (var i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
var keyStr = plt.baselib.format.toDisplayedString(keys[i], cache); var keyStr = baselib.format.toDisplayedString(keys[i], cache);
var valStr = plt.baselib.format.toDisplayedString(this.hash.get(keys[i]), cache); var valStr = baselib.format.toDisplayedString(this.hash.get(keys[i]), cache);
ret.push('(' + keyStr + ' . ' + valStr + ')'); ret.push('(' + keyStr + ' . ' + valStr + ')');
} }
return ('#hash(' + ret.join(' ') + ')'); return ('#hash(' + ret.join(' ') + ')');
}; };
EqualHashTable.prototype.equals = function(other, aUnionFind) { EqualHashTable.prototype.equals = function (other, aUnionFind) {
if ( !(other instanceof EqualHashTable) ) { if ( !(other instanceof EqualHashTable) ) {
return false; return false;
} }
if (this.hash.keys().length != other.hash.keys().length) { if (this.hash.keys().length !== other.hash.keys().length) {
return false; return false;
} }
var keys = this.hash.keys(); var keys = this.hash.keys(), i;
for (var i = 0; i < keys.length; i++){ for (i = 0; i < keys.length; i++){
if (! (other.hash.containsKey(keys[i]) && if (! (other.hash.containsKey(keys[i]) &&
plt.baselib.equality.equals(this.hash.get(keys[i]), baselib.equality.equals(this.hash.get(keys[i]),
other.hash.get(keys[i]), other.hash.get(keys[i]),
aUnionFind))) { aUnionFind))) {
return false; return false;
} }
} }
return true; return true;
}; };
@ -161,27 +166,12 @@
var isHash = function(x) { var isHash = function (x) {
return (x instanceof EqHashTable || return (x instanceof EqHashTable ||
x instanceof EqualHashTable); x instanceof EqualHashTable);
}; };
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
exports.getEqHashCode = getEqHashCode; exports.getEqHashCode = getEqHashCode;
@ -194,4 +184,4 @@
exports.isHash = isHash; exports.isHash = isHash;
})(this['plt'].baselib); }(this.plt.baselib));

View File

@ -1,15 +1,18 @@
/*jslint vars: true, maxerr: 50, indent: 4 */
// Structure types // Structure types
(function(baselib) { (function (baselib) {
'use strict';
var exports = {}; var exports = {};
baselib.inspectors = exports; baselib.inspectors = exports;
var Inspector = function() { var Inspector = function () {
}; };
var DEFAULT_INSPECTOR = new Inspector(); var DEFAULT_INSPECTOR = new Inspector();
Inspector.prototype.toString = function() { Inspector.prototype.toString = function () {
return "#<inspector>"; return "#<inspector>";
}; };
@ -23,4 +26,4 @@
exports.isInspector = isInspector; exports.isInspector = isInspector;
})(this['plt'].baselib); }(this.plt.baselib));