c++ - 如何实现 mysql 的 DISTINCT 关键字以使用线程并行获取不同的值

标签 c++ mysql parallel-processing

我想使用 hashmap 或 unordered_map 在 c++ 中创建 mysql 的功能性 DISTINCT 关键字。

我必须并行执行此操作,例如最初我在数组中输入整数。

现在我必须在数组中找到不同的数字(并行)

最佳答案

如果原始数组没有改变并假设 hash_map 有可用的 g++ 扩展:

hash_map<int, int> distinct_elems;
for (int i = 0 ; i < num_elems ; ++i)
{
    distinct_elems[i] = i;
}

由于底层数据不会改变 distinct_elems 也不会改变,因此代码:

hash_map<int, int>::iterator de_itr;
for( de_itr = distinct_elems.begin() ; de_itr != distinct_elems.end() ; ++de_itr)
{
    print("%d\n", de_itr->second);
}

或者如果您只是想在 HashMap 中查找值:

hash_map<int, int>::iterator de_itr = distinct_elems.find(value);
if(de_itr != distinct_elems.end())
{
    <do some work>
}

您可以从任意数量的线程执行此操作而无需锁定,因为数据现在基本上是恒定的。

关于c++ - 如何实现 mysql 的 DISTINCT 关键字以使用线程并行获取不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9879070/

相关文章:

c++ - 为什么非常量引用不能绑定(bind)到临时对象?

PHP - 多个文件到数据库中一个字段的路径

mysql - 创建存储过程时 MySQL 中的输入意外结束

c++ - 谐波级数和 c++ openMP

c++ - 为什么我的字符串只接受三个字符?

c++ - 正则表达式以匹配sql where条件

c++ - UTF8 字符是否有分隔符字节?

php - 如何对多个数组进行 m​​ysql UPDATE

haskell - Rand 的 MonadParallel 实例

python - 与 matlab 并行运行 python 脚本