## Monthly Archives: October 2022

### Rust – Fast manipulation of a vector behind a HashMap using RefCell

Let’s analyze a function which maintains some 3×1 f64 vectors for plotting. There are multiple vectors and each of them is behind an enum key of a HashMap. Hasmap is a member property of a struct, so it looks something like this: We have a function log_debug_data which will record the current position of a…

### Rust’s Copy trait – An example of a Vec inside a struct

While implementing a very primitive molecular dynamics simulator from scratch in Rust, I have encountered an interesting corner case I believe is worth sharing with anyone learning Rust. Among other artifacts, I have set up a primitive model class for storing some information about a single Particle in a file particle.rs: Nothing fancy, just some…

### Leetcode 2429 – Minimize XOR

Source: https://leetcode.com/problems/minimize-xor/ Problem statement Given two positive integers num1 and num2, find the integer x such that: x has the same number of set bits as num2, and The value x XOR num1 is minimal. Note that XOR is the bitwise XOR operation. Return the integer x. The test cases are generated such that x…