是F#映射的迭代还是设置顺序遍历? [英] Is an iteration on a F# map or set in-order traversal?

查看:101
本文介绍了是F#映射的迭代还是设置顺序遍历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AFAIK,F#映射和集合被实现为红黑树,所以我猜这些迭代将是按顺序遍历的。我做了一些测试,迭代结果总是排序。但是我想确保这一点。



是否按顺序遍历?

解决方案

MSDN上的文档对于了解这一点是非常好的。例如, Set.toSeq 是集合元素的有序序列。看起来你的问题的答案是肯定的,对于地图和集合。


AFAIK, F# Map and set are implemented as red-black trees, so I guess that an iteration on these would be in-order traversal. I did some test and the iteration results are always sorted. But I want to make it sure.

Is it in-order traversal?

解决方案

The documentation on MSDN is pretty good for figuring this out. For instance, the return value for Set.toSeq is "An ordered sequence of the elements of set." It looks like the answer to your question is yes, for both maps and sets.

这篇关于是F#映射的迭代还是设置顺序遍历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆