Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Commit

Permalink
Vector tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed Nov 18, 2016
1 parent bf60b15 commit 20da193
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class Vector {
let e = 0;

for (let j = 0; j < n; j++) {
e |= (cs[i + j] ? 1 : 0) << n - j - 1;
e |= (cs[i + j] ? 1 : 0) << (n - j - 1);
}

c[c.length] = e;
Expand Down Expand Up @@ -81,7 +81,7 @@ export default class Vector {
let b = 7;

for (let i = 0, n = c.length; i < n; i++) {
b ^= 31 * b + c[i] + (b << 6) + (b >> 2);
b ^= (31 * b) + c[i] + (b << 6) + (b >> 2);
}

return b ^ (b >> 32);
Expand All @@ -94,7 +94,19 @@ export default class Vector {
* @return {boolean} `true` if the vectors are equal, otherwise `false`.
*/
equals(v) {
return Vector.distance(this, v) === 0;
if (this.l !== v.l) {
return false;
}

const c = this.c;

for (let i = 0, n = c.length; i < n; i++) {
if (c[i] !== v.c[i]) {
return false;
}
}

return true;
}

/**
Expand Down Expand Up @@ -142,7 +154,7 @@ export default class Vector {
* @return {Vector}
*/
static random(l) {
const c = Array(l);
const c = new Array(l);

for (let i = 0; i < l; i++) {
c[i] = (Math.random() + 0.5) | 0;
Expand Down

0 comments on commit 20da193

Please sign in to comment.