summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/accumulator.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/accumulator.h')
-rw-r--r--src/mongo/db/pipeline/accumulator.h272
1 files changed, 136 insertions, 136 deletions
diff --git a/src/mongo/db/pipeline/accumulator.h b/src/mongo/db/pipeline/accumulator.h
index 7fa6cd1a8a9..fcb4fe922e1 100644
--- a/src/mongo/db/pipeline/accumulator.h
+++ b/src/mongo/db/pipeline/accumulator.h
@@ -38,182 +38,182 @@
#include "mongo/db/pipeline/value.h"
namespace mongo {
- class Accumulator : public RefCountable {
- public:
- Accumulator() = default;
-
- /** Process input and update internal state.
- * merging should be true when processing outputs from getValue(true).
- */
- void process(const Value& input, bool merging) {
- processInternal(input, merging);
- }
-
- /** Marks the end of the evaluate() phase and return accumulated result.
- * toBeMerged should be true when the outputs will be merged by process().
- */
- virtual Value getValue(bool toBeMerged) const = 0;
-
- /// The name of the op as used in a serialization of the pipeline.
- virtual const char* getOpName() const = 0;
-
- int memUsageForSorter() const {
- dassert(_memUsageBytes != 0); // This would mean subclass didn't set it
- return _memUsageBytes;
- }
-
- /// Reset this accumulator to a fresh state ready to receive input.
- virtual void reset() = 0;
-
- protected:
- /// Update subclass's internal state based on input
- virtual void processInternal(const Value& input, bool merging) = 0;
-
- /// subclasses are expected to update this as necessary
- int _memUsageBytes = 0;
- };
+class Accumulator : public RefCountable {
+public:
+ Accumulator() = default;
+ /** Process input and update internal state.
+ * merging should be true when processing outputs from getValue(true).
+ */
+ void process(const Value& input, bool merging) {
+ processInternal(input, merging);
+ }
- class AccumulatorAddToSet final : public Accumulator {
- public:
- AccumulatorAddToSet();
+ /** Marks the end of the evaluate() phase and return accumulated result.
+ * toBeMerged should be true when the outputs will be merged by process().
+ */
+ virtual Value getValue(bool toBeMerged) const = 0;
- void processInternal(const Value& input, bool merging) final;
- Value getValue(bool toBeMerged) const final;
- const char* getOpName() const final;
- void reset() final;
+ /// The name of the op as used in a serialization of the pipeline.
+ virtual const char* getOpName() const = 0;
- static boost::intrusive_ptr<Accumulator> create();
+ int memUsageForSorter() const {
+ dassert(_memUsageBytes != 0); // This would mean subclass didn't set it
+ return _memUsageBytes;
+ }
- private:
- typedef boost::unordered_set<Value, Value::Hash> SetType;
- SetType set;
- };
+ /// Reset this accumulator to a fresh state ready to receive input.
+ virtual void reset() = 0;
+protected:
+ /// Update subclass's internal state based on input
+ virtual void processInternal(const Value& input, bool merging) = 0;
- class AccumulatorFirst final : public Accumulator {
- public:
- AccumulatorFirst();
+ /// subclasses are expected to update this as necessary
+ int _memUsageBytes = 0;
+};
- void processInternal(const Value& input, bool merging) final;
- Value getValue(bool toBeMerged) const final;
- const char* getOpName() const final;
- void reset() final;
- static boost::intrusive_ptr<Accumulator> create();
+class AccumulatorAddToSet final : public Accumulator {
+public:
+ AccumulatorAddToSet();
- private:
- bool _haveFirst;
- Value _first;
- };
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) const final;
+ const char* getOpName() const final;
+ void reset() final;
+ static boost::intrusive_ptr<Accumulator> create();
- class AccumulatorLast final : public Accumulator {
- public:
- AccumulatorLast();
+private:
+ typedef boost::unordered_set<Value, Value::Hash> SetType;
+ SetType set;
+};
- void processInternal(const Value& input, bool merging) final;
- Value getValue(bool toBeMerged) const final;
- const char* getOpName() const final;
- void reset() final;
- static boost::intrusive_ptr<Accumulator> create();
+class AccumulatorFirst final : public Accumulator {
+public:
+ AccumulatorFirst();
- private:
- Value _last;
- };
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) const final;
+ const char* getOpName() const final;
+ void reset() final;
+ static boost::intrusive_ptr<Accumulator> create();
- class AccumulatorSum final : public Accumulator {
- public:
- AccumulatorSum();
+private:
+ bool _haveFirst;
+ Value _first;
+};
- void processInternal(const Value& input, bool merging) final;
- Value getValue(bool toBeMerged) const final;
- const char* getOpName() const final;
- void reset() final;
- static boost::intrusive_ptr<Accumulator> create();
+class AccumulatorLast final : public Accumulator {
+public:
+ AccumulatorLast();
+
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) const final;
+ const char* getOpName() const final;
+ void reset() final;
+
+ static boost::intrusive_ptr<Accumulator> create();
+
+private:
+ Value _last;
+};
- private:
- BSONType totalType;
- long long longTotal;
- double doubleTotal;
- };
+class AccumulatorSum final : public Accumulator {
+public:
+ AccumulatorSum();
- class AccumulatorMinMax final : public Accumulator {
- public:
- enum Sense : int {
- MIN = 1,
- MAX = -1, // Used to "scale" comparison.
- };
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) const final;
+ const char* getOpName() const final;
+ void reset() final;
- explicit AccumulatorMinMax(Sense sense);
+ static boost::intrusive_ptr<Accumulator> create();
- void processInternal(const Value& input, bool merging) final;
- Value getValue(bool toBeMerged) const final;
- const char* getOpName() const final;
- void reset() final;
+private:
+ BSONType totalType;
+ long long longTotal;
+ double doubleTotal;
+};
- static boost::intrusive_ptr<Accumulator> createMin();
- static boost::intrusive_ptr<Accumulator> createMax();
- private:
- Value _val;
- const Sense _sense;
+class AccumulatorMinMax final : public Accumulator {
+public:
+ enum Sense : int {
+ MIN = 1,
+ MAX = -1, // Used to "scale" comparison.
};
+ explicit AccumulatorMinMax(Sense sense);
- class AccumulatorPush final : public Accumulator {
- public:
- AccumulatorPush();
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) const final;
+ const char* getOpName() const final;
+ void reset() final;
- void processInternal(const Value& input, bool merging) final;
- Value getValue(bool toBeMerged) const final;
- const char* getOpName() const final;
- void reset() final;
+ static boost::intrusive_ptr<Accumulator> createMin();
+ static boost::intrusive_ptr<Accumulator> createMax();
- static boost::intrusive_ptr<Accumulator> create();
+private:
+ Value _val;
+ const Sense _sense;
+};
- private:
- std::vector<Value> vpValue;
- };
+class AccumulatorPush final : public Accumulator {
+public:
+ AccumulatorPush();
- class AccumulatorAvg final : public Accumulator {
- public:
- AccumulatorAvg();
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) const final;
+ const char* getOpName() const final;
+ void reset() final;
- void processInternal(const Value& input, bool merging) final;
- Value getValue(bool toBeMerged) const final;
- const char* getOpName() const final;
- void reset() final;
+ static boost::intrusive_ptr<Accumulator> create();
- static boost::intrusive_ptr<Accumulator> create();
+private:
+ std::vector<Value> vpValue;
+};
- private:
- double _total;
- long long _count;
- };
+class AccumulatorAvg final : public Accumulator {
+public:
+ AccumulatorAvg();
- class AccumulatorStdDev final : public Accumulator {
- public:
- explicit AccumulatorStdDev(bool isSamp);
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) const final;
+ const char* getOpName() const final;
+ void reset() final;
- void processInternal(const Value& input, bool merging) final;
- Value getValue(bool toBeMerged) const final;
- const char* getOpName() const final;
- void reset() final;
+ static boost::intrusive_ptr<Accumulator> create();
- static boost::intrusive_ptr<Accumulator> createSamp();
- static boost::intrusive_ptr<Accumulator> createPop();
+private:
+ double _total;
+ long long _count;
+};
- private:
- const bool _isSamp;
- long long _count;
- double _mean;
- double _m2; // Running sum of squares of delta from mean. Named to match algorithm.
- };
+
+class AccumulatorStdDev final : public Accumulator {
+public:
+ explicit AccumulatorStdDev(bool isSamp);
+
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) const final;
+ const char* getOpName() const final;
+ void reset() final;
+
+ static boost::intrusive_ptr<Accumulator> createSamp();
+ static boost::intrusive_ptr<Accumulator> createPop();
+
+private:
+ const bool _isSamp;
+ long long _count;
+ double _mean;
+ double _m2; // Running sum of squares of delta from mean. Named to match algorithm.
+};
}