哈斯克尔山脉地图库
是否有 Haskell 库允许我拥有从范围到值的映射? (最好有点效率。)
let myRangeMap = RangeMap [(range 1 3, "foo"),(range 2 7, "bar"),(range 9 12, "baz")]
in rangeValues 2
==> ["foo","bar"]
Is there a Haskell library that allows me to have a Map from ranges to values? (Preferable somewhat efficient.)
let myRangeMap = RangeMap [(range 1 3, "foo"),(range 2 7, "bar"),(range 9 12, "baz")]
in rangeValues 2
==> ["foo","bar"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我编写了一个库来以重叠的间隔进行搜索,因为现有的库不符合我的需求。我认为它可能有一个比 SegmentTree 更平易近人的界面:
https:// www.chr-breitkopf.de/comp/IntervalMap/index.html
它也可以在 Hackage 上找到:https://hackage.haskell.org/package/IntervalMap
I've written a library to search in overlapping intervals because the existing ones did not fit my needs. I think it may have a more approachable interface than for example SegmentTree:
https://www.chr-breitkopf.de/comp/IntervalMap/index.html
It's also available on Hackage: https://hackage.haskell.org/package/IntervalMap
此任务称为对一组间隔进行刺探查询。其有效的数据结构称为(一维)线段树。
SegmentTree 包 提供了此数据结构的实现,但不幸的是我不知道如何使用它。 (我觉得这个包的接口没有提供正确的抽象级别。)
This task is called a stabbing query on a set of intervals. An efficient data structure for it is called (one-dimensional) segment tree.
The SegmentTree package provides an implementation of this data structure, but unfortunately I cannot figure out how to use it. (I feel that the interface of this package does not provide the right level of abstraction.)
也许
rangemin
库 可以满足您的需求?好的旧
Data.Map
(及其更高效的Data.IntMap
表兄弟)有一个函数,可以将映射拆分为小于/大于给定键的键的子映射。这可用于某些类型的范围搜索。
Perhaps the
rangemin
library does what you want?Good old
Data.Map
(and its more efficientData.IntMap
cousin) has a functionwhich splits a map into submaps of keys less than / greater than a given key. This can be used for certain kinds of range searching.