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

TL;DR
This paper presents a highly efficient, loopless, and branchless algorithm that computes the next Dyck word of the same size in constant time using bitwise operations, suitable for 64-bit integers.
Contribution
The authors introduce a novel O(1) algorithm for generating the next Dyck word without loops or branches, improving performance over previous methods.
Findings
Constant-time computation of next Dyck word for 64-bit integers
Loopless and branchless implementation using bitwise operations
Applicable to unsigned integer types up to 64 bits
Abstract
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; }
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsAlgorithms and Data Compression · Natural Language Processing Techniques · Handwritten Text Recognition Techniques
