ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/vendor/pxys2-2.1.0/pxyservd/dbprim/doc/html/ht__add_8c-source.html
Revision: 3253
Committed: Wed Apr 2 20:46:18 2014 UTC (12 years, 3 months ago) by michael
Content type: text/html
File size: 10067 byte(s)
Log Message:
- Imported pxys2-2.1.0

File Contents

# User Rev Content
1 michael 3253 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2     <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3     <title>DatabasePrimitivesLibrary: ht_add.c Source File</title>
4     <link href="doxygen.css" rel="stylesheet" type="text/css">
5     </head><body>
6     <!-- Generated by Doxygen 1.4.4 -->
7     <div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
8     <h1>ht_add.c</h1><a href="ht__add_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
9     <a name="l00002"></a>00002 <span class="comment">** Copyright (C) 2002 by Kevin L. Mitchell &lt;klmitch@mit.edu&gt;</span>
10     <a name="l00003"></a>00003 <span class="comment">**</span>
11     <a name="l00004"></a>00004 <span class="comment">** This library is free software; you can redistribute it and/or</span>
12     <a name="l00005"></a>00005 <span class="comment">** modify it under the terms of the GNU Library General Public</span>
13     <a name="l00006"></a>00006 <span class="comment">** License as published by the Free Software Foundation; either</span>
14     <a name="l00007"></a>00007 <span class="comment">** version 2 of the License, or (at your option) any later version.</span>
15     <a name="l00008"></a>00008 <span class="comment">**</span>
16     <a name="l00009"></a>00009 <span class="comment">** This library is distributed in the hope that it will be useful,</span>
17     <a name="l00010"></a>00010 <span class="comment">** but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
18     <a name="l00011"></a>00011 <span class="comment">** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
19     <a name="l00012"></a>00012 <span class="comment">** Library General Public License for more details.</span>
20     <a name="l00013"></a>00013 <span class="comment">**</span>
21     <a name="l00014"></a>00014 <span class="comment">** You should have received a copy of the GNU Library General Public</span>
22     <a name="l00015"></a>00015 <span class="comment">** License along with this library; if not, write to the Free</span>
23     <a name="l00016"></a>00016 <span class="comment">** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</span>
24     <a name="l00017"></a>00017 <span class="comment">** MA 02111-1307, USA</span>
25     <a name="l00018"></a>00018 <span class="comment">**</span>
26     <a name="l00019"></a>00019 <span class="comment">** @(#)$Id: ht__add_8c-source.html,v 1.3 2006/09/04 15:12:16 spale Exp $</span>
27     <a name="l00020"></a>00020 <span class="comment">*/</span>
28     <a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="dbprim_8h.html">dbprim.h</a>"</span>
29     <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="dbprim__int_8h.html">dbprim_int.h</a>"</span>
30     <a name="l00030"></a>00030
31     <a name="l00031"></a>00031 <a class="code" href="dbprim__int_8h.html#a0">RCSTAG</a>(<span class="stringliteral">"@(#)$Id: ht__add_8c-source.html,v 1.3 2006/09/04 15:12:16 spale Exp $"</span>);
32     <a name="l00032"></a>00032
33     <a name="l00033"></a>00033 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
34     <a name="l00034"></a><a class="code" href="group__dbprim__hash.html#ga11">00034</a> <a class="code" href="group__dbprim__hash.html#ga11">ht_add</a>(<a class="code" href="struct__hash__table__s.html">hash_table_t</a> *table, <a class="code" href="struct__hash__entry__s.html">hash_entry_t</a> *entry, <a class="code" href="struct__db__key__s.html">db_key_t</a> *key)
35     <a name="l00035"></a>00035 {
36     <a name="l00036"></a>00036 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> retval;
37     <a name="l00037"></a>00037
38     <a name="l00038"></a>00038 initialize_dbpr_error_table(); <span class="comment">/* initialize error table */</span>
39     <a name="l00039"></a>00039
40     <a name="l00040"></a>00040 <span class="keywordflow">if</span> (!<a class="code" href="group__dbprim__hash.html#ga27">ht_verify</a>(table) || !<a class="code" href="group__dbprim__hash.html#ga39">he_verify</a>(entry) || !key) <span class="comment">/* verify arguments */</span>
41     <a name="l00041"></a>00041 <span class="keywordflow">return</span> DB_ERR_BADARGS;
42     <a name="l00042"></a>00042
43     <a name="l00043"></a>00043 <span class="keywordflow">if</span> (entry-&gt;<a class="code" href="struct__hash__entry__s.html#o2">he_table</a>) <span class="comment">/* it's already in a table... */</span>
44     <a name="l00044"></a>00044 <span class="keywordflow">return</span> DB_ERR_BUSY;
45     <a name="l00045"></a>00045
46     <a name="l00046"></a>00046 <span class="keywordflow">if</span> (table-&gt;<a class="code" href="struct__hash__table__s.html#o1">ht_flags</a> &amp; <a class="code" href="dbprim_8h.html#a25">HASH_FLAG_FREEZE</a>) <span class="comment">/* don't add to frozen tables */</span>
47     <a name="l00047"></a>00047 <span class="keywordflow">return</span> DB_ERR_FROZEN;
48     <a name="l00048"></a>00048
49     <a name="l00049"></a>00049 <span class="keywordflow">if</span> (!table-&gt;<a class="code" href="struct__hash__table__s.html#o6">ht_table</a> &amp;&amp; !(table-&gt;<a class="code" href="struct__hash__table__s.html#o1">ht_flags</a> &amp; <a class="code" href="group__dbprim__hash.html#ga23">HASH_FLAG_AUTOGROW</a>))
50     <a name="l00050"></a>00050 <span class="keywordflow">return</span> DB_ERR_NOTABLE;
51     <a name="l00051"></a>00051
52     <a name="l00052"></a>00052 <span class="comment">/* It looks like we could optimize here, but don't be deceived--the table</span>
53     <a name="l00053"></a>00053 <span class="comment"> * may grow between here and when we fill in the entry's hash value, and</span>
54     <a name="l00054"></a>00054 <span class="comment"> * that would change the hash value.</span>
55     <a name="l00055"></a>00055 <span class="comment"> */</span>
56     <a name="l00056"></a>00056 <span class="keywordflow">if</span> (!<a class="code" href="group__dbprim__hash.html#ga14">ht_find</a>(table, 0, key)) <span class="comment">/* don't permit duplicates */</span>
57     <a name="l00057"></a>00057 <span class="keywordflow">return</span> DB_ERR_DUPLICATE;
58     <a name="l00058"></a>00058
59     <a name="l00059"></a>00059 <span class="comment">/* grow the table if necessary and allowed */</span>
60     <a name="l00060"></a>00060 <span class="keywordflow">if</span> ((table-&gt;<a class="code" href="struct__hash__table__s.html#o3">ht_count</a> + 1) &gt; table-&gt;<a class="code" href="struct__hash__table__s.html#o4">ht_rollover</a> &amp;&amp;
61     <a name="l00061"></a>00061 (table-&gt;<a class="code" href="struct__hash__table__s.html#o1">ht_flags</a> &amp; <a class="code" href="group__dbprim__hash.html#ga23">HASH_FLAG_AUTOGROW</a>) &amp;&amp;
62     <a name="l00062"></a>00062 (retval = <a class="code" href="group__dbprim__hash.html#ga17">ht_resize</a>(table, <a class="code" href="group__dbprim__hash.html#ga49">_hash_fuzz</a>(table-&gt;<a class="code" href="struct__hash__table__s.html#o3">ht_count</a> + 1))))
63     <a name="l00063"></a>00063 <span class="keywordflow">return</span> retval;
64     <a name="l00064"></a>00064
65     <a name="l00065"></a>00065 <span class="comment">/* Force the link element to point to the entry */</span>
66     <a name="l00066"></a>00066 <a class="code" href="group__dbprim__link.html#ga25">le_object</a>(&amp;entry-&gt;<a class="code" href="struct__hash__entry__s.html#o1">he_elem</a>) = entry;
67     <a name="l00067"></a>00067
68     <a name="l00068"></a>00068 <span class="comment">/* copy key value into the hash entry */</span>
69     <a name="l00069"></a>00069 entry-&gt;<a class="code" href="struct__hash__entry__s.html#o4">he_key</a> = *key; <span class="comment">/* thank goodness for structure copy! */</span>
70     <a name="l00070"></a>00070
71     <a name="l00071"></a>00071 <span class="comment">/* get the hash value for the entry */</span>
72     <a name="l00072"></a>00072 entry-&gt;<a class="code" href="struct__hash__entry__s.html#o3">he_hash</a> =
73     <a name="l00073"></a>00073 (*table-&gt;<a class="code" href="struct__hash__table__s.html#o7">ht_func</a>)(table, &amp;entry-&gt;<a class="code" href="struct__hash__entry__s.html#o4">he_key</a>) % table-&gt;<a class="code" href="struct__hash__table__s.html#o2">ht_modulus</a>;
74     <a name="l00074"></a>00074
75     <a name="l00075"></a>00075 <span class="comment">/* Now add the entry to the table... */</span>
76     <a name="l00076"></a>00076 <span class="keywordflow">if</span> ((retval = <a class="code" href="group__dbprim__link.html#ga6">ll_add</a>(&amp;table-&gt;<a class="code" href="struct__hash__table__s.html#o6">ht_table</a>[entry-&gt;<a class="code" href="struct__hash__entry__s.html#o3">he_hash</a>], &amp;entry-&gt;<a class="code" href="struct__hash__entry__s.html#o1">he_elem</a>,
77     <a name="l00077"></a>00077 <a class="code" href="group__dbprim__link.html#gga28a133">LINK_LOC_HEAD</a>, 0)))
78     <a name="l00078"></a>00078 <span class="keywordflow">return</span> retval;
79     <a name="l00079"></a>00079
80     <a name="l00080"></a>00080 table-&gt;<a class="code" href="struct__hash__table__s.html#o3">ht_count</a>++; <span class="comment">/* OK, now increment element count */</span>
81     <a name="l00081"></a>00081
82     <a name="l00082"></a>00082 entry-&gt;<a class="code" href="struct__hash__entry__s.html#o2">he_table</a> = table; <span class="comment">/* point entry at table */</span>
83     <a name="l00083"></a>00083
84     <a name="l00084"></a>00084 <span class="keywordflow">return</span> 0;
85     <a name="l00085"></a>00085 }
86     </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sat Jul 15 14:10:33 2006 for DatabasePrimitivesLibrary by&nbsp;
87     <a href="http://www.doxygen.org/index.html">
88     <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </small></address>
89     </body>
90     </html>