Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C have hash/dictionary data structure?

Tags:

c

hashtable

I'm learning C now coming from knowing perl and a bit python. I did a quick search and found there is no explicit hash/dictionary as in perl/python and I saw people were saying you need a function to look up a hash table. So the fact is C doesn't provide an inherent hash structure and you have to write some function to be able to use hash in C?

like image 911
olala Avatar asked Apr 22 '13 15:04

olala


People also ask

Does C have a hash function?

Types of Hashing Function in C In this method, the hash function is dependent upon the remainder of a division. Example: elements to be placed in a hash table are 42,78,89,64 and let's take table size as 10.

Does C language have dictionary?

Section 6.6 of The C Programming Language presents a simple dictionary (hashtable) data structure. I don't think a useful dictionary implementation could get any simpler than this. For your convenience, I reproduce the code here. Note that if the hashes of two strings collide, it may lead to an O(n) lookup time.

Is there a hash table library in C?

The standard C library doesn't include any large, persistent data structures - neither lists, nor trees, nor stacks, nor hashtables.

What is data dictionary in C language?

A data dictionary is a collection of descriptions of the data objects or items in a data model for the benefit of programmers and others who need to refer to them.


2 Answers

Basically, the only data structure that C has are arrays, structs (which is kind of like a map, but the keys must be known at compile time) and unions. Everything else must be coded manually or provided by a library.

like image 110
Oswald Avatar answered Sep 30 '22 20:09

Oswald


It's not part of standard C libraries. Use a library such as Glib.

like image 44
djechlin Avatar answered Sep 30 '22 21:09

djechlin