How Can Be Adding a New Item to a Dynamic Array Achieved in Constant Time?

Based on the previous article titled “Exploring Internal Implementation of Go Slice,” we know that a dynamic array is a data structure that can grow and shrink as needed, which is called resizing. As seen in the implementation, resizing is an expensive operation because it involves copying all the items from the old array to the new array. This resizing is performed only when the array is full. Since the capacity is doubled each time the array is resized, the resizing operation will be less frequent as the array grows....

October 27, 2023 · 4 min · 704 words · Jose Sitanggang

A Simple Proof of XOR Uniqueness

I have a simple algorithm to conceal an auto-increment ID within a globally unique identifier such as UUIDv4, which involves XOR. The motivation behind this algorithm is to eliminate the predictability of the auto-increment ID when it’s exposed in a URL1. I can use UUID directly, but indexing UUIDs in MySQL has a significant performance impact2. UUID is necessary for security, while the auto-increment ID is essential for performance. This algorithm combines the best of both worlds....

September 23, 2023 · 4 min · 675 words · Jose Sitanggang