Skip to content

[FEA] insert_reduce_by_key #23

@jrhemstad

Description

@jrhemstad

Is your feature request related to a problem? Please describe.

A common use case for hash maps is to perform a reduce-by-key-like operation that doesn't require sorting the key/value pairs.

Similar to the bulk insert functions, our static/dynamic maps could provide a bulk insert_reduce_by_key operation that looks something like:

/**
 * @brief Inserts a set of key-value pairs and performs a reduction among the values of identical
 * keys.
 *
 * @tparam InputIt
 * @tparam BinaryOp
 * @tparam Hash
 * @tparam KeyEqual
 * @param first Beginning of the key-value pair range
 * @param last End of the key-value pair range
 * @param op The binary operation to perform among values of identical keys
 * @param hash
 * @param key_equal
 */
template <typename InputIt, typename BinaryOp, typename Hash, typename KeyEqual>
void insert_reduce_by_key(InputIt first, InputIt last, BinaryOp op, Hash hash, KeyEqual key_equal);

One issue with this operation is that since the BinaryOp is any generic operation, applying will have to be done with an atomicCAS. If the operation was simply a sum, it would be more efficient to directly use an atomicAdd, but there isn't any way for us to detect what the user provided operation is. Therefore, we could possibly provide explicit functions that map to native atomic instructions, e.g., insert_sum_by_key, insert_min_by_key, etc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions