Implement quad search#355
Conversation
88d5688 to
aef5af1
Compare
| } | ||
|
|
||
| #[inline] | ||
| pub fn quad_contains(slice: &[u16], val: u16) -> bool { |
There was a problem hiding this comment.
I am wondering whether I should introduce this function, since it is used only once in the ArrayStore::contains method, or simply use the quad_search(...).is_ok() function that returns the position where the number is found or should be.
| let v0 = u16x8::from_slice(&chunks[lo][..GAP / 2]); | ||
| let v1 = u16x8::from_slice(&chunks[lo][GAP / 2..]); |
There was a problem hiding this comment.
This from_slice method panics if the slice is too small; we need to check the generated assembler to see if it can avoid this redundant check.
| return match (v0.simd_ge(ndl).first_set(), v1.simd_ge(ndl).first_set()) { | ||
| (Some(i), _) if v0[i] == val => Ok(base_index + i), | ||
| (Some(i), _) => Err(base_index + i), | ||
| (_, Some(i)) if v1[i] == val => Ok(base_index + GAP / 2 + i), | ||
| (_, Some(i)) => Err(base_index + GAP / 2 + i), | ||
| (None, None) => Err(slice.len()), | ||
| }; |
There was a problem hiding this comment.
I am wondering if this is the best approach to take to compute the position where the needle is/should be located, or if I can do something else, less expensive than two simd_ge plus two first_set?
|
Hey @Dr-Emann 👋 I know that you like this kind of SIMD-based code, so if you want and have time to review this, I would be glad you do 🙏 If you don't have time, no worries 👍 Have a nice day 🌵 |
This PR implements the SIMD-based Quad search described by Daniel Lemire in this blog post, and fixes #234.