|
|
|
@ -11,6 +11,19 @@ function checkValueEquality (a, b) { |
|
|
|
|
return a === b; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Type-aware projection |
|
|
|
|
*/ |
|
|
|
|
function projectForUnique (elt) { |
|
|
|
|
if (elt === null) { return '$null'; } |
|
|
|
|
if (typeof elt === 'string') { return '$string' + elt; } |
|
|
|
|
if (typeof elt === 'boolean') { return '$boolean' + elt; } |
|
|
|
|
if (typeof elt === 'number') { return '$number' + elt; } |
|
|
|
|
if (util.isArray(elt)) { return '$date' + elt.getTime(); } |
|
|
|
|
|
|
|
|
|
return elt; // Arrays and objects, will check for pointer equality
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new index |
|
|
|
@ -61,7 +74,7 @@ Index.prototype.insert = function (doc) { |
|
|
|
|
if (!util.isArray(key)) { |
|
|
|
|
this.tree.insert(key, doc); |
|
|
|
|
} else { |
|
|
|
|
_.uniq(key, model.areThingsEqual).forEach(function (_key) { |
|
|
|
|
_.uniq(key, projectForUnique).forEach(function (_key) { |
|
|
|
|
self.tree.insert(_key, doc); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|