haskell / haskell/vector

overlaps for Data.Vector.Mutable behaves oddly for empty vectors

未关闭
#444 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Haskell
星标
400
派生
145
PR 合并指标
30 天内没有已合并 PR

描述

The `basicOverlaps` implementation for Data.Vector.Mutable is:

``` haskell
basicOverlaps (MVector i m arr1) (MVector j n arr2)
= sameMutableArray arr1 arr2
&& (between i j (j+n) || between j i (i+m))
where
between x y z = x >= y && x < z
```

This will return `True` for two vectors where two vectors share the same mutable array and offset, but one has a zero length and the other has a non-zero length. I cannot find a precise definition of what it means for possibly-empty vectors to overlap, so it's hard to say for sure this is wrong, but it certainly disagrees with my understanding of what `overlaps` ought to mean.

I suggest this implementation instead:

``` haskell
basicOverlaps (MVector i m arr1) (MVector j n arr2)
= sameMutableArray arr1 arr2 && i < j + n && j < i + m
```

That will still report an overlap for an empty vector with an offset in the middle of a containing non-empty vector, though. It's even less clear what the right answer is there. So I guess what we really need is a precise specification first, and then we can write an implementation that matches it.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。