tisonkun commented on code in PR #210:
URL: https://github.com/apache/datasketches-rust/pull/210#discussion_r3848768284


##########
datasketches/tests/serde_tests/tdigest.rs:
##########
@@ -25,6 +26,47 @@ use googletest::prelude::near;
 
 use crate::serialization_test_data;
 
+fn fnv1a(bytes: &[u8]) -> u64 {
+    bytes.iter().fold(0xcbf2_9ce4_8422_2325, |hash, byte| {
+        (hash ^ u64::from(*byte)).wrapping_mul(0x0000_0100_0000_01b3)
+    })
+}
+
+fn patterned_digest(k: u16, len: usize, salt: usize) -> TDigestMut {
+    let mut tdigest = TDigestMut::new(k);
+    for index in 0..len {
+        let value = (((index * 37 + salt * 17) % 101) as f64) - 50.0;
+        tdigest.update(value);
+    }
+    tdigest
+}
+
+fn native_image(
+    k: u16,
+    reverse_merge: bool,
+    min: f64,
+    max: f64,
+    centroids: &[(f64, u64)],
+    buffered: &[f64],
+) -> Vec<u8> {
+    let mut bytes = Vec::with_capacity(32 + size_of_val(centroids) + 
size_of_val(buffered));
+    bytes.extend_from_slice(&[2, 1, 20]); // preamble longs, serial version, 
family
+    bytes.extend_from_slice(&k.to_le_bytes());
+    bytes.extend_from_slice(&[if reverse_merge { 4 } else { 0 }, 0, 0]);
+    bytes.extend_from_slice(&(centroids.len() as u32).to_le_bytes());
+    bytes.extend_from_slice(&(buffered.len() as u32).to_le_bytes());
+    bytes.extend_from_slice(&min.to_le_bytes());
+    bytes.extend_from_slice(&max.to_le_bytes());
+    for &(mean, weight) in centroids {
+        bytes.extend_from_slice(&mean.to_le_bytes());
+        bytes.extend_from_slice(&weight.to_le_bytes());
+    }
+    for value in buffered {
+        bytes.extend_from_slice(&value.to_le_bytes());
+    }
+    bytes
+}

Review Comment:
   Resolved below.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to