From 6bf494815c2bd2a899cae8d966d9fd124a56f13f Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 9 Feb 2012 12:46:05 +0000 Subject: Add some more aggregates --- project2/common/aggregates/count.cpp | 28 ++++++++++++++++++++++++++++ project2/common/aggregates/countDistinct.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 project2/common/aggregates/count.cpp create mode 100644 project2/common/aggregates/countDistinct.cpp diff --git a/project2/common/aggregates/count.cpp b/project2/common/aggregates/count.cpp new file mode 100644 index 0000000..9bdb47c --- /dev/null +++ b/project2/common/aggregates/count.cpp @@ -0,0 +1,28 @@ +#include "../aggregate.h" + +class Count : public ValueAggregate { + public: + Count(ScriptNodePtr s) : + ValueAggregate(s), + c(0) + { + } + void reset() const + { + c = 0; + } + void pushValue(const VariableType &) const + { + c += 1; + } + VariableType resultValue() const + { + return c; + } + private: + mutable int c; +}; + +DECLARE_LOADER("count", Count); + + diff --git a/project2/common/aggregates/countDistinct.cpp b/project2/common/aggregates/countDistinct.cpp new file mode 100644 index 0000000..4a2c540 --- /dev/null +++ b/project2/common/aggregates/countDistinct.cpp @@ -0,0 +1,26 @@ +#include "../aggregate.h" + +class CountDistinct : public ValueAggregate { + public: + CountDistinct(ScriptNodePtr s) : + ValueAggregate(s) + { + } + void reset() const + { + result.clear(); + } + void pushValue(const VariableType & v) const + { + result.insert(v); + } + VariableType resultValue() const + { + return result.size(); + } + private: + mutable std::set result; +}; + +DECLARE_LOADER("countdistinct", CountDistinct); + -- cgit v1.2.3