I want to implement a key value pair data structure in C. Any idea?
The C Programming Language by Kernighan and Ritchie has an example of making an associate map in c, and what I'll detail below is based on what I remember from that. Basically you'll need a struct Map that contains struct Key and struct Value.
Now coming to the point that which data structure is used by map. The internal implementation of map is self-balancing Binary Tree. There are generally two methods for implementing a self-balancing binary tree: Red-Black Tree and.
The map data type is referred to as an associative array because, like an array, it is a collection of values rather than a single value, as an Int or a String is. Furthermore, each distinct key is associated with a value, resulting in an associative array.
map is often implemented using red-black trees, while unordered_map is often implemented using hash tables.
This is a simple hash table implementation in ANSI C. It supports the rudimentary functions generally expected of a hash table:
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With