码迷,mamicode.com
首页 > 编程语言 > 详细

D语言中的algorithm过一遍

时间:2016-08-07 06:19:09      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

参考https://dlang.org/phobos/std_algorithm.html

    在std.algorithm中提供了大量操作Range的函数。一共分为六大类。

一、Searching  搜索

     1) all  判断函数,是否集合中所有元素是否都符合条件

auto arr = [1, 3, 5, 7, 9];
auto ret1 = arr.all!(f=> f != 2);
auto ret2 = arr.all!"a!=2"();
writeln(ret1);
writeln(ret2);
//输出
//true
//true

     2) any   判断函数,是否存在任意一个元素符合条件

auto arr = [1, 3, 5, 7, 9];
auto ret1 = arr.any!(f=> f == 3);
auto ret2 = arr.any!"a==3"();
writeln(ret1);
writeln(ret2);
//输出
//true
//true

     3) balancedParens    检测元素是否能完全配对

auto str1 = "1 + (2 * (3 + 1 / 2)";
auto str2 = "1 + (2 * (3 + 1 / 2))";
auto ret1 = str1.balancedParens(‘(‘,‘)‘);
auto ret2 = str2.balancedParens(‘(‘,‘)‘);
writeln(ret1);
writeln(ret2);
//输出
//false
//true

     4) boyerMooreFinder

     5) canFind

     6) count

     7) countUntil

     8) commonPrefix

     9) endsWith

     10) find

     11) findAdjacent

     13) findAmong

     14) findSkip

     15) findSplit

     16) findSplitAfter

     17) findSplitBefore

     18) minCount

     19) maxCount

     20) minPos

     21) maxPos

     22) mismatch

     23) skipOver

     24) startsWith

     25) until

 

二、Comparison  比较

 

三、Iteration   迭代

 

四、Sorting  排序

 

五、Set operations  集合运算

 

六、Mutation  变换

D语言中的algorithm过一遍

标签:

原文地址:http://www.cnblogs.com/wanhongnan/p/5745324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!