aherbert commented on PR #357:
URL:
https://github.com/apache/commons-collections/pull/357#issuecomment-1307849658
IIUC the use of `isEmpty` is to prevent a client sending an empty something
to a server which would waste its time, or use it as a signal. The former seems
like an error by the client (or a denial of service attack); the later can be
achieved by other means, for example sending empty/signalling bytes before
deserialisation on the server side. This would avoid having to create the
(empty) HasherCollection altogether.
It seems like quite an edge case scenario. If you have to use an empty
Hasher as a signal then it can be done on the server side using:
```Java
static boolean isEmpty(Hasher h) {
boolean[] flag = {true};
// Shape can be precomputed for this purpose
h.indices(Shape.fromKM(1, 1)).forEachIndex(i -> flag[0] = false);
return flag[0];
}
```
If you have to deserialise the input bytes to a Hasher then just do it as a
customisation of your choice of Hasher with an `isEmpty` method. If you are
using an EnhancedDoubleHasher then note that this cannot be "empty" even if the
initial and increment are zero given that Shape numberOfHash functions is
always `> 0` so at least 1 index will be output.
In general any Hasher should output indices. If you created a hasher that
contains nothing, this itself is something that should generate output indices.
The Hasher simply outputs indices based on a source, and ideally the output
sequence is fairly unique among possible input sources.
--
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]