为什么大多数时候只是向前遍历?
我注意到许多迭代器或数据读取器仅向前推进 DataReader、XmlReader、IEnumerator,还有更多(你明白了) 。
因此,简单地问为什么它们是仅向前,通常当我为我的自定义需求创建数据迭代器时,我通常会尝试添加对两侧导航的支持。我同意大多数时候我们不需要向后遍历,但有时我们确实需要,因此我们最终创建了 temp
变量或在需要时保存数据的东西。
所以我的问题是:
为什么大多数数据迭代器都是只向前的
创建向后可遍历迭代器时我错了/数据读取器。如果不是,为什么框架不对其内置数据迭代器提供这样的支持。
我们是否有任何严重性能缺陷,或者只是不被认为是具有此类功能的良好设计 .
这个问题从一开始就困扰了我很多,但一直没有得到满意的答案,所以我在这里问这个问题。我相信许多开发人员可能会同意我的观点,即向后遍历有时是有用的。
I have noticed that many iterators or data readers are forward only like DataReader, XmlReader, IEnumerator, any many more (you got the idea).
So simply asking why are they forward-only usually when i create a Data Iterator for my custom needs i usually Try adding support for navigation on both sides. I agree that most of time we don't need backward traversing but sometimes we do need and so we end up creating temp
variables or something to hold on the data while required.
So my questions are:
Why are most Data-Iterators forward-only
Am i wrong in creating a backward traversable Iterator/ Data reader. if not why doesn't framework have such support for its inbuilt Data Iterators.
Do we have any serious performance drawback or its just not considered a good design to have such feature.
This question has bugged me a lot from start but never got a satisfactory answer so I'm asking it here.I do believe many developers may agree with me that backward traversing can be useful sometimes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“仅转发”是:
例如,如果您从数据库、网络流等读取数据,则只能保证“转发”。我们当然不想任意缓冲所有这些数据 - 它可能会巨大。
如果客户端认为他们拥有适量的数据,他们可以随时调用 ToList() 等将其缓冲在内存中并允许随机访问。
例如,考虑这个完全有效序列:
这个例子有点不太可能,但是从套接字读取,数据库,甚至是大文件 - 本质上可能是相同的情况。
"forwards only" is:
for example, if you are reading data from a database, a network stream, etc, you can only guarantee "forwards". We certainly don't want to arbitrarily buffer all that data - it could be huge potentially.
If the client thinks they have a sane amount of data, they can always call
ToList()
etc to buffer it in memory and allow random access.For example, consider this perfectly valid sequence:
obviously that example is a little unlikely, but reading from a socket, database, or even a large file - can be essentially the same scenario.