|
|
@@ -10,7 +10,7 @@
|
|
|
**/
|
|
|
|
|
|
var SetIsSubsetExpression = module.exports = function SetIsSubsetExpression() {
|
|
|
- if (arguments.length !== 2) throw new Error("two args expected");
|
|
|
+// if (arguments.length !== 2) throw new Error("two args expected");
|
|
|
base.call(this);
|
|
|
}, klass = SetIsSubsetExpression,
|
|
|
FixedArityExpression = require("./FixedArityExpressionT")(klass, 2),
|
|
|
@@ -22,9 +22,19 @@ var SetIsSubsetExpression = module.exports = function SetIsSubsetExpression() {
|
|
|
});
|
|
|
|
|
|
|
|
|
+// DEPENDENCIES
|
|
|
+var Value = require("../Value"),
|
|
|
+ Expression = require("./Expression"),
|
|
|
+ Helpers = require("./Helpers");
|
|
|
+
|
|
|
+// PROTOTYPE MEMBERS
|
|
|
+proto.getOpName = function getOpName() {
|
|
|
+ return "$setissubset";
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
// lhs should be array, rhs should be set (object). See arrayToSet implementation.
|
|
|
var setIsSubsetHelper = function setIsSubsetHelper(lhs, rhs){
|
|
|
-
|
|
|
var lset = Helpers.arrayToSet(lhs);
|
|
|
rkeys = Object.keys(rhs);
|
|
|
// do not shortcircuit when lhs.size() > rhs.size()
|
|
|
@@ -38,6 +48,22 @@ var setIsSubsetHelper = function setIsSubsetHelper(lhs, rhs){
|
|
|
return true;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Takes 2 arrays. Returns true if the first is a subset of the second. Returns false otherwise.
|
|
|
+ * @method evaluateInternal
|
|
|
+ **/
|
|
|
+proto.evaluateInternal = function evaluateInternal(vars) {
|
|
|
+ var lhs = this.operands[0].evaluateInternal(vars),
|
|
|
+ rhs = this.operands[1].evaluateInternal(vars);
|
|
|
+
|
|
|
+ if (!(lhs instanceof Array)) throw new Error("Both operands of " + this.getOpName() + ": be arrays. First argument is of type " + typeof lhs);
|
|
|
+ if (!(rhs instanceof Array)) throw new Error("Both operands of " + this.getOpName() + ": be arrays. First argument is of type " + typeof rhs);
|
|
|
+
|
|
|
+ return setIsSubsetHelper(lhs, Helpers.arrayToSet(rhs));
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
var Optimized = function Optimized(cachedRhsSet, operands) {
|
|
|
this.operands = operands;
|
|
|
this._cachedRhsSet = cachedRhsSet;
|
|
|
@@ -52,34 +78,24 @@ Optimized.prototype = Object.create(SetIsSubsetExpression.prototype, {
|
|
|
Optimized.prototype.evaluateInternal = function evaluateInternal(vars){
|
|
|
lhs = this.operands[0].evaluateInternal(vars);
|
|
|
|
|
|
- if (!(lhs instanceof Array)) throw new Error("uassert 17046: both operands of " + this.getOpName() + " must be arrays. Second argument is of type " + typeof lhs);
|
|
|
+ if (!(lhs instanceof Array)) throw new Error("uassert 17310: both operands of " + this.getOpName() + " must be arrays. First argument is of type " + typeof lhs);
|
|
|
|
|
|
return setIsSubsetHelper(lhs, this._cachedRhsSet);
|
|
|
};
|
|
|
|
|
|
-// DEPENDENCIES
|
|
|
-var Value = require("../Value"),
|
|
|
- Expression = require("./Expression"),
|
|
|
- Helpers = require("./Helpers");
|
|
|
-
|
|
|
-
|
|
|
-// PROTOTYPE MEMBERS
|
|
|
-proto.getOpName = function getOpName() {
|
|
|
- return "$setissubset";
|
|
|
-};
|
|
|
|
|
|
proto.optimize = function optimize(cachedRhsSet, operands) {
|
|
|
-
|
|
|
// perform basic optimizations
|
|
|
- var optimized = base.optimize.call(this);
|
|
|
+ //var optimized = base.optimize.call(this);
|
|
|
+ var optimized = NaryExpression.optimize();
|
|
|
|
|
|
// if NaryExpression.optimize() created a new value, return it directly
|
|
|
if(optimized != this){
|
|
|
return optimized;
|
|
|
}
|
|
|
|
|
|
- if (operands[1] instanceof ConstantExpression){
|
|
|
- var ce = operands[1],
|
|
|
+ if (this.operands[1] instanceof ConstantExpression){
|
|
|
+ var ce = this.operands[1],
|
|
|
rhs = ce.getValue();
|
|
|
|
|
|
if (!(rhs instanceof Array)) throw new Error("uassert 17311: both operands of " + this.getOpName() + " must be arrays. Second argument is of type " + typeof rhs);
|
|
|
@@ -91,18 +107,5 @@ proto.optimize = function optimize(cachedRhsSet, operands) {
|
|
|
|
|
|
};
|
|
|
|
|
|
-/**
|
|
|
- * Takes 2 arrays. Returns true if the first is a subset of the second. Returns false otherwise.
|
|
|
- * @method evaluateInternal
|
|
|
- **/
|
|
|
-proto.evaluateInternal = function evaluateInternal(vars) {
|
|
|
- var lhs = this.operands[0].evaluateInternal(vars),
|
|
|
- rhs = this.operands[1].evaluateInternal(vars);
|
|
|
- if (!(lhs instanceof Array)) throw new Error(this.getOpName() + ": object 1 must be an array. Got a(n) " + typeof lhs);
|
|
|
- if (!(rhs instanceof Array)) throw new Error(this.getOpName() + ": object 2 must be an array. Got a(n) " + typeof rhs);
|
|
|
-
|
|
|
- return setIsSubsetHelper(lhs, Helpers.arrayToSet(rhs));
|
|
|
-};
|
|
|
-
|
|
|
/** Register Expression */
|
|
|
Expression.registerExpression("$setissubset", base.parse);
|