[英]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
具有takeWhileR
和dropWhileR
用于从右侧有效地解构Seq
。 However, takeR
, dropR
and splitAtR
are conspicuously absent. 然而, takeR
, dropR
和splitAtR
显然不存在。 take
and drop
are implemented in terms of splitAt
. take
和drop
是根据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.