将区间编码为用于交集查询的字符串 实际目标到目前为止我尝试过的

问题描述

目标是检查两个间隔是否相交。容易……对吧?只需插入这个家伙,我们就可以继续前进?

        [master f6aa9c6] chore: release 0.0.2
         2 files changed,4 insertions(+),3 deletions(-)
        Updated tag 'v0.0.2' (was 4cc5955)
        To https://gitlab.com/jx5/PHP-test.git
         + 4cc5955...91ae836 v0.0.2 -> v0.0.2 (forced update)
        Using batch mode as inside a pipeline
        about to run: git for-each-ref --sort=-creatordate --format=%(objectname)%00%(refname:short) --count=2 refs/tags in dir .
        91ae8362f782e9b10f994ef05e3baab7c143eb4fv0.0.2
        8e0b3aa673dfc553cd377064a662dc6ae12a00aav0.0.1
        about to run: git rev-list -n 1 8e0b3aa673dfc553cd377064a662dc6ae12a00aa in dir .
        121f4dd3da5bac2d14b15b0974f390a9e2879801
        about to run: git for-each-ref --sort=-creatordate --format=%(objectname)%00%(refname:short) --count=1 refs/tags in dir .
        91ae8362f782e9b10f994ef05e3baab7c143eb4fv0.0.2
        about to run: git rev-list -n 1 91ae8362f782e9b10f994ef05e3baab7c143eb4f in dir .
        f6aa9c6e8b7c59189679cf2da7fce79bf26727ee
        Generating change log from git ref 121f4dd3da5bac2d14b15b0974f390a9e2879801 => f6aa9c6e8b7c59189679cf2da7fce79bf26727ee
        Finding issues in commit messages using git format
        about to run: git tag --list v0.0.2 in dir .
        v0.0.2
        about to run: git tag --list vv0.0.2 in dir .
        error: Failed to query release on repo jx5/PHP-test for tag v0.0.2: Not Found
        
        Pipeline Failed on stage 'from-build-pack' : container 'step-promote-changelog'. The execution of the pipeline has stopped.

没那么快,我们有以下限制:

  • 我们不能在交叉检查期间直接使用候选项目的区间。我们必须对区间 intersects = itemStart < queryEnd && queryStart < itemEnd 进行预处理。编码的项目间隔必须是数字或字符串。但是,我们可以在检查期间单独使用或不使用 [itemStart,itemEnd] => encodedItem
  • 在执行交集检查时,我们仅限于以下操作:[queryStart,queryEnd]beginsWith。不能应用更多的布尔运算符。 (这些是 dynamodb 的限制)。
    • between 检查字符串 a 是否以字符串 b 开头。
    • beginsWith(a,b) 检查 a 是否在 b 和 c 之间。适用于字符串和数字。
  • 项目的开始值和结束值在 between(a,b,c) 范围内。

总而言之,最终的交叉检查必须采用以下两种形式之一:

[0,3254778254386]
intersects = between(encodedItem,encodedQueryStart,encodedQueryEnd)

也许有一个数学证明,将二维区间展平为一维可以防止我们检查区间是否相交。


实际目标

虽然我对随机字符串问题感兴趣作为消遣,但这个问题背后存在一个现实世界的问题。我正在尝试对键值数据库执行日期范围交叉查询,在本例中为 dynamodb


到目前为止我尝试过的

Z 顺序

我一直在研究地理空间索引和 Z-Ordering,这让我相信这是可能的。 [0][1][2][3] 使用 Z 排序,您可以通过将间隔插入一个字符串来确定查询间隔是否包含另一个

例如

intersects = beginsWith(encodedItem,encodedQuery)

一旦这个预处理完成,我就可以了

            itemA = { start: 123,end: 456 }
     encodedItemA = "142536"
            itemB = { start: 111,end: 115 }
     encodedItemB = "111115"
            query = { start: 110,end: 119 }
encodedQueryStart = "111100" // interleave query.start with itself
  encodedQueryEnd = "111199" // interleave query.end with itself

然而,“isContained”与“intersects”不同。

冗余

我探索的另一件事是扩展每个项目,使其不再是一个间隔,而是由许多点表示,便于前缀搜索。例如

isContained = between(encodedItem,encodedQueryEnd)
isContained = between("142536","111100","111199") // returns false ✅
isContained = between("111115","111199") // returns true ✅

这有其自身的权衡。


我可以尝试使用其他任何聪明的魔法吗? ?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...