Does C have a hash / data dictionary structure?

Now I'm learning C, knowing Perl and a bit of Python. I did a quick search and found that there is no explicit hash / dictionary, as in perl / python, and I saw that people said that you need a function to find the hash table. So, the fact is that C does not provide a built-in hash structure, and you need to write some function in order to be able to use the hash in C?

+4
source share
5 answers

Basically, the only data structure that C has is arrays, structures (which are map-like, but keys must be known at compile time) and concatenations. Everything else must be manually encoded or provided by the library.

+8

C. , ​​ Glib.

+4

GLib:

GLib - , , , , , , mainloop .. UNIX- , Windows OS X. GLib GNU (GNU LGPL).

OpenSource, : GNOME, Wireshark . Glib , :

  • (GHashTable)
  • (GList)
  • (QQueue)
  • Dataset
  • ..
+1

KLib :

  • khash.h: -, .
  • kbtree.h: B.
  • ksort.h: , , , , , Knuth k-small.
  • kseq.h: FASTA/FASTQ.
  • kvec.h: .
  • klist.h: .
  • kstring. {h, c}: .
  • kmath. {h, c}: , MT19937-64, .
+1

Ignoring all of the misleading answers above, C has a standard library for this long before all these fancy languages ​​have appeared. The basic version makes only one table, and the GNU version as much as you want.

   #include <search.h>

   int hcreate(size_t nel);

   ENTRY *hsearch(ENTRY item, ACTION action);

   void hdestroy(void);

   #define _GNU_SOURCE         /* See feature_test_macros(7) */
   #include <search.h>

   int hcreate_r(size_t nel, struct hsearch_data *htab);

   int hsearch_r(ENTRY item, ACTION action, ENTRY **retval,
                 struct hsearch_data *htab);

   void hdestroy_r(struct hsearch_data *htab);

checkout

+1
source

Source: https://habr.com/ru/post/1660846/


All Articles