范围/线段树 Ruby

发布于 2024-11-28 22:19:01 字数 73 浏览 1 评论 0原文

我正在寻找 Ruby 中的范围或段树实现。我找不到任何可用的样品或宝石。

有人有示例代码吗?

谢谢,

I am looking for a range or segment tree implementation in Ruby. I could not find any sample or gem available.

Does anyone have a sample code ?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冧九 2024-12-05 22:19:01

看起来有一个叫做 interval-tree,repo 在这里,https:// github.com/gam3/interval-tree 和这里 https://github.com/misshie/区间树。看起来似乎是后者制造了这个东西,但红宝石上的宝石指向了前者。很奇怪。

存储库和其他地方的文档都是错误的。要使用它,请使用 IntervalTree::InclusiveTree.newIntervalTree::ExclusiveTree.new。这在任何地方都没有记录,这很奇怪。另外,同样奇怪的是,不可能向 github 存储库添加问题来解决此问题。我正在考虑分叉并制作一个可以由社区维护的新版本。

不管怎样,这是你如何使用它的:

require "interval-tree"

itv = [(0...3), (1...4), (3...5),]
t = IntervalTree::Tree.new(itv)
p t.search(2) => [0...3, 1...4]
p t.search(1...3) => [0...3, 1...4, 3...5]

正如你所看到的,require 语句在存储库中也被错误地记录。真是一团糟。

There looks to be one called interval-tree, repo is here, https://github.com/gam3/interval-tree and here https://github.com/misshie/interval-tree. It seems like it is the later who made the thing, but the gem on rubygems points to the first. Very strange.

The documentation is wrong on the repo and everywhere else. To use it, use either IntervalTree::InclusiveTree.new or IntervalTree::ExclusiveTree.new. This is not documented anywhere which is strange. Also, equally strange, it is not possible to add issues to the github repo to fix this. I am considering forking and making a new version which can be maintained by the community.

Anyways, here is how you use it:

require "interval-tree"

itv = [(0...3), (1...4), (3...5),]
t = IntervalTree::Tree.new(itv)
p t.search(2) => [0...3, 1...4]
p t.search(1...3) => [0...3, 1...4, 3...5]

As you see, also the require statement is wrongly documented in the repo. What a mess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文