Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
string_histogram.hpp File Reference

MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gather_str.cpp). More...

#include "shambase/aliases_int.hpp"
#include <unordered_map>
#include <string>
#include <vector>
Include dependency graph for string_histogram.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  shamalgs
 namespace to contain everything implemented by shamalgs

Functions

std::unordered_map< std::string, int > shamalgs::collective::string_histogram (const std::vector< std::string > &inputs, std::string delimiter, bool hash_based)
 Constructs a histogram from a vector of strings, counting occurrences of each unique string.
std::unordered_map< std::string, int > shamalgs::collective::all_string_histogram (const std::vector< std::string > &inputs, std::string delimiter, bool hash_based)
 same as string_histogram but with result return on every rank

Detailed Description

MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gather_str.cpp).

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

Definition in file string_histogram.hpp.

Function Documentation

◆ all_string_histogram()

std::unordered_map< std::string, int > shamalgs::collective::all_string_histogram ( const std::vector< std::string > & inputs,
std::string delimiter,
bool hash_based )

same as string_histogram but with result return on every rank

Definition at line 141 of file string_histogram.cpp.

◆ string_histogram()

std::unordered_map< std::string, int > shamalgs::collective::string_histogram ( const std::vector< std::string > & inputs,
std::string delimiter,
bool hash_based )

Constructs a histogram from a vector of strings, counting occurrences of each unique string.

This function takes a vector of strings, concatenates them into a single string using the specified delimiter, and then splits the concatenated string back into individual strings. It then counts the occurrences of each unique string and returns a histogram as an unordered map.

Parameters
inputsA vector of strings to process.
delimiterA string used to concatenate and split the inputs. Defaults to a newline character.
Returns
An unordered map where keys are unique strings from the input and values are the counts of their occurrences. (valid only on rank 0)

Definition at line 131 of file string_histogram.cpp.