OpenHFT / Zero-Allocation-Hashing

Zero-allocation hashing for Java
Apache License 2.0
788 stars 136 forks source link

Add new api for more than 64-bit hash #34

Closed gzm55 closed 4 years ago

gzm55 commented 4 years ago

Add an interface LongTupleHashFunction which extends the 64-bit LongHashFunction. The new interface add two sets of APIs while keeping compatible to the original long API:

  1. long hash(..., long[] result);
  2. long[] hashTuple(...);

Among three sets of the hash API, the real work will appear in the long hash(..., long[] result) style functions which should returns result[0] as the direct result. The other sets can be deduced from this style ones.

In the mean time, the implementation of LongTupleHashFunction must override bits() function providing the real bits of this function. The result of bits() should be larger than 64, but don't have to be divided by 64.

I choose long[] for the result container since it is very simple and can be optimized by JIT. When developing a long hash(..., long[] result), we just need to check if the result is null, which means omitting the full result, and don't have to checkresult.length(). LongTupleHashFunction provides a newLongTuple() function to alloc a correct array based on bits().

Since a result container can be easily reused within one thread, so the cost of allocation could trend to zero.

Murmur3F 128-bit has been migrated to `LongTupleHashFunction'.

leventov commented 4 years ago

@gzm55 do you want to become a maintainer of the library? You could consult @peter-lawrey for getting credentials to be able to push new releases to net.openhft groupId.

gzm55 commented 4 years ago

@gzm55 do you want to become a maintainer of the library? You could consult @peter-lawrey for getting credentials to be able to push new releases to net.openhft groupId.

yeah, i'd like to, and will consult @peter-k-lawrey for the requirements and info.

RobAustin commented 4 years ago

@gzm55 I will grant you write access.

RobAustin commented 4 years ago

@leventov are you ok if I grant @gzm55 https://github.com/gzm55 write access ?

leventov commented 4 years ago

@RobAustin I'm ok but it's not enough, permissions should also be granted to net.openhft groupId in https://issues.sonatype.org/browse/OSSRH

dpisklov commented 4 years ago

we (chronicle) can deal with releases for now I think, let's grant write permissions to @gzm55 and see how it works.

gzm55 commented 4 years ago

we (chronicle) can deal with releases for now I think, let's grant write permissions to @gzm55 and see how it works.

@leventov @RobAustin @dpisklov i have joined, thanks very much.

gzm55 commented 4 years ago

@leventov update as previous discussion. java docs are not complete, so plz just review the api.

leventov commented 4 years ago

Looks good.

gzm55 commented 4 years ago

@leventov java docs are complete

gzm55 commented 4 years ago

@leventov update the class level document and method document before hashChar() (there is a TODO mark there), if they're ok, i will finish the following javadoc.

gzm55 commented 4 years ago

@leventov update based on the previous review, and still left some javadoc below TODO mark. I hope to finish the docs this weekend.

gzm55 commented 4 years ago

@leventov package/class/method level documents are all ready.

gzm55 commented 4 years ago

@leventov any suggestions? Or if busy, we can improve docs after merging into master.

leventov commented 4 years ago

@gzm55 please go ahead