当前位置: 首页 > news >正文

金堂做网站的公司pageadmin系统

金堂做网站的公司,pageadmin系统,谷歌浏览器下载安卓版,备案 网站负责人 法人本文档演示了如何使用筛选器函数,使异步消息块能够根据消息的有效负载接受或拒绝消息。 创建消息块对象(例如 concurrency::unbounded_buffer、concurrency::call 或 concurrency::transformer)时,可以提供筛选器函数,用于确定消息块是接受还…

本文档演示了如何使用筛选器函数,使异步消息块能够根据消息的有效负载接受或拒绝消息。

创建消息块对象(例如 concurrency::unbounded_buffer、concurrency::call 或 concurrency::transformer)时,可以提供筛选器函数,用于确定消息块是接受还是拒绝消息。 筛选器函数是保证消息块仅接收特定值的有效方式。

筛选器函数很重要,因为它们使你能够连接消息块以形成数据流网络。 在数据流网络中,消息块通过仅处理满足特定标准的消息来控制数据流。 将数据流网络与控制流模型进行比较,在后者中,数据流是通过使用条件语句、循环等控制结构来调节的。

本文档提供了有关如何使用消息筛选器的基本示例。 

示例:count_primes 函数

考虑以下函数 count_primes,该函数说明了不筛选传入消息的消息块的基本用法。 此消息块将质数追加到 std::vector 对象。 count_primes 函数将几个数字发送到消息块,从消息块接收输出值,并将这些数字打印到控制台。

// Illustrates usage of a message buffer that does not use filtering.
void count_primes(unsigned long random_seed)
{// Holds prime numbers.vector<unsigned long> primes;// Adds numbers that are prime to the vector object.transformer<unsigned long, unsigned long> t([&primes](unsigned long n) -> unsigned long{if (is_prime(n)){primes.push_back(n);}return n;});// Send random values to the message buffer.mt19937 generator(random_seed);for (int i = 0; i < 20; ++i){send(t, static_cast<unsigned long>(generator()%10000));}// Receive from the message buffer the same number of times// to ensure that the message buffer has processed each message.for (int i = 0; i < 20; ++i){receive(t);}// Print the prime numbers to the console.wcout << L"The following numbers are prime: " << endl;for(unsigned long prime : primes){wcout << prime << endl;}
}

transformer 对象处理所有输入值;但是,它只需要那些为质数的值。 尽管可以编写应用程序以使消息发送方仅发送质数,但并不能始终得知消息接收方的要求。

示例:count_primes_filter 函数

以下函数 count_primes_filter 执行与 count_primes 函数相同的任务。 但是,此版本中的 transformer 对象使用筛选器函数以便仅接受那些为质数的值。 执行该操作的函数仅接收质数;因此,它不必调用 is_prime 函数。

由于 transformer 对象仅接收质数,所以 transformer 对象本身可以保存质数。 换言之,此示例中的 transformer 对象不需要将质数添加到 vector 对象。

// Illustrates usage of a message buffer that uses filtering.
void count_primes_filter(unsigned long random_seed)
{// Accepts numbers that are prime.transformer<unsigned long, unsigned long> t([](unsigned long n) -> unsigned long{// The filter function guarantees that the input value is prime.// Return the input value.return n;},nullptr,[](unsigned long n) -> bool{// Filter only values that are prime.return is_prime(n);});// Send random values to the message buffer.mt19937 generator(random_seed);size_t prime_count = 0;for (int i = 0; i < 20; ++i){if (send(t, static_cast<unsigned long>(generator()%10000))){++prime_count;}}// Print the prime numbers to the console. wcout << L"The following numbers are prime: " << endl;while (prime_count-- > 0){wcout << receive(t) << endl;}
}

transformer 对象现在仅处理那些为质数的值。 在前面的示例中,transformer 对象处理所有消息。 因此,前面的示例必须接收与其发送的相同数量的消息。 此示例使用 concurrency::send 函数的结果来确定要从 transformer 对象接收的消息数。 send 函数在消息缓冲区接受消息时返回 true,在消息缓冲区拒绝消息时返回 false。 因此,消息缓冲区接受消息的次数与质数的计数相匹配。

示例:已完成的消息块筛选器代码示例

以下代码显示完整示例。 该示例同时调用 count_primes 函数和 count_primes_filter 函数。

// primes-filter.cpp
// compile with: /EHsc
#include <agents.h>
#include <algorithm>
#include <iostream>
#include <random>using namespace concurrency;
using namespace std;// Determines whether the input value is prime.
bool is_prime(unsigned long n)
{if (n < 2)return false;for (unsigned long i = 2; i < n; ++i){if ((n % i) == 0)return false;}return true;
}// Illustrates usage of a message buffer that does not use filtering.
void count_primes(unsigned long random_seed)
{// Holds prime numbers.vector<unsigned long> primes;// Adds numbers that are prime to the vector object.transformer<unsigned long, unsigned long> t([&primes](unsigned long n) -> unsigned long{if (is_prime(n)){primes.push_back(n);}return n;});// Send random values to the message buffer.mt19937 generator(random_seed);for (int i = 0; i < 20; ++i){send(t, static_cast<unsigned long>(generator()%10000));}// Receive from the message buffer the same number of times// to ensure that the message buffer has processed each message.for (int i = 0; i < 20; ++i){receive(t);}// Print the prime numbers to the console.wcout << L"The following numbers are prime: " << endl;for(unsigned long prime : primes){wcout << prime << endl;}
}// Illustrates usage of a message buffer that uses filtering.
void count_primes_filter(unsigned long random_seed)
{// Accepts numbers that are prime.transformer<unsigned long, unsigned long> t([](unsigned long n) -> unsigned long{// The filter function guarantees that the input value is prime.// Return the input value.return n;},nullptr,[](unsigned long n) -> bool{// Filter only values that are prime.return is_prime(n);});// Send random values to the message buffer.mt19937 generator(random_seed);size_t prime_count = 0;for (int i = 0; i < 20; ++i){if (send(t, static_cast<unsigned long>(generator()%10000))){++prime_count;}}// Print the prime numbers to the console. wcout << L"The following numbers are prime: " << endl;while (prime_count-- > 0){wcout << receive(t) << endl;}
}int wmain()
{const unsigned long random_seed = 99714;wcout << L"Without filtering:" << endl;count_primes(random_seed);wcout << L"With filtering:" << endl;count_primes_filter(random_seed);/* Output:99739349924188931297712786473229With filtering:The following numbers are prime:99739349924188931297712786473229*/
}
可靠编程

筛选器函数可以是 lambda 函数、函数指针或函数对象。 每个筛选器函数采用以下格式之一:

bool (T)
bool (T const &)

为了消除不必要的数据复制,需要按值传输聚合类型时,请使用第二种格式。 

http://www.yayakq.cn/news/469057/

相关文章:

  • 如何做网站安全扫描自己建网站怎么建
  • 网站请人做要多少钱如何做网销
  • 网站建设售前怎么做好洛阳网站建设建站系统
  • 菜鸟必读 网站被入侵后需做的检测 1建站要多少钱
  • 北京免费网站建设模板下载如何开网站
  • 番禺网站建设gzhchl西安 域名空间网站制作
  • 青海省教育厅门户网站学籍查询搜狗推广下架
  • 山东青岛网站建设公司郑州新一网站建设
  • 网站开发 打标签网站建设空间选择的重要性
  • 湖南网站建设公司 在线磐石网络网站备案的核验单
  • 卓越职业院校建设专题网站杭州营销策划推广公司
  • 国外做蛋糕的网站网站设计联系方式
  • 吉安做网站的公司手机网站实例
  • 谢晶晶的赣州没有网页制作做网站优化需要做哪些事项
  • 建站公司怎么接单发稿媒体平台
  • 怎么样查询建设网站百度推广文案
  • 制作企业网站需要多少钱深圳建设网站费用
  • 电子商务网站的建设过程如何查询网站的建设商
  • 网站最重要的是首页吗怎么查看网站备案
  • 网站建设报价单模板河北网站备案
  • 手机网站免费生成app简易的旅游网页制作
  • 玉林做绿化苗木网站的是哪个单位世界贸易网
  • 网站建设实施方案ppt网站被**泛解析后的解决方法
  • 南京科技网站设计费用网站开发简易软件
  • 北京网站建设华大爱站网长尾关键词挖掘工具的作用
  • 营销型网站建设申请域名时公司类型的域名后缀一般是建设单位发包许可证网站
  • 大型网站开发pdf做网站哪里接单
  • 网站建设动画代码代理网页软件
  • 西安至成网站建设公司小公司网络组建
  • 产品网站建设公司哪家好网络公司除了建网站