Permalink
Browse files

hashPair ignores order of arguments

  • Loading branch information...
1 parent 6d57c6c commit 4bce8024d935940dca84861a845df539ded9c4ee @josephg committed Oct 23, 2012
Showing with 35 additions and 15 deletions.
  1. +16 −6 cp.js
  2. +2 −2 cp.min.js
  3. +17 −7 lib/chipmunk.js
View
@@ -56,12 +56,6 @@ var assertSoft = function(value, message)
}
};
-var hashPair = function(a, b)
-{
-// assert(typeof(a) === 'string' || typeof(a) === 'number', "HashPair used on something not a string or a number");
- return a + ' ' + b;
-};
-
var mymin = function(a, b)
{
return a < b ? a : b;
@@ -84,6 +78,22 @@ if (typeof window === 'object' && window.navigator.userAgent.indexOf('Firefox')
max = mymax;
}
+/* The hashpair function takes two numbers and returns a hash code for them.
+ * Required that hashPair(a, b) === hashPair(b, a).
+ * Chipmunk's hashPair function is defined as:
+ * #define CP_HASH_COEF (3344921057ul)
+ * #define CP_HASH_PAIR(A, B) ((cpHashValue)(A)*CP_HASH_COEF ^ (cpHashValue)(B)*CP_HASH_COEF)
+ * But thats not suitable in javascript because multiplying by a large number will make the number
+ * a large float.
+ *
+ * The result of hashPair is used as the key in objects, so it returns a string.
+ */
+var hashPair = function(a, b)
+{
+ //assert(typeof(a) === 'number', "HashPair used on something not a number");
+ return a < b ? a + ' ' + b : b + ' ' + a;
+};
+
var deleteObjFromList = function(arr, obj)
{
for(var i=0; i<arr.length; i++){
Oops, something went wrong.

0 comments on commit 4bce802

Please sign in to comment.