re20.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>&lt;GHashTable&gt;: </title>
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
  7. <link rel="home" href="index.html" title="">
  8. <link rel="up" href="ch01.html" title="GLib">
  9. <link rel="prev" href="re19.html" title="&lt;%GLibFormatSizeFlags&gt;">
  10. <link rel="next" href="re21.html" title="&lt;%GLibHookFlagMask&gt;">
  11. <meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
  12. <link rel="stylesheet" href="style.css" type="text/css">
  13. </head>
  14. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  15. <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
  16. <td width="100%" align="left" class="shortcuts"></td>
  17. <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
  18. <td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
  19. <td><a accesskey="p" href="re19.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
  20. <td><a accesskey="n" href="re21.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
  21. </tr></table>
  22. <div class="refentry">
  23. <a name="id-1.1.21"></a><div class="titlepage"></div>
  24. <div class="refnamediv">
  25. <h2>&lt;GHashTable&gt;</h2>
  26. <p>&lt;GHashTable&gt;</p>
  27. </div>
  28. <div class="refsect1">
  29. <a name="id-1.1.21.2"></a><h2>Description</h2>
  30. <p>The <span class="type">GHashTable</span> struct is an opaque data structure to represent a
  31. [Hash Table][glib-Hash-Tables]. It should only be accessed via the
  32. following functions.</p>
  33. </div>
  34. <div class="refsect1">
  35. <a name="id-1.1.21.3"></a><h2>Functions</h2>
  36. <div class="refsect2">
  37. <a name="id-1.1.21.3.2"></a><h3>hash-table:add?</h3>
  38. <div class="informalexample"><pre class="programlisting">(define-values (%return) (hash-table:add? hash-table key))
  39. </pre></div>
  40. <p>This is a convenience function for using a <span class="type">GHashTable</span> as a set. It
  41. is equivalent to calling <code class="function">g_hash_table_replace()</code> with <em class="parameter"><code>key</code></em> as both the
  42. key and the value.
  43. </p>
  44. <p>In particular, this means that if <em class="parameter"><code>key</code></em> already exists in the hash table, then
  45. the old copy of <em class="parameter"><code>key</code></em> in the hash table is freed and <em class="parameter"><code>key</code></em> replaces it in the
  46. table.
  47. </p>
  48. <p>When a hash table only ever contains keys that have themselves as the
  49. corresponding value it is able to be stored more efficiently. See
  50. the discussion in the section description.
  51. </p>
  52. <p>Starting from GLib 2.40, this function returns a boolean value to
  53. indicate whether the newly added value was already in the hash table
  54. or not.</p>
  55. <div class="refsect3">
  56. <a name="id-1.1.21.3.2.7"></a><h4>Parameters</h4>
  57. <div class="informaltable"><table>
  58. <tr>
  59. <td class="parameter_name"><p>hash_table</p></td>
  60. <td class="parameter_description">
  61. <p>a <span class="type">GHashTable</span></p>
  62. <p>Passed as <code class="code">hash-table</code></p>
  63. </td>
  64. </tr>
  65. <tr>
  66. <td class="parameter_name"><p>key</p></td>
  67. <td class="parameter_description">
  68. <p>a key to insert</p>
  69. <p>Passed as <code class="code">key</code></p>
  70. </td>
  71. </tr>
  72. </table></div>
  73. </div>
  74. </div>
  75. <div class="refsect2">
  76. <a name="id-1.1.21.3.3"></a><h3>hash-table:contains?</h3>
  77. <div class="informalexample"><pre class="programlisting">(define-values (%return) (hash-table:contains? hash-table key))
  78. </pre></div>
  79. <p>Checks if <em class="parameter"><code>key</code></em> is in <em class="parameter"><code>hash_table</code></em>.</p>
  80. <div class="refsect3">
  81. <a name="id-1.1.21.3.3.4"></a><h4>Parameters</h4>
  82. <div class="informaltable"><table>
  83. <tr>
  84. <td class="parameter_name"><p>hash_table</p></td>
  85. <td class="parameter_description">
  86. <p>a <span class="type">GHashTable</span></p>
  87. <p>Passed as <code class="code">hash-table</code></p>
  88. </td>
  89. </tr>
  90. <tr>
  91. <td class="parameter_name"><p>key</p></td>
  92. <td class="parameter_description">
  93. <p>a key to check</p>
  94. <p>Passed as <code class="code">key</code></p>
  95. </td>
  96. </tr>
  97. </table></div>
  98. </div>
  99. </div>
  100. <div class="refsect2">
  101. <a name="id-1.1.21.3.4"></a><h3>hash-table:destroy</h3>
  102. <div class="informalexample"><pre class="programlisting">(define-values () (hash-table:destroy hash-table))
  103. </pre></div>
  104. <p>Destroys all keys and values in the <span class="type">GHashTable</span> and decrements its
  105. reference count by 1. If keys and/or values are dynamically allocated,
  106. you should either free them first or create the <span class="type">GHashTable</span> with destroy
  107. notifiers using <code class="function">g_hash_table_new_full()</code>. In the latter case the destroy
  108. functions you supplied will be called on all keys and values during the
  109. destruction phase.</p>
  110. <div class="refsect3">
  111. <a name="id-1.1.21.3.4.4"></a><h4>Parameters</h4>
  112. <div class="informaltable"><table><tr>
  113. <td class="parameter_name"><p>hash_table</p></td>
  114. <td class="parameter_description">
  115. <p>a <span class="type">GHashTable</span></p>
  116. <p>Passed as <code class="code">hash-table</code></p>
  117. </td>
  118. </tr></table></div>
  119. </div>
  120. </div>
  121. <div class="refsect2">
  122. <a name="id-1.1.21.3.5"></a><h3>hash-table:insert?</h3>
  123. <div class="informalexample"><pre class="programlisting">(define-values (%return) (hash-table:insert? hash-table key value))
  124. </pre></div>
  125. <p>Inserts a new key and value into a <span class="type">GHashTable</span>.
  126. </p>
  127. <p>If the key already exists in the <span class="type">GHashTable</span> its current
  128. value is replaced with the new value. If you supplied a
  129. <em class="parameter"><code>value_destroy_func</code></em> when creating the <span class="type">GHashTable</span>, the old
  130. value is freed using that function. If you supplied a
  131. <em class="parameter"><code>key_destroy_func</code></em> when creating the <span class="type">GHashTable</span>, the passed
  132. key is freed using that function.
  133. </p>
  134. <p>Starting from GLib 2.40, this function returns a boolean value to
  135. indicate whether the newly added value was already in the hash table
  136. or not.</p>
  137. <div class="refsect3">
  138. <a name="id-1.1.21.3.5.6"></a><h4>Parameters</h4>
  139. <div class="informaltable"><table>
  140. <tr>
  141. <td class="parameter_name"><p>hash_table</p></td>
  142. <td class="parameter_description">
  143. <p>a <span class="type">GHashTable</span></p>
  144. <p>Passed as <code class="code">hash-table</code></p>
  145. </td>
  146. </tr>
  147. <tr>
  148. <td class="parameter_name"><p>key</p></td>
  149. <td class="parameter_description">
  150. <p>a key to insert</p>
  151. <p>Passed as <code class="code">key</code></p>
  152. </td>
  153. </tr>
  154. <tr>
  155. <td class="parameter_name"><p>value</p></td>
  156. <td class="parameter_description">
  157. <p>the value to associate with the key</p>
  158. <p>Passed as <code class="code">value</code></p>
  159. </td>
  160. </tr>
  161. </table></div>
  162. </div>
  163. </div>
  164. <div class="refsect2">
  165. <a name="id-1.1.21.3.6"></a><h3>hash-table:lookup</h3>
  166. <div class="informalexample"><pre class="programlisting">(define-values (%return) (hash-table:lookup hash-table key))
  167. </pre></div>
  168. <p>Looks up a key in a <span class="type">GHashTable</span>. Note that this function cannot
  169. distinguish between a key that is not present and one which is present
  170. and has the value <code class="constant">NULL</code>. If you need this distinction, use
  171. <code class="function">g_hash_table_lookup_extended()</code>.</p>
  172. <div class="refsect3">
  173. <a name="id-1.1.21.3.6.4"></a><h4>Parameters</h4>
  174. <div class="informaltable"><table>
  175. <tr>
  176. <td class="parameter_name"><p>hash_table</p></td>
  177. <td class="parameter_description">
  178. <p>a <span class="type">GHashTable</span></p>
  179. <p>Passed as <code class="code">hash-table</code></p>
  180. </td>
  181. </tr>
  182. <tr>
  183. <td class="parameter_name"><p>key</p></td>
  184. <td class="parameter_description">
  185. <p>the key to look up</p>
  186. <p>Passed as <code class="code">key</code></p>
  187. </td>
  188. </tr>
  189. </table></div>
  190. </div>
  191. </div>
  192. <div class="refsect2">
  193. <a name="id-1.1.21.3.7"></a><h3>hash-table:lookup-extended</h3>
  194. <div class="informalexample"><pre class="programlisting">(define-values
  195. (%return orig-key value)
  196. (hash-table:lookup-extended hash-table lookup-key))
  197. </pre></div>
  198. <p>Looks up a key in the <span class="type">GHashTable</span>, returning the original key and the
  199. associated value and a <span class="type">gboolean</span> which is <code class="constant">TRUE</code> if the key was found. This
  200. is useful if you need to free the memory allocated for the original key,
  201. for example before calling <code class="function">g_hash_table_remove()</code>.
  202. </p>
  203. <p>You can actually pass <code class="constant">NULL</code> for <em class="parameter"><code>lookup_key</code></em> to test
  204. whether the <code class="constant">NULL</code> key exists, provided the hash and equal functions
  205. of <em class="parameter"><code>hash_table</code></em> are <code class="constant">NULL</code>-safe.</p>
  206. <div class="refsect3">
  207. <a name="id-1.1.21.3.7.5"></a><h4>Parameters</h4>
  208. <div class="informaltable"><table>
  209. <tr>
  210. <td class="parameter_name"><p>hash_table</p></td>
  211. <td class="parameter_description">
  212. <p>a <span class="type">GHashTable</span></p>
  213. <p>Passed as <code class="code">hash-table</code></p>
  214. </td>
  215. </tr>
  216. <tr>
  217. <td class="parameter_name"><p>lookup_key</p></td>
  218. <td class="parameter_description">
  219. <p>the key to look up</p>
  220. <p>Passed as <code class="code">lookup-key</code></p>
  221. </td>
  222. </tr>
  223. <tr>
  224. <td class="parameter_name"><p>orig_key</p></td>
  225. <td class="parameter_description">
  226. <p>return location for the original key</p>
  227. <p>Passed as <code class="code">orig-key</code></p>
  228. </td>
  229. </tr>
  230. <tr>
  231. <td class="parameter_name"><p>value</p></td>
  232. <td class="parameter_description">
  233. <p>return location for the value associated
  234. with the key</p>
  235. <p>Passed as <code class="code">value</code></p>
  236. </td>
  237. </tr>
  238. </table></div>
  239. </div>
  240. </div>
  241. <div class="refsect2">
  242. <a name="id-1.1.21.3.8"></a><h3>hash-table:remove?</h3>
  243. <div class="informalexample"><pre class="programlisting">(define-values (%return) (hash-table:remove? hash-table key))
  244. </pre></div>
  245. <p>Removes a key and its associated value from a <span class="type">GHashTable</span>.
  246. </p>
  247. <p>If the <span class="type">GHashTable</span> was created using <code class="function">g_hash_table_new_full()</code>, the
  248. key and value are freed using the supplied destroy functions, otherwise
  249. you have to make sure that any dynamically allocated values are freed
  250. yourself.</p>
  251. <div class="refsect3">
  252. <a name="id-1.1.21.3.8.5"></a><h4>Parameters</h4>
  253. <div class="informaltable"><table>
  254. <tr>
  255. <td class="parameter_name"><p>hash_table</p></td>
  256. <td class="parameter_description">
  257. <p>a <span class="type">GHashTable</span></p>
  258. <p>Passed as <code class="code">hash-table</code></p>
  259. </td>
  260. </tr>
  261. <tr>
  262. <td class="parameter_name"><p>key</p></td>
  263. <td class="parameter_description">
  264. <p>the key to remove</p>
  265. <p>Passed as <code class="code">key</code></p>
  266. </td>
  267. </tr>
  268. </table></div>
  269. </div>
  270. </div>
  271. <div class="refsect2">
  272. <a name="id-1.1.21.3.9"></a><h3>hash-table:remove-all</h3>
  273. <div class="informalexample"><pre class="programlisting">(define-values () (hash-table:remove-all hash-table))
  274. </pre></div>
  275. <p>Removes all keys and their associated values from a <span class="type">GHashTable</span>.
  276. </p>
  277. <p>If the <span class="type">GHashTable</span> was created using <code class="function">g_hash_table_new_full()</code>,
  278. the keys and values are freed using the supplied destroy functions,
  279. otherwise you have to make sure that any dynamically allocated
  280. values are freed yourself.</p>
  281. <div class="refsect3">
  282. <a name="id-1.1.21.3.9.5"></a><h4>Parameters</h4>
  283. <div class="informaltable"><table><tr>
  284. <td class="parameter_name"><p>hash_table</p></td>
  285. <td class="parameter_description">
  286. <p>a <span class="type">GHashTable</span></p>
  287. <p>Passed as <code class="code">hash-table</code></p>
  288. </td>
  289. </tr></table></div>
  290. </div>
  291. </div>
  292. <div class="refsect2">
  293. <a name="id-1.1.21.3.10"></a><h3>hash-table:replace?</h3>
  294. <div class="informalexample"><pre class="programlisting">(define-values (%return) (hash-table:replace? hash-table key value))
  295. </pre></div>
  296. <p>Inserts a new key and value into a <span class="type">GHashTable</span> similar to
  297. <code class="function">g_hash_table_insert()</code>. The difference is that if the key
  298. already exists in the <span class="type">GHashTable</span>, it gets replaced by the
  299. new key. If you supplied a <em class="parameter"><code>value_destroy_func</code></em> when creating
  300. the <span class="type">GHashTable</span>, the old value is freed using that function.
  301. If you supplied a <em class="parameter"><code>key_destroy_func</code></em> when creating the
  302. <span class="type">GHashTable</span>, the old key is freed using that function.
  303. </p>
  304. <p>Starting from GLib 2.40, this function returns a boolean value to
  305. indicate whether the newly added value was already in the hash table
  306. or not.</p>
  307. <div class="refsect3">
  308. <a name="id-1.1.21.3.10.5"></a><h4>Parameters</h4>
  309. <div class="informaltable"><table>
  310. <tr>
  311. <td class="parameter_name"><p>hash_table</p></td>
  312. <td class="parameter_description">
  313. <p>a <span class="type">GHashTable</span></p>
  314. <p>Passed as <code class="code">hash-table</code></p>
  315. </td>
  316. </tr>
  317. <tr>
  318. <td class="parameter_name"><p>key</p></td>
  319. <td class="parameter_description">
  320. <p>a key to insert</p>
  321. <p>Passed as <code class="code">key</code></p>
  322. </td>
  323. </tr>
  324. <tr>
  325. <td class="parameter_name"><p>value</p></td>
  326. <td class="parameter_description">
  327. <p>the value to associate with the key</p>
  328. <p>Passed as <code class="code">value</code></p>
  329. </td>
  330. </tr>
  331. </table></div>
  332. </div>
  333. </div>
  334. <div class="refsect2">
  335. <a name="id-1.1.21.3.11"></a><h3>hash-table:size</h3>
  336. <div class="informalexample"><pre class="programlisting">(define-values (%return) (hash-table:size hash-table))
  337. </pre></div>
  338. <p>Returns the number of elements contained in the <span class="type">GHashTable</span>.</p>
  339. <div class="refsect3">
  340. <a name="id-1.1.21.3.11.4"></a><h4>Parameters</h4>
  341. <div class="informaltable"><table><tr>
  342. <td class="parameter_name"><p>hash_table</p></td>
  343. <td class="parameter_description">
  344. <p>a <span class="type">GHashTable</span></p>
  345. <p>Passed as <code class="code">hash-table</code></p>
  346. </td>
  347. </tr></table></div>
  348. </div>
  349. </div>
  350. <div class="refsect2">
  351. <a name="id-1.1.21.3.12"></a><h3>hash-table:steal?</h3>
  352. <div class="informalexample"><pre class="programlisting">(define-values (%return) (hash-table:steal? hash-table key))
  353. </pre></div>
  354. <p>Removes a key and its associated value from a <span class="type">GHashTable</span> without
  355. calling the key and value destroy functions.</p>
  356. <div class="refsect3">
  357. <a name="id-1.1.21.3.12.4"></a><h4>Parameters</h4>
  358. <div class="informaltable"><table>
  359. <tr>
  360. <td class="parameter_name"><p>hash_table</p></td>
  361. <td class="parameter_description">
  362. <p>a <span class="type">GHashTable</span></p>
  363. <p>Passed as <code class="code">hash-table</code></p>
  364. </td>
  365. </tr>
  366. <tr>
  367. <td class="parameter_name"><p>key</p></td>
  368. <td class="parameter_description">
  369. <p>the key to remove</p>
  370. <p>Passed as <code class="code">key</code></p>
  371. </td>
  372. </tr>
  373. </table></div>
  374. </div>
  375. </div>
  376. <div class="refsect2">
  377. <a name="id-1.1.21.3.13"></a><h3>hash-table:steal-all</h3>
  378. <div class="informalexample"><pre class="programlisting">(define-values () (hash-table:steal-all hash-table))
  379. </pre></div>
  380. <p>Removes all keys and their associated values from a <span class="type">GHashTable</span>
  381. without calling the key and value destroy functions.</p>
  382. <div class="refsect3">
  383. <a name="id-1.1.21.3.13.4"></a><h4>Parameters</h4>
  384. <div class="informaltable"><table><tr>
  385. <td class="parameter_name"><p>hash_table</p></td>
  386. <td class="parameter_description">
  387. <p>a <span class="type">GHashTable</span></p>
  388. <p>Passed as <code class="code">hash-table</code></p>
  389. </td>
  390. </tr></table></div>
  391. </div>
  392. </div>
  393. <div class="refsect2">
  394. <a name="id-1.1.21.3.14"></a><h3>hash-table:steal-extended</h3>
  395. <div class="informalexample"><pre class="programlisting">(define-values
  396. (%return stolen-key stolen-value)
  397. (hash-table:steal-extended hash-table lookup-key))
  398. </pre></div>
  399. <p>Looks up a key in the <span class="type">GHashTable</span>, stealing the original key and the
  400. associated value and returning <code class="constant">TRUE</code> if the key was found. If the key was
  401. not found, <code class="constant">FALSE</code> is returned.
  402. </p>
  403. <p>If found, the stolen key and value are removed from the hash table without
  404. calling the key and value destroy functions, and ownership is transferred to
  405. the caller of this method; as with <code class="function">g_hash_table_steal()</code>.
  406. </p>
  407. <p>You can pass <code class="constant">NULL</code> for <em class="parameter"><code>lookup_key</code></em>, provided the hash and equal functions
  408. of <em class="parameter"><code>hash_table</code></em> are <code class="constant">NULL</code>-safe.</p>
  409. <div class="refsect3">
  410. <a name="id-1.1.21.3.14.6"></a><h4>Parameters</h4>
  411. <div class="informaltable"><table>
  412. <tr>
  413. <td class="parameter_name"><p>hash_table</p></td>
  414. <td class="parameter_description">
  415. <p>a <span class="type">GHashTable</span></p>
  416. <p>Passed as <code class="code">hash-table</code></p>
  417. </td>
  418. </tr>
  419. <tr>
  420. <td class="parameter_name"><p>lookup_key</p></td>
  421. <td class="parameter_description">
  422. <p>the key to look up</p>
  423. <p>Passed as <code class="code">lookup-key</code></p>
  424. </td>
  425. </tr>
  426. <tr>
  427. <td class="parameter_name"><p>stolen_key</p></td>
  428. <td class="parameter_description">
  429. <p>return location for the
  430. original key</p>
  431. <p>Passed as <code class="code">stolen-key</code></p>
  432. </td>
  433. </tr>
  434. <tr>
  435. <td class="parameter_name"><p>stolen_value</p></td>
  436. <td class="parameter_description">
  437. <p>return location
  438. for the value associated with the key</p>
  439. <p>Passed as <code class="code">stolen-value</code></p>
  440. </td>
  441. </tr>
  442. </table></div>
  443. </div>
  444. </div>
  445. <div class="refsect2">
  446. <a name="id-1.1.21.3.15"></a><h3>hash-table:unref</h3>
  447. <div class="informalexample"><pre class="programlisting">(define-values () (hash-table:unref hash-table))
  448. </pre></div>
  449. <p>Atomically decrements the reference count of <em class="parameter"><code>hash_table</code></em> by one.
  450. If the reference count drops to 0, all keys and values will be
  451. destroyed, and all memory allocated by the hash table is released.
  452. This function is MT-safe and may be called from any thread.</p>
  453. <div class="refsect3">
  454. <a name="id-1.1.21.3.15.4"></a><h4>Parameters</h4>
  455. <div class="informaltable"><table><tr>
  456. <td class="parameter_name"><p>hash_table</p></td>
  457. <td class="parameter_description">
  458. <p>a valid <span class="type">GHashTable</span></p>
  459. <p>Passed as <code class="code">hash-table</code></p>
  460. </td>
  461. </tr></table></div>
  462. </div>
  463. </div>
  464. </div>
  465. </div>
  466. <div class="footer">
  467. <hr>Generated by GTK-Doc V1.33.1</div>
  468. </body>
  469. </html>