diff options
-rw-r--r-- | project2/common/aggregates/count.cpp | 28 | ||||
-rw-r--r-- | project2/common/aggregates/countDistinct.cpp | 26 |
2 files changed, 54 insertions, 0 deletions
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<VariableType> result; +}; + +DECLARE_LOADER("countdistinct", CountDistinct); + |