dictionary/map/key-value pairs data structure in C

后端 未结 4 1736
借酒劲吻你
借酒劲吻你 2021-01-07 06:38

How does one construct and access a set of key-value pairs in C? To use a silly simple example, let\'s say I want to create a table which translates between an integer and i

4条回答
  •  误落风尘
    2021-01-07 07:11

    You could also use the libghthash for general purpose hashes. They are quite easy to use, and incorporate in your application. However, it is a third party API - so if that's a problem, you would have to implement your own.

    There's no built in associate array/hash tables in C.

    The array initialization (C99) is probably the best way to go unless you have non-numeric keys:

    T hash[] = {
        [1] = tObj,
        [255] = tObj2,
    };
    

提交回复
热议问题