简体   繁体   English

为什么Data.Sequence中缺少takeR,dropR和splitAtR?

[英]Why are takeR, dropR and splitAtR missing from Data.Sequence?

Data.Sequence has takeWhileR and dropWhileR for efficient deconstruction of Seq s from the right. Data.Sequence具有takeWhileRdropWhileR用于从右侧有效地解构Seq However, takeR , dropR and splitAtR are conspicuously absent. 然而, takeRdropRsplitAtR显然不存在。 take and drop are implemented in terms of splitAt . takedrop是根据splitAt So, do finger trees not admit an efficient splitAtR or was this functionality not included for some other reason? 那么,手指树是否不允许有效的splitAtR或者由于其他原因而不包含此功能?

(Separate but somewhat related question: Would a naive dropR implementation in terms of viewR perform decently well?) (单独但有些相关的问题:就viewR来说,一个天真的dropR实现viewR表现得不错吗?)

This question is based on containers-0.5.6.3 . 这个问题基于containers-0.5.6.3

length is O(1), so splitAt suffices to define everything you need, in an efficient way. length为O(1),因此splitAt足以以有效的方式定义您需要的所有内容。

 splitAtR i s = splitAt (length s - i) s
 takeR i s = snd $ splitAtR i s
 dropR i s = fst $ splitAtR i s

According to the docs, splitAt costs O(log(min(i,length si))) , so by symmetry splitAtR costs the same (just an additional +O(1) , which we can neglect). 根据文档, splitAt成本为O(log(min(i,length si))) ,因此通过对称splitAtR成本相同(只是额外的+O(1) ,我们可以忽略)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM