jaideeppyne commented on PR #517:
URL: https://github.com/apache/datasketches-cpp/pull/517#issuecomment-5472897508

   Vouched, and I went and read it rather than taking my own word for it.
   
   `EmptyCompactSketch` says it in the source:
   
   ```java
   //For backward compatibility, a candidate long must have Flags= compact, 
read-only,
   //  COMPACT-Family=3, SerVer=3, PreLongs=1, and be exactly 8 bytes long. The 
seedHash is ignored.
   // NOTE: The empty and ordered flags may or may not be set
   private static final long EMPTY_SKETCH_MASK = 0X00_00_EB_00_00_FF_FF_FFL;
   private static final long EMPTY_SKETCH_TEST = 0X00_00_0A_00_00_03_03_01L;
   static final byte[] EMPTY_COMPACT_SKETCH_ARR = { 1, 3, 3, 0, 0, 0x1E, 0, 0 };
   ```
   
   Two things line up with what you said. The serialized array carries `0, 0` 
in the seed hash position, so Java writes zeros rather than a computed hash. 
And the mask has `00_00` in its top two bytes, so those same two bytes are 
excluded from the recognition test, which is what makes "the seedHash is 
ignored" structural rather than just a convention. The `0xEB` in the flags byte 
is the other half of the backward compatibility you mentioned, since it lets 
the empty and ordered bits be either way.
   
   On scope, this PR only does the read half. It stops `theta_a_not_b` throwing 
on an empty B, which brings it in line with `theta_union_base::update`, 
`theta_intersection_base::update` and `deserialize_v3/v4`, all three of which 
already exempt empty sketches. It does not change what C++ writes: 
`compact_theta_sketch_alloc` takes `seed_hash_(other.get_seed_hash())`, so an 
empty compact sketch still serializes `compute_seed_hash(seed)` and that is the 
remaining difference from Java, 6 of the 20 cases I diffed on #460.
   
   Happy to do the write half too, emitting a zero seed hash for empty compact 
sketches to match `EMPTY_COMPACT_SKETCH_ARR`. I did not put it here because it 
changes bytes on the wire and felt like it deserved its own PR and your call on 
release timing, rather than being folded into a one line read fix. Say which 
you prefer and I will do it that way.


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