fulmicoton commented on PR #116:
URL: 
https://github.com/apache/datasketches-rust/pull/116#issuecomment-4237510940

   To bullet proof this, should we introduce a Coupon struct?
   
   ```
   /// A coupon encodes a (slot, value) pair derived from hashing an input.
   ///
   /// Format: `[value (6 bits) << 26] | [slot (26 bits)]`
   ///
   /// The slot identifies an HLL register (derived from the lower bits of the 
hash),
   /// and the value represents the number of leading zeros plus one (from the 
upper bits).
   #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
   pub struct Coupon(u32);
   
   impl Coupon {
       /// Sentinel value indicating an empty coupon slot.
       const EMPTY: Self = Coupon(0);
   
       /// Create a coupon by hashing a value.
       #[inline(always)]
       pub fn from_hash(v: impl Hash) -> Self {
           let mut hasher = MurmurHash3X64128::default();
           v.hash(&mut hasher);
           let (lo, hi) = hasher.finish128();
   
           let addr26 = lo as u32 & KEY_MASK_26;
           let lz = hi.leading_zeros();
           let capped = lz.min(62);
           let value = capped + 1;
   
           Coupon((value << KEY_BITS_26) | addr26)
       }
   
       /// Pack slot number and value into a coupon.
       ///
       /// Format: [value (6 bits) << 26] | [slot (26 bits)]
       #[inline(always)]
       fn pack(slot: u32, value: u8) -> Self {
           Coupon(((value as u32) << KEY_BITS_26) | (slot & KEY_MASK_26))
       }
   
       /// Extract slot number (low 26 bits) from coupon.
       #[inline(always)]
       fn slot(self) -> u32 {
           self.0 & KEY_MASK_26
       }
   
       /// Extract value (upper 6 bits) from coupon.
       #[inline(always)]
       fn value(self) -> u8 {
           (self.0 >> KEY_BITS_26) as u8
       }
   }
   ```


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