arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1602.06426cs.DS
收藏

产生下一个Dyck字的无环无分支$O(1)$算法

A loopless and branchless $O(1)$ algorithm to generate the next Dyck word

Cassio Neri

摘要:

设integer为任意C/C++无符号整型类型,最长为64位。给定一个Dyck字,下面的代码返回下一个相同大小的Dyck字,前提是它存在。integer next_dyck_word(integer w){ integer const a = w & -w; integer const b = w + a; integer c = w ^ b; c =(c / a >> 2)+ 1; c =((c * c - 1)& 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| return c; }

英文摘要:

Let integer be any C/C++ unsigned integer type up to 64-bits long. Given a Dyck word the following code returns the next Dyck word of the same size, provided it exists. integer next_dyck_word(integer w) { integer const a = w & -w; integer const b = w + a; integer c = w ^ b; c = (c / a >> 2) + 1; c = ((c * c - 1) & 0xaaaaaaaaaaaaaaaa) | b; return c; }

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑