2 PUBLIC
"-//W3C//DTD XTHML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en" lang=
"en">
6 <link rel=
"stylesheet" type=
"text/css" href=
"styles.css" />
7 <title>uthash: a hash table for C structures
</title>
12 <img src=
"banner.png" alt=
"uthash: a hash table for C structures" />
13 </div> <!-- banner -->
16 <a href=
"http://github.com/troydhanson/uthash">GitHub page
</a> >
17 uthash home
<!-- http://troydhanson.github.com/uthash/ -->
19 <a href=
"https://twitter.com/share" class=
"twitter-share-button" data-via=
"troydhanson">Tweet
</a>
20 <script>!function(d
,s
,id
){var js
,fjs
=d
.getElementsByTagName(s
)[0];if(!d
.getElementById(id
)){js
=d
.createElement(s
);js
.id
=id
;js
.src
="//platform.twitter.com/widgets.js";fjs
.parentNode
.insertBefore(js
,fjs
);}}(document
,"script","twitter-wjs");</script>
28 <h2>documentation
</h2>
29 <div><a href=
"userguide.html">uthash
</a></div>
30 <div><a href=
"utlist.html">utlist
</a></div>
31 <div><a href=
"utarray.html">utarray
</a></div>
32 <div><a href=
"utringbuffer.html">utringbuffer
</a></div>
33 <div><a href=
"utstring.html">utstring
</a></div>
36 <h3>GNU/Linux, Windows
</h3>
37 <div><a href=https://github.com/troydhanson/uthash/archive/master.zip
>uthash-master.zip
</a></div>
38 <div><a href=https://github.com/troydhanson/uthash
>git clone
</a></div>
41 <div><a href=
"license.html">BSD revised
</a></div>
45 <div><a href=
"http://troydhanson.github.io/">Troy D. Hanson
</a></div>
48 <div><a href=
"https://github.com/Quuxplusone">Arthur O'Dwyer
</a></div>
54 Any C structure can be stored in a hash table using uthash. Just add a
55 <em>UT_hash_handle
</em> to the structure and choose one or more fields
56 in your structure to act as the key. Then use these macros to store,
57 retrieve or delete items from the hash table.
60 Example
1. Adding an item to a hash.
66 int id; /* we'll use this field as the key */
68 UT_hash_handle hh; /* makes this structure hashable */
71 struct my_struct *users = NULL;
73 void add_user(struct my_struct *s) {
74 HASH_ADD_INT( users, id, s );
79 </div> <!-- listing -->
82 Example
2. Looking up an item in a hash.
85 struct my_struct *find_user(int user_id) {
88 HASH_FIND_INT( users,
&user_id, s );
94 </div> <!-- listing -->
97 Example
3. Deleting an item from a hash.
101 void delete_user(struct my_struct *user) {
102 HASH_DEL( users, user);
107 </div> <!-- listing -->
109 For more information and examples, please see the
<a href=
"userguide.html">User Guide.
</a>
116 </div> <!-- footer -->