Improved p-fast Trie: A Highly Efficient Prefix Matching Algorithm

2025-08-10

This article presents an improved p-fast trie data structure, a highly efficient algorithm for finding the longest matching prefix or nearest predecessor/successor of a query string in a set of strings. Compared to previous versions, this improved version is more concise and space-efficient. It uses a hash table to store each unique prefix and a bitmap to represent the possible next characters for each prefix, achieving O(log k) time complexity (where k is the key length). While predecessor searches might require more probes, its performance still surpasses traditional qp-tries.

Read more
Development prefix matching

Compiler Optimization: Improving Lemire's Nearly Divisionless Random Number Generation

2025-03-09

The author improved a nearly divisionless algorithm for generating bounded random numbers (Lemire's algorithm). A previous version reduced code bloat by inlining the fast path, but compiler optimization was limited. The author discovered that when the limit is a compile-time constant, the rejection threshold can be precomputed, and division avoidance is unnecessary. The new implementation has only one call to the random number generator, and the compiler automatically eliminates the loop when the limit is a power of two. This is more efficient than last year's version, and the author explores similar compile-time optimization techniques in Rust.

Read more