ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
subset.hpp
Go to the documentation of this file.
1/**
2 * @file subset.hpp
3 * @brief Enumerate tuple subsets satisfying an aggregate HAVING predicate.
4 *
5 * For aggregate provenance evaluation, ProvSQL needs to determine which
6 * subsets of base tuples produce a group-aggregate value that satisfies
7 * the HAVING condition. This header declares the @c enumerate_valid_worlds()
8 * function that enumerates all such subsets ("valid worlds") as bitmasks.
9 *
10 * A *world* is represented as a @c mask_t = @c std::vector<bool> of length
11 * @f$n@f$, where bit @f$i@f$ is @c true iff tuple @f$i@f$ is present in
12 * that world. The function returns all worlds where the aggregate of the
13 * present tuples' values satisfies the given comparison.
14 */
15#ifndef SUBSET_HPP
16#define SUBSET_HPP
17
18#include <cstdint>
19#include <vector>
20
21#include "Aggregation.h"
22
23/**
24 * @brief A bitmask over @f$n@f$ tuples representing one possible world.
25 *
26 * @c mask_t[i] is @c true iff tuple @f$i@f$ is present in this world.
27 */
28using mask_t=std::vector<bool>;
29
30/**
31 * @brief Enumerate all subsets of @p n tuples satisfying an aggregate predicate.
32 *
33 * For each subset @f$W \subseteq \{0, \ldots, n-1\}@f$ of the tuples,
34 * computes the aggregate of their @p values, tests the predicate
35 * @f$\text{agg}(W) \;\mathit{op}\; \text{constant}@f$, and includes @f$W@f$
36 * in the result if the predicate holds.
37 *
38 * @param values Aggregate contribution of each tuple (one value per tuple).
39 * @param constant The constant on the right-hand side of the comparison.
40 * @param op Comparison operator (=, ≠, <, ≤, >, ≥).
41 * @param agg_kind Aggregation function (SUM, COUNT, MIN, MAX, …).
42 * @param enumerate If @c false, only determine whether the set of valid worlds
43 * is an upset; the returned vector may be empty.
44 * @param upset Output: set to @c true if the set of valid worlds forms an
45 * upset (upward-closed set), @c false otherwise.
46 * @return Vector of bitmasks, one per valid world.
47 */
48std::vector<mask_t> enumerate_valid_worlds(
49 const std::vector<long> &values,
50 int constant,
52 AggregationOperator agg_kind,
53 bool enumerate,
54 bool &upset
55 );
56
57#endif /* SUBSET_HPP */
Typed aggregation value, operator, and aggregator abstractions.
AggregationOperator
SQL aggregation functions tracked by ProvSQL.
Definition Aggregation.h:50
ComparisonOperator
SQL comparison operators used in gate_cmp circuit gates.
Definition Aggregation.h:38
std::vector< mask_t > enumerate_valid_worlds(const std::vector< long > &values, int constant, ComparisonOperator op, AggregationOperator agg_kind, bool enumerate, bool &upset)
Enumerate all subsets of n tuples satisfying an aggregate predicate.
Definition subset.cpp:347
std::vector< bool > mask_t
A bitmask over tuples representing one possible world.
Definition subset.hpp:28