f8730fee4f058ff8327bbffe571b6a43e005f5c7
[ircu2.10.12-pk.git] / libs / dbprim / st_init.c
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$
20 */
21 #include "dbprim.h"
22 #include "dbprim_int.h"
23
24 RCSTAG("@(#)$Id$");
25
26 /** \ingroup dbprim_smat
27  *
28  * This function dynamically initializes a sparse matrix table.
29  *
30  * \param table A pointer to a #smat_table_t to be initialized.
31  * \param flags A bit-wise OR of #HASH_FLAG_AUTOGROW and
32  *              #HASH_FLAG_AUTOSHRINK.  If neither behavior is
33  *              desired, use 0.
34  * \param resize
35  *              A #hash_resize_t function pointer for determining
36  *              whether resizing is permitted and/or for notification
37  *              of the resize.
38  * \param extra Extra pointer data that should be associated with the
39  *              sparse matrix table.
40  * \param init_mod
41  *              An initial modulus for the table.  This will
42  *              presumably be extracted by st_modulus() in a previous
43  *              invocation of the application.  A 0 value is valid.
44  *
45  * \retval DB_ERR_BADARGS       An invalid argument was given.
46  * \retval ENOMEM               Unable to allocate memory.
47  */
48 unsigned long
49 st_init(smat_table_t *table, unsigned long flags, smat_resize_t resize,
50         void *extra, unsigned long init_mod)
51 {
52   unsigned long retval;
53
54   initialize_dbpr_error_table(); /* set up error tables */
55
56   if (!table) /* verify arguments */
57     return DB_ERR_BADARGS;
58
59   table->st_resize = resize;
60
61   /* initialize the hash table */
62   if ((retval = ht_init(&table->st_table, flags, _smat_hash, _smat_comp,
63                         _smat_resize, extra, init_mod)))
64     return retval;
65
66   table->st_magic = SMAT_TABLE_MAGIC; /* initialize the rest of the table */
67
68   return 0;
69 }