nodedb_codec/vector_quant/opq_rotation.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! Shared utilities for OPQ codebook training.
4
5/// Minimal deterministic RNG (Xorshift64) — avoids external deps in lib code.
6pub(super) struct Xorshift64(u64);
7
8impl Xorshift64 {
9 pub(super) fn new(seed: u64) -> Self {
10 Self(if seed == 0 {
11 0xDEAD_BEEF_CAFE_1234
12 } else {
13 seed
14 })
15 }
16
17 #[inline]
18 pub(super) fn next_u64(&mut self) -> u64 {
19 let mut x = self.0;
20 x ^= x << 13;
21 x ^= x >> 7;
22 x ^= x << 17;
23 self.0 = x;
24 x
25 }
26}