Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10 from joshuahhh/master
Browse files Browse the repository at this point in the history
Removed 'compare' functions and other unnecessary bits
  • Loading branch information
IjzerenHein authored Feb 22, 2019
2 parents e12a41f + 4b427b1 commit de28399
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 70 deletions.
46 changes: 13 additions & 33 deletions lib/kiwi.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
|
| The full license is in the file COPYING.txt, distributed with this software.
|----------------------------------------------------------------------------*/
function createMap(compare) {
function createMap() {
return new IndexedMap();
}
var IndexedMap = /** @class */ (function () {
Expand Down Expand Up @@ -221,13 +221,6 @@
this._id = VarId++;
this._name = name;
}
/**
* A static variable comparison function.
* @private
*/
Variable.Compare = function (a, b) {
return a.id() - b.id();
};
/**
* Returns the unique id number of the variable.
* @private
Expand Down Expand Up @@ -439,7 +432,7 @@
return this._terms.size() == 0;
};
Expression.prototype.toString = function () {
var result = this._terms.array.map(function (pair, idx) {
var result = this._terms.array.map(function (pair) {
return (pair.second + "*" + pair.first.toString());
}).join(" + ");
if (!this.isConstant() && this._constant !== 0) {
Expand All @@ -457,7 +450,7 @@
function parseArgs(args) {
var constant = 0.0;
var factory = function () { return 0.0; };
var terms = createMap(Variable.Compare);
var terms = createMap();
for (var i = 0, n = args.length; i < n; ++i) {
var item = args[i];
if (typeof item === "number") {
Expand Down Expand Up @@ -521,11 +514,11 @@
/**
* Create a new symbolic strength.
*
* @param {Number} a strong
* @param {Number} b medium
* @param {Number} c weak
* @param {Number} [w] weight
* @return {Number} strength
* @param a strong
* @param b medium
* @param c weak
* @param [w] weight
* @return strength
*/
Strength.create = function (a, b, c, w) {
if (w === void 0) { w = 1.0; }
Expand Down Expand Up @@ -598,13 +591,6 @@
this._expression = expression.minus(rhs);
}
}
/**
* A static constraint comparison function.
* @private
*/
Constraint.Compare = function (a, b) {
return a.id() - b.id();
};
/**
* Returns the unique id number of the constraint.
* @private
Expand Down Expand Up @@ -1351,28 +1337,28 @@
* @private
*/
function createCnMap() {
return createMap(Constraint.Compare);
return createMap();
}
/**
* An internal function for creating a row map.
* @private
*/
function createRowMap() {
return createMap(Symbol.Compare);
return createMap();
}
/**
* An internal function for creating a variable map.
* @private
*/
function createVarMap() {
return createMap(Variable.Compare);
return createMap();
}
/**
* An internal function for creating an edit map.
* @private
*/
function createEditMap() {
return createMap(Variable.Compare);
return createMap();
}
/**
* An enum defining the available symbol types.
Expand Down Expand Up @@ -1401,12 +1387,6 @@
this._id = id;
this._type = type;
}
/**
* The static Symbol comparison function.
*/
Symbol.Compare = function (a, b) {
return a.id() - b.id();
};
/**
* Returns the unique id number of the symbol.
*/
Expand Down Expand Up @@ -1436,7 +1416,7 @@
*/
function Row(constant) {
if (constant === void 0) { constant = 0.0; }
this._cellMap = createMap(Symbol.Compare);
this._cellMap = createMap();
this._constant = constant;
}
/**
Expand Down
10 changes: 1 addition & 9 deletions src/constraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ class Constraint {
}
}

/**
* A static constraint comparison function.
* @private
*/
public static Compare( a: Constraint, b: Constraint ): number {
return a.id() - b.id();
}

/**
* Returns the unique id number of the constraint.
* @private
Expand Down Expand Up @@ -113,4 +105,4 @@ class Constraint {
* The internal constraint id counter.
* @private
*/
let CnId = 0;
let CnId = 0;
4 changes: 2 additions & 2 deletions src/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Expression {
}

public toString(): string {
let result = this._terms.array.map(function(pair, idx) {
let result = this._terms.array.map(function(pair) {
return (pair.second + "*" + pair.first.toString());
}).join(" + ");

Expand Down Expand Up @@ -145,7 +145,7 @@ interface IParseResult {
function parseArgs( args: IArguments ): IParseResult {
let constant = 0.0;
let factory = () => 0.0;
let terms = createMap<Variable, number>( Variable.Compare );
let terms = createMap<Variable, number>();
for ( let i = 0, n = args.length; i < n; ++i ) {
let item = args[ i ];
if ( typeof item === "number" ) {
Expand Down
2 changes: 1 addition & 1 deletion src/maptype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
export interface IMap<T extends { id(): number }, U> extends IndexedMap<T, U> { }

export
function createMap<T extends { id(): number }, U>( compare: any ): IMap<T, U> {
function createMap<T extends { id(): number }, U>(): IMap<T, U> {
return new IndexedMap<T, U>();
}

Expand Down
17 changes: 5 additions & 12 deletions src/solver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,31 +773,31 @@ interface IRowCreation {
* @private
*/
function createCnMap(): IMap<Constraint, ITag> {
return createMap<Constraint, ITag>( Constraint.Compare );
return createMap<Constraint, ITag>();
}

/**
* An internal function for creating a row map.
* @private
*/
function createRowMap(): IMap<Symbol, Row> {
return createMap<Symbol, Row>( Symbol.Compare );
return createMap<Symbol, Row>();
}

/**
* An internal function for creating a variable map.
* @private
*/
function createVarMap(): IMap<Variable, Symbol> {
return createMap<Variable, Symbol>( Variable.Compare );
return createMap<Variable, Symbol>();
}

/**
* An internal function for creating an edit map.
* @private
*/
function createEditMap(): IMap<Variable, IEditInfo> {
return createMap<Variable, IEditInfo>( Variable.Compare );
return createMap<Variable, IEditInfo>();
}

/**
Expand All @@ -817,13 +817,6 @@ enum SymbolType {
* @private
*/
class Symbol {
/**
* The static Symbol comparison function.
*/
public static Compare( a: Symbol, b: Symbol ): number {
return a.id() - b.id();
}

/**
* Construct a new Symbol
*
Expand Down Expand Up @@ -1037,6 +1030,6 @@ class Row {
}
}

private _cellMap = createMap<Symbol, number>( Symbol.Compare );
private _cellMap = createMap<Symbol, number>();
private _constant: number;
}
10 changes: 5 additions & 5 deletions src/strength.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
/**
* Create a new symbolic strength.
*
* @param {Number} a strong
* @param {Number} b medium
* @param {Number} c weak
* @param {Number} [w] weight
* @return {Number} strength
* @param a strong
* @param b medium
* @param c weak
* @param [w] weight
* @return strength
*/
static create( a: number, b: number, c: number, w: number = 1.0 ) {
let result: number = 0.0;
Expand Down
8 changes: 0 additions & 8 deletions src/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ class Variable {
this._name = name;
}

/**
* A static variable comparison function.
* @private
*/
public static Compare( a: Variable, b: Variable ): number {
return a.id() - b.id();
}

/**
* Returns the unique id number of the variable.
* @private
Expand Down

0 comments on commit de28399

Please sign in to comment.