C 中的映射算法
scala 可以进行映射(ADT),所以我们可以像这样映射 ('A', 3) = (Char, Int)
在 C 中怎么样?
我想映射并检查两个映射 'a' = 1, 'b' = 3, 'c' = 4 之间的所有关系并进行比较
映射
abbbcccc和 'e' = 1 , 'b' = 3, 'g ' = 4 是 bbbegggg 映射
我想找到这些关系 ('a' , 1) 不在 ('e' = 1 , 'b' = 3, 'g' = 4)。那么,这张地图 ('b' = 3) 位于 ('e' = 1 , 'b' = 3, 'g' = 4) 这张地图中。并计数++;
我怎样才能使这些像地图一样?我可以通过数组来实现吗?
scala can make mapping (ADT) so we can mapping like this ('A', 3) = (Char, Int)
how about in C?
I want to mapping and check all the relations and comparing between two maps
'a' = 1, 'b' = 3, 'c' = 4 is mapping by abbbcccc
and 'e' = 1 , 'b' = 3, 'g' = 4 is mapping by bbbegggg
I want to find these relation ('a' , 1) is not in ('e' = 1 , 'b' = 3, 'g' = 4). then, this map
('b' = 3) is in ('e' = 1 , 'b' = 3, 'g' = 4) this map. and count++;
How I can make these like maps? can I make it by array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是用纯 C 语言,不是。
您可以使用一个或两个数组来实现一个,但您必须实现散列算法或某种比较和搜索算法。或者,您可以使用某种搜索树来实现它。
如果您不想编写地图数据类型,则必须使用具有该功能的库。 GLib 包含一个: http://developer.gnome.org/glib/2.30 /glib-Hash-Tables.html
Not in plain C, no.
You could implement one with an array or two, but you would have to implement either a hashing algorithm, or some kind of comparison and search algorithm. Alternatively you could use some kind of search tree to implement it.
If you don't want to write a map data type, you will have to use a library with that functionality. GLib contains one: http://developer.gnome.org/glib/2.30/glib-Hash-Tables.html