STL映射C中的一种功能 [英] STL map kinda functionality in C

查看:65
本文介绍了STL映射C中的一种功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想存储一个键值对,然后根据给定的键值检索值




我在C ++中非常反过来,但这需要在C中实现。


如果想知道如何在C中实现这个目标会有什么想法吗?


提前致谢

DKRS。

Hi,

I would like to store a key-value pair and then retrieve the value
based on a given key value.

I am quite conversent in C++ but this needs be implemented in C.

Would appriciate any idea how to achieve this in C?

Thanks in advance
DKRS.

推荐答案

comp_novice说:
comp_novice said:




我想存储一个键值对,然后检索值

基于给定的键值。


我在C ++中非常反过来但这需要在C中实现。


任意想法如何在C中实现这一目标?
Hi,

I would like to store a key-value pair and then retrieve the value
based on a given key value.

I am quite conversent in C++ but this needs be implemented in C.

Would appriciate any idea how to achieve this in C?



使用二叉搜索树。编写一个可以处理任何

数据类型的bst是微不足道的。如果你想把钥匙与剩余的价值分开,那么这对你来说很重要,但是C并不介意。


有关C中二进制搜索树的信息,请查看 http://adtinfo.org

记录了Ben Pfaff的GNU libavl库。 IIRC Ben通常使用int而不是你需要的空白来建造他们的树木,但

技术基本相同。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)

Use a binary search tree. It is trivial to write a bst that can handle any
data type. If you wish to separate the key from the rest of the value,
that''s up to you, but C doesn''t really mind either way.

For information on binary search trees in C, check out http://adtinfo.org
which documents Ben Pfaff''s GNU libavl library. IIRC Ben normally builds
his trees out of ints rather than the void *s you''ll be needing, but the
techniques are basically the same.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Richard Heathfield< in **** *@invalid.invalidwrites:
Richard Heathfield <in*****@invalid.invalidwrites:

有关C中二进制搜索树的信息,请查看 http://adtinfo.org

记录了Ben Pfaff的GNU libavl库。 IIRC Ben通常使用int而不是你需要的空白来建造他们的树木,但

技术基本相同。
For information on binary search trees in C, check out http://adtinfo.org
which documents Ben Pfaff''s GNU libavl library. IIRC Ben normally builds
his trees out of ints rather than the void *s you''ll be needing, but the
techniques are basically the same.



我认为C Unleashed书的实现可能使用了

整数,但GNU libavl使用了void * s。

-

你称之为* C *问题?你到底在吸什么? --Kaz

I think that the C Unleashed book implementation might have used
ints, but GNU libavl uses void *s.
--
"You call this a *C* question? What the hell are you smoking?" --Kaz


Ben Pfaff说:
Ben Pfaff said:

Richard Heathfield< in ***** @ invalid .invalidwrites:
Richard Heathfield <in*****@invalid.invalidwrites:

>有关C中二进制搜索树的信息,请查看 http://adtinfo.org
文件是Ben Pfaff的GNU libavl库。 IIRC Ben通常用int而不是你需要的空间建造他的树木,但
技术基本相同。
>For information on binary search trees in C, check out http://adtinfo.org
which documents Ben Pfaff''s GNU libavl library. IIRC Ben normally builds
his trees out of ints rather than the void *s you''ll be needing, but the
techniques are basically the same.



我认为C Unleashed书的实现可能已经使用了

ints,


I think that the C Unleashed book implementation might have used
ints,



确实。

Indeed.


但GNU libavl使用void * s。
but GNU libavl uses void *s.



哦,这很好 - 我希望我知道;我本可以为自己省下一些工作。 :-)


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)

Oh, that''s good - I wish I''d known; I could have saved myself some work. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


这篇关于STL映射C中的一种功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆