Add an explanation of quickly hashing onto a non-power of two range. #10577

pull gmaxwell wants to merge 1 commits into bitcoin:master from gmaxwell:hashrange-comment changing 1 files +31 −0
  1. gmaxwell commented at 11:46 PM on June 11, 2017: contributor

    In Olaoluwa Osuntokun's recent protocol proposal they were using a mod in an inner loop. I wanted to suggest a normative protocol change to use the trick we use here, but to find an explanation of it I had to dig up the PR on github. After I posted about it several other developers commented that it was very interesting and they were unaware of it.

    I think ideally the code should be self documenting and help educate other contributors about non-obvious techniques that we use. So I've written a description of the technique with citations for future reference.

  2. fanquake added the label Docs and Output on Jun 12, 2017
  3. laanwj commented at 7:36 AM on June 12, 2017: member
  4. in src/cuckoocache.h:210 in 3dedf120f2 outdated
     205 | @@ -206,6 +206,37 @@ class cache
     206 |      /** compute_hashes is convenience for not having to write out this
     207 |       * expression everywhere we use the hash values of an Element.
     208 |       *
     209 | +     * We need to map the 32-bit input hash onto a hash bucket in a range [0, size) in a
     210 | +     *  manner which preserves as much of the hashe's uniformity as possible.  Ideally
    


    sipa commented at 10:27 PM on June 12, 2017:

    typo: hashe's

  5. in src/cuckoocache.h:211 in 3dedf120f2 outdated
     205 | @@ -206,6 +206,37 @@ class cache
     206 |      /** compute_hashes is convenience for not having to write out this
     207 |       * expression everywhere we use the hash values of an Element.
     208 |       *
     209 | +     * We need to map the 32-bit input hash onto a hash bucket in a range [0, size) in a
     210 | +     *  manner which preserves as much of the hashe's uniformity as possible.  Ideally
     211 | +     *  would bitmask but the size is usually not a power of two.
    


    sipa commented at 10:27 PM on June 12, 2017:

    typo: "Ideally would bitmask" is not grammatical

  6. in src/cuckoocache.h:214 in 3dedf120f2 outdated
     205 | @@ -206,6 +206,37 @@ class cache
     206 |      /** compute_hashes is convenience for not having to write out this
     207 |       * expression everywhere we use the hash values of an Element.
     208 |       *
     209 | +     * We need to map the 32-bit input hash onto a hash bucket in a range [0, size) in a
     210 | +     *  manner which preserves as much of the hashe's uniformity as possible.  Ideally
     211 | +     *  would bitmask but the size is usually not a power of two.
     212 | +     *
     213 | +     * The naive approach would be to use a mod -- which isn't perfectly uniform but so
     214 | +     *  long as the hash is much larger than size its not that bad.  Unfortunately,
    


    sipa commented at 10:27 PM on June 12, 2017:

    typo: its

  7. sipa commented at 10:29 PM on June 12, 2017: member

    ACK, but some typos

  8. Add an explanation of quickly hashing onto a non-power of two range.
    In Olaoluwa Osuntokun's recent protocol proposal they were using a
     mod in an inner loop.  I wanted to suggest a normative protocol
     change to use the trick we use here, but to find an explanation
     of it I had to dig up the PR on github.  After I posted about it
     several other developers commented that it was very interesting
     and they were unaware of it.
    
    I think ideally the code should be self documenting and help
     educate other contributors about non-obvious techniques that
     we use.  So I've written a description of the technique with
     citations for future reference.
    dd869c60ca
  9. laanwj approved
  10. sipa commented at 5:57 PM on June 13, 2017: member

    utACK dd869c60ca069fa3eea3dd1aab977b8a10e05f2f

  11. MarcoFalke commented at 8:58 AM on June 18, 2017: member

    utACK dd869c60ca069fa3eea3dd1aab977b8a10e05f2f

  12. MarcoFalke assigned laanwj on Jun 24, 2017
  13. laanwj merged this on Jun 24, 2017
  14. laanwj closed this on Jun 24, 2017

  15. laanwj referenced this in commit 232508fe0f on Jun 24, 2017
  16. markblundeberg referenced this in commit f760e536af on Jun 21, 2019
  17. jtoomim referenced this in commit 45ffdb9fb0 on Jun 29, 2019
  18. PastaPastaPasta referenced this in commit fefa0faff7 on Jul 6, 2019
  19. PastaPastaPasta referenced this in commit cc1c973e16 on Jul 8, 2019
  20. PastaPastaPasta referenced this in commit 9ec0827670 on Jul 9, 2019
  21. PastaPastaPasta referenced this in commit f4c0858b49 on Jul 11, 2019
  22. barrystyle referenced this in commit 381a704079 on Jan 22, 2020
  23. zkbot referenced this in commit bb6e5fad4c on Apr 20, 2021
  24. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-18 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me