I implemented equals only for testing purposes (see TestSegmentMerger.java) and then hashCode for consistency. I can move the equals code to the test case if you prefer.
Ahh, OK. Yeah I think move it to the test case? Thanks.
There used to be an assert in SegmentMerger but it was removed in r1148938
Ahh you're right! Hmm, but, we actually know the accurate delCount higher up; let me tweak the patch a bit to pass this down, so we don't have to re-count it separately.
so I assumed the numDeletedDocs() was unreliable and the del count should be computed from liveDocs. I am not familiar enough with the merge process to know whether some invariants are broken or not. Should I open a bug?
As far as I know, it's only unreliable in this context (SegmentReader passed to SegmentMerger for merging); this is because we allow newly marked deleted docs to happen concurrently up until the moment we need to pass the SR instance to the merger (search for "// Must sync to ensure BufferedDeletesStream" in IndexWriter.java) ... but it would be nice to fix that, so I think open a new issue (it won't block this one)? We should be able to make a new SR instance, sharing the same core as the current one but using the correct delCount...