5

I am starting to learn about the hash table data structure in C, and I've noticed (if I understand the concept correctly) that hash tables are awfully similar to python dictionaries. If I am incorrect and they are two completely different things, could someone explain to me what a hash table is without getting too technical? Thanks.

Serket
  • 3,785
  • 3
  • 14
  • 45
  • 4
    They are not entirely different things. The concept is the same, though the implementation will be specific to different versions of CPython – roganjosh May 02 '20 at 20:45
  • 2
    As far as I am aware, they are implemented in a similar way. Each index is used to generate a hash to locate the value at the given index – GTBebbo May 02 '20 at 20:46
  • They are basically the same thing. Key/value stores with more efficient lookups via hash. – tdelaney May 02 '20 at 20:46
  • 5
    This question is essentially analogous to "what is the difference between a car and a Ford Focus". Python dicts fall under the category of hash tables. – user2357112 May 02 '20 at 20:49
  • 1
    Does this answer your question? [How are Python's Built In Dictionaries Implemented?](https://stackoverflow.com/questions/327311/how-are-pythons-built-in-dictionaries-implemented) – roganjosh May 02 '20 at 21:00
  • 1
    The dupe obviously is more broad than your question, but the answer by Aaron Hall quite clearly states that they are hash tables in Python and there's plenty of detail in there for you to reconcile your C learning with CPython – roganjosh May 02 '20 at 21:01
  • Does this answer your question? [What is a hash table and how do you make it in C?](https://stackoverflow.com/questions/31930046/what-is-a-hash-table-and-how-do-you-make-it-in-c) – R.Nish May 02 '20 at 21:03
  • Python dictionaries are hash tables – juanpa.arrivillaga May 02 '20 at 21:26

1 Answers1

2

There is not really any difference between them. That's why python's dicts don't support duplicates. That is also why python has the function hash which python's dictionaries use by default.

xilpex
  • 3,097
  • 2
  • 14
  • 45
  • 2
    "The second one is the one which takes in a custom hash function" - what? No it doesn't. `mapping` is a dict or other key-value data structure, not a hash function. – user2357112 May 02 '20 at 20:52