Hash tables VS associative arrays

后端 未结 5 1225
南旧
南旧 2020-12-07 14:06

Recently I have read about hash-tables in a very famous book \"Introduction to Algorithms\". I haven\'t used them in any real applications yet, but want to.

5条回答
  •  忘掉有多难
    2020-12-07 14:59

    The difference between an associative array and a hash table is that an associative array is a data type, while a hash table is a data implementation. Obviously the associative array type is very important in many current programming languages: Perl, Python, PHP, etc. A hash table is the main way to implement an associative array, but not quite the only way. And associative arrays are the main use of hash tables, but not quite the only use. So it's not that they are the same, but if you already have associative arrays, then you usually shouldn't worry about the difference.

    For performance reasons, it can be important to know that your associative arrays in your favorite language are implemented as hashes. And it can be important to have some idea of the overhead cost of that implementation. Hash tables are slower and use more memory than linear arrays as you see them in C.

    Perl lumps the two concepts together by calling associative arrays "hashes". Like a number of features of Perl, it isn't quite wrong, but it's sloppy.

提交回复
热议问题