ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/vendor/pxys2-2.0.0/pxyservd/dbprim/ht_free.c
Revision: 3252
Committed: Wed Apr 2 20:41:43 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 1995 byte(s)
Log Message:
- Imported pxys2-2.0.0

File Contents

# Content
1 /*
2 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Library General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Library General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Library General Public
15 ** License along with this library; if not, write to the Free
16 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
17 ** MA 02111-1307, USA
18 **
19 ** @(#)$Id: ht_free.c,v 1.2 2003/06/12 01:10:04 klmitch Exp $
20 */
21 #include <stdlib.h>
22
23 #include "dbprim.h"
24 #include "dbprim_int.h"
25
26 RCSTAG("@(#)$Id: ht_free.c,v 1.2 2003/06/12 01:10:04 klmitch Exp $");
27
28 /** \ingroup dbprim_hash
29 * \brief Free memory used by an empty hash table.
30 *
31 * This function releases the memory used by the bucket table in an
32 * empty hash table.
33 *
34 * \param table A pointer to a #hash_table_t.
35 *
36 * \retval DB_ERR_BADARGS An invalid argument was given.
37 * \retval DB_ERR_FROZEN The table is frozen.
38 * \retval DB_ERR_NOTEMPTY The table is not empty.
39 */
40 unsigned long
41 ht_free(hash_table_t *table)
42 {
43 initialize_dbpr_error_table(); /* initialize error table */
44
45 if (!ht_verify(table)) /* verify argument */
46 return DB_ERR_BADARGS;
47
48 if (table->ht_flags & HASH_FLAG_FREEZE) /* don't free from frozen tables */
49 return DB_ERR_FROZEN;
50
51 if (table->ht_count) /* make sure the table's empty */
52 return DB_ERR_NOTEMPTY;
53
54 if (!table->ht_modulus && !table->ht_table) /* short-circuit */
55 return 0;
56
57 free(table->ht_table); /* free allocated memory */
58
59 table->ht_modulus = 0; /* zero the table and modulus */
60 table->ht_table = 0;
61
62 return 0;
63 }