News for hackers. Stuff that matters.
Re:Static search trees: 40x faster than binary search by shawn_w on Tuesday December 31, 2024 @11:22PM (#42563931)
Fluent in C and C++ among others, know nothing about Rust. It's mostly easy to follow, but I'm having trouble with notation like `&[u32]` and `&[u32; P]`. Arrays that hold unsigned 32 bit integers? But there's `Vec<u32>` which also seems like an array type? Is it like the difference between C++ primitive arrays and std::vector?
Re:Static search trees: 40x faster than binary search by dwattttt on Wednesday January 01, 2025 @12:03AM (#42564083)
For `&[u32]` and `&[u32; P]`, those are both references to an array of unsigned 32 but integers, however the former is to an array of any size (and carries its size at runtime), whereas the latter is to an array with an explicitly known size at compile time. It's unusual in C, I think you can express it as `int[24] *` (or possibly some other permutation, I'm away from a compiler).

Vec<u32> is pretty much like std::vector compared to them, yeah.

Re:Static search trees: 40x faster than binary search by loeg on Wednesday January 01, 2025 @01:16AM (#42564288)
`&[u32]` is essentially `std::span<const uint32_t>`.

`&[u32; P]` is similarly something like `std::span<const uint32_t, P>`.

`[u32; P]` (no `&`) is essentially `std::array<uint32_t, P>`.

`Vec<u32>` is essentially `std::vector<uint32_t>`, yes.

Re:Static search trees: 40x faster than binary search by shawn_w on Wednesday January 01, 2025 @12:54PM (#42567698)
Thanks