I'm trying to port some Delphi code to a C library, but the central structure of it is based around a multimap. With no Generics of any kind and no language-level support for dynamic arrays, it would be pretty painful to build my own multimap in C. But I figure someone's already written some somewhere. Where would I find a good multimap implementation for C?

(Also, just to clarify, the "multimap" tag notes on here says "a structure similar to a map but allowing duplicate keys." I'm a bit confused by that, because that's not the multimap container I'm familiar with. What I need is "a structure similar to a map, but allowing multiple values for each (unique) key." In other words, multimap<x, y> = map<x, list<y>>.)

有帮助吗?

解决方案

Although not directly a multimap library, uthash implements a simple associative array in C and is only a header file, so it is fairly portable with low environment overhead.

Using uthash, you could simply create a multi-level associative array, treating the child associative arrays as sets. The uthash documentation provides a simple example for creating and using multi-level associative arrays.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top