Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Robin Hood Hashing (Papers We Love SF August 2017)

Robin Hood Hashing (Papers We Love SF August 2017)

Robin Hood Hashing (1986) provided a breakthrough algorithm for storing data in hash tables, and has a really cool name. These slides were presented at the Papers We Love, Too meetup in San Francisco.

André Arko

August 24, 2017
Tweet

More Decks by André Arko

Other Decks in Programming

Transcript

  1. Robin Hood Hashing
    (Pedro Celis, 1986)
    Papers We Love

    View Slide

  2. André Arko
    this is me, @indirect

    View Slide

  3. Robin Hood
    Hashing

    View Slide

  4. Robin Hood Hashing (1986)
    example hash table data
    LEIA
    HAN
    REY
    LUKE
    : ALDERAAN
    : CORELLIA
    : JAKKU
    : TATTOOINE

    View Slide

  5. Robin Hood Hashing (1986)
    example hash table data
    LEIA
    HAN
    REY
    LUKE

    View Slide

  6. Robin Hood Hashing (1986)
    example hash table data
    LEIA
    HAN
    REY
    LUKE

    View Slide

  7. Robin Hood Hashing (1986)
    keys hashed to index values
    LEIA
    HAN
    REY
    LUKE

    View Slide

  8. Robin Hood Hashing (1986)
    keys hashed to index values
    LEIA
    HAN
    REY
    LUKE

    View Slide

  9. Robin Hood Hashing (1986)
    keys hashed to index values
    LEIA
    HAN
    REY
    LUKE
    HASHING
    ALGORITHM

    View Slide

  10. Robin Hood Hashing (1986)
    keys hashed to index values
    LEIA
    HAN
    REY
    LUKE
    HASHING
    ALGORITHM

    View Slide

  11. Robin Hood Hashing (1986)
    keys hashed to index values
    LEIA
    HAN
    REY
    LUKE
    HASHING
    ALGORITHM
    2
    4
    0
    4

    View Slide

  12. Robin Hood Hashing (1986)
    keys hashed to index values
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4

    View Slide

  13. Robin Hood Hashing (1986)
    keys hashed to index values
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4

    View Slide

  14. data stored in an array
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    Robin Hood Hashing (1986)

    View Slide

  15. data stored in an array
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    Robin Hood Hashing (1986)

    View Slide

  16. data stored in an array
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    Robin Hood Hashing (1986)

    View Slide

  17. data stored in an array
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    LEIA:ALDERAAN
    Robin Hood Hashing (1986)

    View Slide

  18. data stored in an array
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    LEIA:ALDERAAN
    Robin Hood Hashing (1986)

    View Slide

  19. data stored in an array
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    LEIA:ALDERAAN
    HAN:CORELLIA
    Robin Hood Hashing (1986)

    View Slide

  20. data stored in an array
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    LEIA:ALDERAAN
    HAN:CORELLIA
    Robin Hood Hashing (1986)

    View Slide

  21. data stored in an array
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    LEIA:ALDERAAN
    HAN:CORELLIA
    REY:JAKKU
    Robin Hood Hashing (1986)

    View Slide

  22. hash collisions
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    LEIA:ALDERAAN
    HAN:CORELLIA
    REY:JAKKU
    Robin Hood Hashing (1986)

    View Slide

  23. resolving collisions: chaining
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    0
    1
    2
    3
    4
    LEIA:ALDERAAN
    HAN:CORELLIA
    REY:JAKKU
    Robin Hood Hashing (1986)

    View Slide

  24. 0
    1
    2
    3
    4
    5
    resolving collisions: open addressing
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    LEIA:ALDERAAN
    HAN:CORELLIA
    REY:JAKKU
    Robin Hood Hashing (1986)

    View Slide

  25. 0
    1
    2
    3
    4
    5
    resolving collisions: open addressing
    LEIA
    HAN
    REY
    LUKE
    2
    4
    0
    4
    LEIA:ALDERAAN
    HAN:CORELLIA +
    REY:JAKKU
    LUKE:TATTOOINE
    Robin Hood Hashing (1986)

    View Slide

  26. 0
    1
    2
    3
    4
    5
    resolving collisions: open addressing
    LEIA
    HAN
    REY
    LUKE
    FINN
    2
    4
    0
    4
    5
    LEIA:ALDERAAN
    HAN:CORELLIA +
    REY:JAKKU
    LUKE:TATTOOINE
    Robin Hood Hashing (1986)

    View Slide

  27. 0
    1
    2
    3
    4
    5
    6
    Robin Hood Hashing (1986)
    resolving collisions: open addressing
    LEIA
    HAN
    REY
    LUKE
    FINN
    2
    4
    0
    4
    5
    LEIA:ALDERAAN
    HAN:CORELLIA +
    REY:JAKKU
    LUKE:TATTOOINE +
    FINN:CORUSCANT

    View Slide

  28. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Robin Hood Hashing (1986)
    resolving collisions: open addressing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    2
    4
    0
    4
    5
    9
    6
    8
    LEIA:ALDERAAN
    HAN:CORELLIA +
    REY:JAKKU
    LUKE:TATTOOINE +
    FINN:CORUSCANT+
    CHEWIE:KASHYYK
    LANDO:BESPIN
    MAUL:DATHOMIR

    View Slide

  29. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Robin Hood Hashing (1986)
    worst-case performance: it’s really bad
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA +
    REY:JAKKU
    LUKE:TATTOOINE +
    FINN:CORUSCANT+
    CHEWIE:KASHYYK
    LANDO:BESPIN
    MAUL:DATHOMIR
    LEIA:ALDERAAN

    View Slide

  30. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    worst-case performance: it’s really bad
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA +
    REY:JAKKU
    LUKE:TATTOOINE +
    FINN:CORUSCANT+
    CHEWIE:KASHYYK+
    LANDO:BESPIN+
    MAUL:DATHOMIR+
    WICKET:ENDOR
    LEIA:ALDERAAN

    View Slide

  31. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data 6 slots away from ideal
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA +
    REY:JAKKU
    LUKE:TATTOOINE +
    FINN:CORUSCANT+
    CHEWIE:KASHYYK+
    LANDO:BESPIN+
    MAUL:DATHOMIR+
    WICKET:ENDOR
    LEIA:ALDERAAN

    View Slide

  32. Robin Hood Hashing (1986)
    as you can probably imagine,
    this gets very bad,
    very quickly

    View Slide

  33. Robin Hood Hashing (1986)
    but a hero is on the horizon!
    Robin Hood Hashing
    offers vastly more
    efficient storage

    View Slide

  34. Robin Hood Hashing (1986)
    how much better is it, really?
    O(ln n) probes,
    where n is items
    in the hash

    View Slide

  35. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4

    View Slide

  36. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    REY:JAKKU 0

    View Slide

  37. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    REY:JAKKU 0
    LEIA:ALDERAAN 0

    View Slide

  38. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LEIA:ALDERAAN 0

    View Slide

  39. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    LEIA:ALDERAAN 0

    View Slide

  40. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    FINN:CORUSCANT 1
    LEIA:ALDERAAN 0

    View Slide

  41. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    FINN:CORUSCANT 1
    CHEWIE:KASHYYK 0
    LEIA:ALDERAAN 0

    View Slide

  42. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    FINN:CORUSCANT 1
    CHEWIE:KASHYYK 0
    LANDO:BESPIN 1
    LEIA:ALDERAAN 0

    View Slide

  43. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    FINN:CORUSCANT 1
    CHEWIE:KASHYYK 0
    LANDO:BESPIN 1
    MAUL:DATHOMIR 0
    LEIA:ALDERAAN 0

    View Slide

  44. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    FINN:CORUSCANT 1
    CHEWIE:KASHYYK 0
    LANDO:BESPIN 1
    MAUL:DATHOMIR 0
    LEIA:ALDERAAN 0

    View Slide

  45. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    WICKET:ENDOR 2
    CHEWIE:KASHYYK 0
    LANDO:BESPIN 1
    MAUL:DATHOMIR 0
    LEIA:ALDERAAN 0

    View Slide

  46. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    WICKET:ENDOR 2
    CHEWIE:KASHYYK 0
    FINN:CORUSCANT 2
    MAUL:DATHOMIR 0
    LEIA:ALDERAAN 0

    View Slide

  47. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    WICKET:ENDOR 2
    CHEWIE:KASHYYK 0
    FINN:CORUSCANT 2
    LANDO:BESPIN 2
    LEIA:ALDERAAN 0

    View Slide

  48. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    WICKET:ENDOR 2
    MAUL:DATHOMIR 1
    FINN:CORUSCANT 2
    LANDO:BESPIN 2
    LEIA:ALDERAAN 0

    View Slide

  49. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    data stored in an array with robin hood hashing
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    WICKET:ENDOR 2
    MAUL:DATHOMIR 1
    FINN:CORUSCANT 2
    LANDO:BESPIN 2
    LEIA:ALDERAAN 0
    CHEWIE:KASHYYK 1

    View Slide

  50. 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Robin Hood Hashing (1986)
    only 2 slots away from ideal
    LEIA
    HAN
    REY
    LUKE
    FINN
    CHEWIE
    LANDO
    MAUL
    WICKET
    2
    4
    0
    4
    5
    9
    6
    8
    4
    HAN:CORELLIA 0
    REY:JAKKU 0
    LUKE:TATTOOINE 1
    WICKET:ENDOR 2
    MAUL:DATHOMIR 1
    FINN:CORUSCANT 2
    LANDO:BESPIN 2
    LEIA:ALDERAAN 0
    CHEWIE:KASHYYK 1

    View Slide

  51. Robin Hood Hashing (1986)
    stealing from the rich and giving to the poor?
    that’s Robin Hood all over

    View Slide

  52. Robin Hood Hashing (1986)
    further reading
    ‣ Robin Hood Hashing (1986 original paper)
    ‣ Robin Hood Hashing with Linear Probing paper (2005)
    ‣ Paul Khuong experimenting with hashing options (2009)
    ‣ Paul’s follow-up and conclusions (2011)
    ‣ Sebastian Sylvan saying robin hood should be the default (2013)
    ‣ Sebastian following up on slowness after deletions (2013)
    ‣ Emmanuel Goossaert benchmarking in C++ (2013)
    ‣ Paul Kuhong again, on linear probing for performance (2013)
    ‣ Emmanuel benchmarking again after tweaking deletions (2013)

    View Slide

  53. Robin Hood Hashing (1986)
    thanks!
    slides

    bit.ly/indirect-robin-hood-hashing
    twitter

    @indirect
    email

    [email protected]

    View Slide