开发者

C map data structure [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. 开发者_运维知识库

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 6 years ago.

Improve this question

I want to implement a key value pair data structure in C. Any idea?


This is a simple hash table implementation in ANSI C. It supports the rudimentary functions generally expected of a hash table:

  • Inserting and retrieving key-value associations
  • Querying the existence of a key
  • Returning the total number of key-value associations
  • Enumerating over all key-value associations

Hope this helps!


If your key and value part are same data type then you can use a 2-D array with 2 column where first column will be your key and second will be data. IT will behave as map but time complexity will diff. Time complexity : search - O(n) Insert - want to maintain unique key then O(n) else O(1).

int map[N][2];

if you want to have key-value pair different type then you can use list structure.

struct node
{
int key;  //key part
string value;  // value part
struct node *next;
};

Time complexity : search - O(n) Insert - want to maintain unique key then O(n) else O(1).


Typical map functions are also supported by the hashmap implementation in libmba.

I found about it a while ago, though I haven't used it. You can also check the library project homepage.

I hope it might be prove useful to someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜