Operators
The operators/
directory implements MPC-enabled data-parallel operators used by ORQ queries.
Contents:
aggregation_selector.h
- Internal helper class to select between aggregation types at runtimeaggregation.h
– Secure aggregation functions (SUM, COUNT, etc.) and oblivious aggregation networkcircuits.h
- Implementation of various boolean circuits.common.h
– Common utilities shared by operators.distinct.h
– Distinct operator.join.h
- Join operator.merge.h
– Oblivious Merge.quicksort.h
– Quicksort implementation.radixsort.h
– Radixsort implementation.shuffle.h
– Oblivious shuffle operators.sorting.h
– Sorting helper functions.streaming.h
– Streaming operators.
Note: For documentation on the join functions, see orq::relational::EncodedTable::_join()
.
Boolean Circuits
Implementation of various boolean circuits.
(moved out of BSharedVector.h)
-
namespace orq
-
namespace operators
Typedefs
-
template<typename S, typename E>
using unique_B = std::unique_ptr<BSharedVector<S, E>> Alias for a unique pointer to a BSharedVector.
- Template Parameters:
S –
E –
Functions
Computes vectorized boolean addition using a ripple carry adder. We use a slightly non-traditional circuit to achieve exactly \(\ell - 1\) rounds of computation (where \(\ell\) is the bitwidth of the shares), and bit packing, which achieves asymptotically optimal bandwidth as the input vectors grow. Thus, in many cases, RCA is actually superior to PPA, since we are usually not round-constrained.
- Parameters:
a –
b –
carry_in – the carry-in bit. used for subtraction. default false.
- Returns:
A unique pointer to a new shared vector that contains boolean shares of the elementwise additions
Implements a comparison circuit using ripple_carry_adder; i.e., via boolean subtraction.
a < b
impliesa - b < 0
, and we can checkltz()
for free with boolean shares. So, subtract the two inputs and return (a secret sharing of) the sign bit.This runs a slightly optimized version of RCA, since we only need to compute carries (no sum bits). In most cases it is a bit faster, but is not round optimal.
- Parameters:
a –
b –
- Returns:
unique pointer to a BSharedVector
Computes a prefix graph component for the parallel prefix adder.
- Template Parameters:
Share – Share data type
EVector – Share container type
- Parameters:
x – A pair containing the non-shifted generate and propagate vectors of x
y – A pair containing the shifted generate and propagate vectors of y
- Returns:
A new pair containing the output generate and propagate vectors, respectively.
Computes vectorized boolean addition using a parallel prefix adder (specifically, a Kogge-Stone circuit).
A prior version used the Sklansky circuit, which has half the bandwidth, but the bandwidth savings don’t matter here: we always compute over the full-width types. Additionally, the greater fan-out of Sklansky had higher local compute overheads due to data movement.
- Parameters:
current – the first BSharedVector
other – the second BSharedVector
carry_in – the carry bit (default false)
- Returns:
A unique pointer to a new shared vector that contains boolean shares of the elementwise additions
-
template<typename S, typename E>
-
namespace operators
Shuffle
Defines
-
random_buffer_size
-
namespace orq
-
namespace operators
Typedefs
-
template<typename E>
using AElementwisePermutation = ASharedVector<int, orq::EVector<int, E::replicationNumber>>
-
template<typename E>
using BElementwisePermutation = BSharedVector<int, orq::EVector<int, E::replicationNumber>>
Functions
Protocol agnostic function to apply sharded permutations.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute.
perm – The permutation to apply.
Protocol agnostic function to apply sharded permutations.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute.
perm – The permutation whose inverse to apply.
Obliviously apply an elementwise secret-shared permutation.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
EVectorPerm – Permutation type.
- Parameters:
x – The secret-shared vector to permute.
perm – The permutation to apply.
Generate a pseudorandom local permutation using Fisher-Yates shuffle.
Creates a vector {0, 1, …, size-1}, permutes it, and returns it.
- Parameters:
size – The size of the permutation.
generator – The common PRG object used as the pseudorandomness source.
- Returns:
The permutation as a vector of destination indices.
-
template<typename T>
void local_apply_perm(Vector<T> &x, const LocalPermutation &permutation) Apply a local permutation to a vector.
- Template Parameters:
T – Data type of vector elements.
- Parameters:
x – The vector to permute (modified in place).
permutation – The permutation to apply.
-
template<typename T>
void local_apply_perm(Vector<T> &x, Vector<int> &permutation) Overload for both vector and permutation represented as ORQ Vector.
- Template Parameters:
T – Data type of vector elements.
- Parameters:
x – The vector to permute (modified in place).
permutation – The permutation to apply as ORQ Vector.
-
template<typename T>
void local_apply_perm_single_threaded(Vector<T> &x, const LocalPermutation &permutation) Single-threaded version of local_apply_perm.
Avoids reentering the runtime within a thread.
- Template Parameters:
T – Data type of vector elements.
- Parameters:
x – The vector to permute (modified in place).
permutation – The permutation to apply.
-
template<typename T>
void local_apply_perm_single_threaded(Vector<T> &x, Vector<int> &permutation) Single-threaded overload for both vector and permutation represented as ORQ Vector.
- Template Parameters:
T – Data type of vector elements.
- Parameters:
x – The vector to permute (modified in place).
permutation – The permutation to apply.
-
template<typename T, int R, typename P>
void local_apply_perm(EVector<T, R> &x, P &permutation) Catch-all overload for arbitrary vector types and permutation as ORQ Vector
- Template Parameters:
T – Data type of vector elements.
R – Replication number.
P – Permutation type.
- Parameters:
x – The vector to permute (modified in place).
permutation – The permutation to apply.
-
template<typename EVector>
void local_apply_perm(ElementwisePermutation<EVector> &x, Vector<int> &permutation) Overload when vector is an ElementwisePermutation.
- Template Parameters:
EVector – Share container type.
- Parameters:
x – The vector to permute (modified in place).
permutation – The permutation to apply.
Overload for permutation a SharedVector. Permutation type P can be a LocalPermutation or Vector<int>.
- Template Parameters:
S – Share data type.
E – Share container type.
P – Permutation type.
- Parameters:
x – The vector to permute (modified in place).
permutation – The permutation to apply.
-
template<typename T, typename S = int>
void local_apply_inverse_perm(Vector<T> &x, const std::vector<S> &permutation) Apply the inverse of a local permutation to a vector.
NOTE: this can also be implemented by just applying
permutation
as a new mapping. However, this is currently less efficient.- Template Parameters:
T – Data type of vector elements.
S – Permutation data type.
- Parameters:
x – The vector to permute.
permutation – The permutation whose inverse to apply.
-
template<typename T, typename S = int>
void local_apply_inverse_perm(Vector<T> &x, const Vector<S> &permutation) Overload when both are ORQ Vectors.
- Template Parameters:
T – Data type of vector elements.
S – Permutation data type.
- Parameters:
x – The vector to permute.
permutation – The permutation whose inverse to apply.
-
template<typename T, int R, typename S = int>
void local_apply_inverse_perm(EVector<T, R> &x, const std::vector<S> &permutation) Overload when we are permutation an EVector.
- Template Parameters:
T – Data type of vector elements.
R – Replication number.
S – Permutation data type.
- Parameters:
x – The vector to permute.
permutation – The permutation whose inverse to apply.
Overload when vector is a SharedVector.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
S – Permutation data type.
- Parameters:
x – The vector to permute.
permutation – The permutation whose inverse to apply.
Overload when vector is a SharedVector and permutation is a ORQ Vector
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The vector to permute.
permutation – The permutation whose inverse to apply.
-
template<typename EVector>
void local_apply_inverse_perm(ElementwisePermutation<EVector> &x, Vector<int> &permutation) Overload when the vector is an ElementwisePermutation and permutation is a ORQ Vector
- Template Parameters:
EVector – Share container type.
- Parameters:
x – The vector to permute.
permutation – The permutation whose inverse to apply.
Obliviously apply a sharded secret-shared permutation (Honest Majority).
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute.
permutation – The permutation to apply.
Obliviously apply a sharded secret-shared permutation (Honest Majority).
This overloaded function just passes the ElementwisePermutation’s underlying SharedVector.
- Parameters:
x – The ElementwisePermutation to permute.
permutation – The permutation to apply.
Obliviously apply the inverse of a sharded secret-shared permutation.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute.
permutation – The permutation whose inverse to apply.
Obliviously apply the inverse of a sharded secret-shared permutation (Honest Majority).
- Template Parameters:
EVector – Share container type.
- Parameters:
x – The ElementwisePermutation to permute.
permutation – The permutation whose inverse to apply.
Apply a permutation correlation to a secret-shared vector (2PC only).
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute and share.
perm – The permutation correlation.
send_party – The index of the party acting as the sender.
Apply the inverse of a permutation correlation to a secret-shared vector (2PC only).
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute and share.
perm – The permutation correlation whose inverse to apply.
send_party – The index of the party acting as the sender.
Obliviously apply a sharded secret-shared permutation (Dishonest Majority).
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute.
permutation – The permutation to apply.
Obliviously apply the inverse of a sharded secret-shared permutation (Dishonest Majority).
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute.
permutation – The permutation whose inverse to apply.
Protocol agnostic function to apply sharded permutations.
This overloaded function just passes the ElementwisePermutation’s underlying SharedVector.
- Template Parameters:
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute.
permutation – The permutation to apply.
Protocol agnostic function to apply inversesharded permutations.
- Template Parameters:
EVector – Share container type.
- Parameters:
x – The secret-shared vector to permute.
permutation – The permutation whose inverse to apply.
-
template<typename EVector>
ElementwisePermutation<EVector> compose_permutations(ElementwisePermutation<EVector> &sigma, ElementwisePermutation<EVector> &rho) Compose two elementwise secret-shared permutations.
- Template Parameters:
EVector – Share container type.
- Parameters:
sigma – The first permutation to be applied in the composition.
rho – The second permutation to be applied in the composition.
- Returns:
An elementwise secret-sharing of the composed permutation.
Obliviously shuffle a secret-shared vector.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x – The vector to shuffle.
Obliviously shuffle a table of secret-shared vectors.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
_data_a – List of pointers to all arithmetic columns.
_data_b – List of pointers to all binary columns.
size – Size of the vectors to shuffle.
-
template<typename E>
-
namespace operators
Sorting
Defines
-
DEFAULT_SORT_PROTO
-
namespace orq
Enums
-
namespace operators
Typedefs
-
template<typename T>
using PadWidth = typename std::conditional<std::is_same<T, int64_t>::value, __int128_t, int64_t>::type
Functions
- template<typename Share, typename EVector> static DOXYGEN_IGNORE BSharedVector< Share, EVector > compare (BSharedVector< Share, EVector > &x_vec, BSharedVector< Share, EVector > &y_vec, const std::vector< SortOrder > &order)
Compares two vectors element-wise.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x_vec – Left vector.
y_vec – Right vector.
order – Comparison order.
- Returns:
Comparison result bits.
Compares two
MxN
arrays row-wise by applyingM
greater-than comparisons onN
keys.NOTE: The i-th row, let l, from the left array is greater than the i-th row, let r, from the right array if l’s first key is greater than r’s first key, or the first keys are the same and l’s second key is greater than r’s second key, or the first two keys are the same and so forth, for all keys.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x_vec – The left column-first array with
M
rows andN
columns.y_vec – The right column-first array with
M
rows andN
columns.order – A vector that denotes the order of comparison per key.
- Returns:
A new shared vector that contains the result bits of the
M
greater-than comparisons.
Same as above but accepts the
N
columns by reference.- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x_vec – The left column-first array with
M
rows andN
columns.y_vec – The right column-first array with
M
rows andN
columns.order – A vector that denotes the order of comparison per key.
- Returns:
A new shared vector that contains the result bits of the
M
greater-than comparisons.
Swaps rows of two
MxN
arrays in place using the providedbits
.- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x_vec – The left column-first array with
M
rows andN
columns.y_vec – The right column-first array with
M
rows andN
columns.bits – The B-shared vector that contains ‘M’ bits to use for oblivious swapping (if bits[i]=True, the i-th rows will be swapped).
Swaps rows of two arithmetic arrays using selection bits.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x_vec – Left array.
y_vec – Right array.
bits – Selection bits for swapping.
Same as above but accepts the
N
columns by reference.- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x_vec – The left column-first array with
M
rows andN
columns.y_vec – The right column-first array with
M
rows andN
columns.bits – The B-shared vector that contains ‘M’ bits to use for oblivious swapping (if bits[i]=True, the i-th rows will be swapped).
Swaps arithmetic arrays using selection bits (reference overload).
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x_vec – Left array.
y_vec – Right array.
bits – Selection bits for swapping.
Same as above but accepts the
N
columns by reference.- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
x_vec – The left column-first array with
M
rows andN
columns.y_vec – The right column-first array with
M
rows andN
columns.bits – The B-shared vector that contains ‘M’ bits to use for oblivious swapping (if bits[i]=True, the i-th rows will be swapped).
Sorts rows in the given array on all columns. Updates array in place.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
_columns – The columns of the array.
order – The sorting direction per column.
Same as above but accepts the columns by reference.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
_columns – The columns of the array.
order – The sorting direction per column.
Sorts rows in the given array on all columns. Updates array in place.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
_columns – The columns of the array.
order – The sorting direction per column (default ascending).
Extend <=32 bit elements to 64 bit elements.
Shift original value into most significant 32 bits. Set least significant 32 bits equal to the initial index. If reverse_order is set, pad with the values -1 to -n, otherwise pad with 0 to n-1.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
v – The input vector with <=32 bits.
reverse_order – Indicates whether the upcoming sort is in reverse order.
- Returns:
The 64 bit shared vector.
Remove the padding from the 64 bit result to obtain the original <=32 bit values.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
v – The original input vector to place the result in.
padded – The 64 bit shared vector.
reverse_order – Indicates whether the upcoming sort is in reverse order.
- Returns:
The extracted permutation.
Sorts rows in the given array on all columns. Updates array in place.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
_columns – The columns to sort by.
_data_a – The AShared columns of the array to be sorted.
_data_b – The BShared columns of the array to be sorted.
single_bit – which columns are single-bit columns (thus use 1-bit radixsort)
protocol – which sorting protocol to use
order – The sorting direction per column.
-
template<typename T>
-
namespace operators
-
namespace orq
-
namespace operators
Functions
Partitions a vector segment based on comparison results.
Rearranges elements between start and end indices based on pivot comparisons. Elements equal to 0 in comparisons are moved to the left partition.
Core quicksort algorithm implementation.
Performs the main quicksort logic on a padded vector.
- Template Parameters:
T – Share data type.
EVector – Share container type.
- Parameters:
v – Vector to sort (modified in place).
Main quicksort entry point.
Sorts a vector using the quicksort algorithm with padding for stability. Handles both ascending and descending order sorting.
- Template Parameters:
Share – Share data type.
EVector – Share container type.
- Parameters:
v – Vector to sort (modified in place).
order – Sorting direction (ASC or DESC).
- Returns:
Permutation representing the applied sort order.
-
namespace operators
-
namespace orq
-
namespace operators
Typedefs
Functions
Direct implementation of the AHI+22 radix sort algorithm.
- Template Parameters:
S – Share data type.
E – Share container type.
- Parameters:
v – Vector to sort.
bits – Number of bits to sort on.
full_width – Whether sorting on full bitwidth (affects sign bit handling).
- Returns:
Permutation representing the sort order.
The radix sort protocol.
Implements the radix sort protocol for a given number of bits.
- Template Parameters:
S – Share data type.
E – Share container type.
- Parameters:
v – Vector to sort.
bits – Number of bits to sort on.
full_width – Whether sorting on full bitwidth (affects sign bit handling).
The radix sort protocol entry point.
- Template Parameters:
S – Share data type.
E – Share container type.
- Parameters:
v – Vector to sort.
order – Sort order (ascending or descending).
bits – Number of bits to sort on.
- Returns:
Permutation representing the applied sort order.
-
namespace operators
Merge
-
namespace orq
-
namespace operators
Functions
Performs conditional swap on two boolean shared vectors.
Swaps elements between x and y based on comparison result (x >= y). After the swap, x contains the smaller values and y contains the larger values.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
x – First vector (modified in place).
y – Second vector (modified in place).
Performs odd-even merge on a boolean shared vector.
Implements the odd-even merge algorithm. The vector size must be a power of two.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
v – Vector to be merged (modified in place).
Sorts vectors based on some keys.
Each key needs to have two already sorted halves in the same order.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
_columns – The keys to merge based on.
_data_a – The AShared data vectors to merge.
_data_b – The BShared data vectors to merge.
order – The sorting direction per column.
Sorts vectors based on some keys.
Each key needs to have two already sorted halves in the same order.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
_columns – The keys to merge based on.
_data_a – The AShared data vectors to merge.
_data_b – The BShared data vectors to merge.
order – The sorting direction per column (default ascending).
Sorts a vector that has two already sorted halves in the same order.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
vec – The vector to merge based on.
order – The sorting direction (default ascending).
-
namespace operators
Relational
-
namespace orq
-
namespace aggregators
Typedefs
-
template<typename Share, typename EVector>
using A_ = ASharedVector<Share, EVector>
-
template<typename Share, typename EVector>
using B_ = BSharedVector<Share, EVector>
Enums
Functions
-
template<typename A>
void sum(const A &group, A &a, const A &b) Arithmetic sum aggregation.
- Template Parameters:
A – Arithmetic shared vector type.
- Parameters:
group – Grouping bits indicating which elements to aggregate.
a – Accumulator vector (modified in place).
b – Input vector to be aggregated.
-
template<typename B>
void bit_or(const B &group, B &a, const B &b) Boolean OR aggregation.
- Template Parameters:
B – Boolean shared vector type.
- Parameters:
group – Grouping bits indicating which elements to aggregate.
a – Accumulator vector (modified in place).
b – Input vector to be aggregated.
-
template<typename A>
void count(const A &group, A &a, const A &b) Count aggregation (delegates to sum).
- Template Parameters:
A – Arithmetic shared vector type.
- Parameters:
group – Grouping bits indicating which elements to count.
a – Accumulator vector (modified in place).
b – Input vector (typically all ones for counting).
-
template<typename B>
void _min_max_agg(const B &group, B &a, const B &b, const bool &minimum = false) Internal helper for min/max aggregation.
- Template Parameters:
B – Boolean shared vector type.
- Parameters:
group – Grouping bits indicating which elements to aggregate.
a – Accumulator vector (modified in place).
b – Input vector to be aggregated.
minimum – If true, computes minimum; if false, computes maximum.
-
template<typename B>
void max(const B &group, B &a, const B &b) Maximum aggregation.
- Template Parameters:
B – Boolean shared vector type.
- Parameters:
group – Grouping bits indicating which elements to aggregate.
a – Accumulator vector (modified in place).
b – Input vector to be aggregated.
-
template<typename B>
void min(const B &group, B &a, const B &b) Minimum aggregation.
- Template Parameters:
B – Boolean shared vector type.
- Parameters:
group – Grouping bits indicating which elements to aggregate.
a – Accumulator vector (modified in place).
b – Input vector to be aggregated.
-
template<typename T>
void copy(const T &group, T &a, const T &b) Identity “aggregation”, used for non-aggregated joins. Templated to accept either arithmetic or boolean types. Copies rows from left to the right.
- Parameters:
group – grouping bits.
a – first vector, which will be updated.
b – second vector.
-
template<typename B>
void valid(const B &group, B &a, const B &b) validity aggregation. For internal use while updating valid column.
- Template Parameters:
B – Boolean shared vector type.
- Parameters:
group – Grouping bits.
a – Accumulator vector (modified in place).
b – Input vector.
-
template<typename S, typename E>
void aggregate(std::vector<B_<S, E>> &keys, const std::vector<std::tuple<B_<S, E>, B_<S, E>, void (*)(const B_<S, E>&, B_<S, E>&, const B_<S, E>&)>> &agg_spec_b, const std::vector<std::tuple<A_<S, E>, A_<S, E>, void (*)(const A_<S, E>&, A_<S, E>&, const A_<S, E>&)>> &agg_spec_a, const enum Direction dir = Direction::Forward, std::optional<B_<S, E>> sel_b = {}) Sorting-network based agregation. Assumes all vectors are the same size.
- Template Parameters:
S – underlying data type of vectors
E – Share container type.
- Parameters:
keys – vector of keys to join and aggregate on
agg_spec_b – boolean aggregations
agg_spec_a – arithmetic aggregations
dir – which direction to run the aggregation
sel_b – selection column (for table operations, usually table ID)
-
template<typename S, typename E>
void aggregate(std::vector<B_<S, E>> &keys, const std::vector<std::tuple<B_<S, E>, B_<S, E>, void (*)(const B_<S, E>&, B_<S, E>&, const B_<S, E>&)>> &agg_spec_b, const std::vector<std::tuple<A_<S, E>, A_<S, E>, void (*)(const A_<S, E>&, A_<S, E>&, const A_<S, E>&)>> &agg_spec_a, B_<S, E> sel_b) Aggregation, with additional selection (window) argument. Performs reverse aggregation.
- Template Parameters:
S –
E –
- Parameters:
keys –
agg_spec_b –
agg_spec_a –
sel_b –
-
template<typename T>
void tree_prefix_sum(T v, const bool &reverse = false) Compute a prefix sum over a vector using a log-depth aggregation tree. Based on sorting network aggregation but entirely local computation, with the simplification that all entries belong to the same group.
TODO: extend this to any user-supplied associative operation
- Template Parameters:
T – vector type (shared or plaintext)
- Parameters:
v – input vector
reverse – whether to compute a suffix sum instead
Variables
-
enum orq::aggregators::Direction Direction
-
template<typename Share, typename EVector>
-
namespace aggregators
-
namespace orq
-
namespace operators
Functions
Obliviously marks distinct rows based on keys (adjacent rows only).
Only adjacent rows are considered, so vectors should be sorted before calling for global uniqueness.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
keys – List of keys to consider for uniqueness.
res – Vector to place the result in.
-
namespace operators
-
namespace orq
-
namespace aggregators
-
template<typename A, typename B>
class AggregationSelector - #include <aggregation_selector.h>
A helper type to store an aggregation of either AShared or BShared type.
- Template Parameters:
A –
B –
Public Functions
-
inline af_t getA()
Get the AShared function. If this object does not store an AShared function, abort.
- Returns:
af_t
-
inline bf_t getB()
Get the BShared function. If this object does not store a BShared function, abort.
- Returns:
bf_t
-
inline bool isAggregation()
Check if the stored function is a copy aggregation or aggregation.
- Returns:
true the stored function is an aggregation (non-copy)
- Returns:
false the stored function is a copy function
Private Types
-
template<typename A, typename B>
-
namespace aggregators
-
struct JoinOptions
Options struct for join. Construct an instance and pass it in, or use inline struct initializer syntax.
Available fields:
left_outer
: if this is a left outer join.right_outer
: if this is a right outer join.anti
: if this is an anti join.trim_invalid
: whether to trim invalid rows from the output (bounded by the size of the right table)
The join options generalize the other kinds of joins: inner joins are neither left outer nor right outer; full outer joins are both left outer and right outer. The default is an inner join; i.e., both are
false
.
-
struct AggregationOptions
Options struct for aggregation.
Available fields:
reverse
: whether this is a forward or reverse aggregation. (defaultfalse
)do_sort
: whether to sort first. (defaulttrue
)mark_valid
: whether to mark valid rows post-aggregation. (defaulttrue
)table_id
: an optional string pointing to the name of the table ID column.
Streaming
-
namespace orq
-
namespace operators
Functions
Computes tumbling window identifiers for stream processing.
A tumbling window divides the stream into non-overlapping windows of fixed size. This function computes the window identifier for each element by dividing the key (typically a timestamp or sequence number) by the window size.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
key – Input vector containing keys/timestamps for window assignment.
window_size – The size of each tumbling window.
res – Output vector that will contain the computed window identifiers.
Marks the start of new gap-based sessions in a timestamp sequence.
This function identifies session boundaries based on gaps in timestamps. A new session starts when the gap between consecutive timestamps exceeds the specified threshold. The first element is always marked as a session start.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
timestamp – Input vector of timestamps in ascending order.
session_start – Output boolean vector marking session start positions.
gap – The maximum allowed gap between timestamps within a session.
Creates gap-based session windows for stream aggregation.
This function implements session windowing based on timestamp gaps. Sessions are identified using the mark_gap_session function, then window identifiers are computed using reverse aggregation to assign the same window ID to all elements within a session.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
keys – Vector of key vectors used for aggregation operations.
timestamp_a – Arithmetic shared vector of timestamps.
timestamp_b – Boolean shared vector of timestamps (for multiplexing).
window_id – Output vector that will contain the computed window identifiers.
gap – The maximum allowed gap between timestamps within a session.
Marks the start of new threshold-based sessions.
This function identifies session boundaries based on a threshold applied to a function result (e.g., sensor readings, activity levels). A new session starts when the function result exceeds the threshold and the previous element was below the threshold.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
function_res – Input vector containing function results to compare against threshold.
session_start – Output boolean vector marking session start positions.
potential_window – Output boolean vector indicating elements above threshold.
threshold – The threshold value for session detection.
Creates threshold-based session windows for stream aggregation.
This function implements session windowing based on threshold detection. Sessions are identified when function results exceed a threshold, and window identifiers are computed using aggregation with the potential_window as a selection mask to only include elements that meet the threshold criteria.
- Template Parameters:
Share – The underlying data type of the shared vectors.
EVector – Share container type.
- Parameters:
keys – Vector of key vectors used for aggregation operations.
function_res – Input vector containing function results for threshold comparison.
timestamp_b – Boolean shared vector of timestamps (for multiplexing).
window_id – Output vector that will contain the computed window identifiers.
gap – The threshold value for session detection (note: parameter name is misleading).
-
namespace operators
Common
-
namespace orq
-
namespace operators
Functions
Conditional selection between two boolean shared vectors.
Performs oblivious selection: returns a if sel is false, b if sel is true.
- Template Parameters:
Share – The underlying data type of the shared vectors.
- Parameters:
sel – Boolean selector vector (extended to full bit width).
a – First input vector (returned when sel is false).
b – Second input vector (returned when sel is true).
- Returns:
The multiplexed result vector.
Conditional selection between two arithmetic shared vectors.
Performs oblivious selection: returns a if sel is 0, b if sel is 1. Uses linear combination for arithmetic shares.
- Template Parameters:
Share – The underlying data type of the shared vectors.
- Parameters:
sel – Arithmetic selector vector.
a – First input vector (returned when sel is 0).
b – Second input vector (returned when sel is 1).
- Returns:
The multiplexed result vector.
Identity conversion for boolean shared vectors.
- Template Parameters:
Share – The underlying data type of the shared vectors.
- Parameters:
x – Input boolean shared vector.
res – Output boolean shared vector (copy of input).
Identity conversion for arithmetic shared vectors.
- Template Parameters:
Share – The underlying data type of the shared vectors.
- Parameters:
x – Input arithmetic shared vector.
res – Output arithmetic shared vector (copy of input).
Converts boolean shared vector to arithmetic shared vector.
- Template Parameters:
Share – The underlying data type of the shared vectors.
- Parameters:
x – Input boolean shared vector.
res – Output arithmetic shared vector.
Converts arithmetic shared vector to boolean shared vector.
- Template Parameters:
Share – The underlying data type of the shared vectors.
- Parameters:
x – Input arithmetic shared vector.
res – Output boolean shared vector.
Creates boolean shared vector from plaintext data.
- Template Parameters:
Share – The underlying data type of the shared vectors.
- Parameters:
data – Plaintext vector to be secret-shared.
out – Output boolean shared vector.
data_party – The party that provides the input data.
Creates arithmetic shared vector from plaintext data.
- Template Parameters:
Share – The underlying data type of the shared vectors.
- Parameters:
data – Plaintext vector to be secret-shared.
out – Output arithmetic shared vector.
data_party – The party that provides the input data.
-
namespace operators