So I think a more useful implementation of add() could look like this:
But I don't think we should just immediately make the stats classes mutable without thinking things through more, I'm not sure there is really any problem creating new objects (we should benchmark this, before making things mutable).
maybe we should not have add() here then at all and let the consumer take care of this themselves.
should be treated as 0, i.e. it should not "reset" the accumulated value from other shards to -1, right?
i think it must not be treated as 0, the same way its handled by default in TermContext if some segments are 3.x: it means this statistic is simply not supported.
In other words, if any segment across any shard returns -1, the cumulative stat should always be -1: it means its not supported by the codec.
The similarities that use these new statistics already look for -1 and have fallback mechanisms for this case.