浏览代码

Merge branch 'feature/mongo_2.6.5_accumulators' into feature/mongo_2.6.5_accumulators_Push

Kyle P Davis 11 年之前
父节点
当前提交
ad57c73320
共有 1 个文件被更改,包括 33 次插入41 次删除
  1. 33 41
      lib/pipeline/accumulators/Accumulator.js

+ 33 - 41
lib/pipeline/accumulators/Accumulator.js

@@ -1,8 +1,7 @@
 "use strict";
 
 /**
- * A base class for all pipeline accumulators. Uses NaryExpression as a base class.
- *
+ * A base class for all pipeline accumulators.
  * @class Accumulator
  * @namespace mungedb-aggregate.pipeline.accumulators
  * @module mungedb-aggregate
@@ -10,66 +9,59 @@
  **/
 var Accumulator = module.exports = function Accumulator(){
 	if (arguments.length !== 0) throw new Error("zero args expected");
-	this._memUsageBytes = 0;
 	base.call(this);
 }, klass = Accumulator, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
-// DEPENDENCIES
-// var Value = require("../Value"),
-
-proto.memUsageForSorter = function memUsageForSorter() {
-	return this._memUsageBytes;
-};
-
-proto.getFactory = function getFactory(){
-	return klass;	// using the ctor rather than a separate .create() method
-};
-
 /** Process input and update internal state.
- * merging should be true when processing outputs from getValue(true).
+ *  merging should be true when processing outputs from getValue(true).
+ *  @method process
+ *  @param input {Value}
+ *  @param merging {Boolean}
  */
-proto.process = function process(input, merging){
+proto.process = function process(input, merging) {
 	this.processInternal(input, merging);
 };
 
-proto.toJSON = function toJSON(isExpressionRequired){
-	var rep = {};
-	rep[this.getOpName()] = this.operands[0].toJSON(isExpressionRequired);
-	return rep;
+/** Marks the end of the evaluate() phase and return accumulated result.
+ *  toBeMerged should be true when the outputs will be merged by process().
+ *  @method getValue
+ *  @param toBeMerged {Boolean}
+ *  @return {Value}
+ */
+proto.getValue = function getValue(toBeMerged) {
+	throw new Error("You need to define this function on your accumulator");
 };
 
 /**
- * If this function is not overridden in the sub classes,
- * then throw an error
- *
- **/
+ * The name of the op as used in a serialization of the pipeline.
+ * @method getOpName
+ * @return {String}
+ */
 proto.getOpName = function getOpName() {
 	throw new Error("You need to define this function on your accumulator");
 };
 
+//NOTE: DEVIATION FROM MONGO: not implementing this
+//int memUsageForSorter() const {}
+
 /**
- * If this function is not overridden in the sub classes,
- * then throw an error
- *
- **/
-proto.getValue = function getValue(toBeMerged) {
+ * Reset this accumulator to a fresh state ready to receive input.
+ * @method reset
+ */
+proto.reset = function reset() {
 	throw new Error("You need to define this function on your accumulator");
 };
 
 /**
- * If this function is not overridden in the sub classes,
- * then throw an error
- *
- **/
+ * Update subclass's internal state based on input
+ * @method processInternal
+ * @param input {Value}
+ * @param merging {Boolean}
+ */
 proto.processInternal = function processInternal(input, merging) {
 	throw new Error("You need to define this function on your accumulator");
 };
 
-/**
- * If this function is not overridden in the sub classes,
- * then throw an error
- *
- **/
-proto.reset = function reset() {
-	throw new Error("You need to define this function on your accumulator");
-};
+//NOTE: DEVIATION FROM MONGO: not implementing this
+// /// subclasses are expected to update this as necessary
+// int _memUsageBytes;