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


##########
src/tdigest/serialization.rs:
##########
@@ -17,6 +41,45 @@ impl TDigest {
         });
         bytes.push(SERIAL_VERSION);
         bytes.push(TDIGEST_FAMILY_ID);
+        LE::write_u16(&mut bytes, self.k);
+        bytes.push({
+            let mut flags = 0;
+            if self.is_empty() {
+                flags |= FLAGS_IS_EMPTY;
+            }
+            if self.is_single_value() {
+                flags |= FLAGS_IS_SINGLE_VALUE;
+            }
+            if self.reverse_merge {
+                flags |= FLAGS_REVERSE_MERGE;
+            }
+            flags
+        });
+        LE::write_u16(&mut bytes, 0); // unused
+        if self.is_empty() {
+            return bytes;
+        }
+        if self.is_single_value() {
+            LE::write_f64(&mut bytes, self.min);
+            return bytes;
+        }
+        LE::write_u32(&mut bytes, self.centroids.len() as u32);

Review Comment:
   Not sure if this can result in data loss. Seems possible if `self.k = 
u16::MAX` and thus the largets cap is `u16::MAX * 2 + 10 > u32::MAX`.



-- 
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