Debian Codegraph @

ext/sparse/sptab.h

raw
1 /*
2 * sptab.h - Sparse hashtable
3 *
4 * Copyright (c) 2009-2024 Shiro Kawai <[email protected]>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the authors nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef GAUCHE_SPTAB_H
35 #define GAUCHE_SPTAB_H
36
37 #include <gauche.h>
38 #include <gauche/extend.h>
39
40 #if defined(EXTSPARSE_EXPORTS)
41 #define LIBGAUCHE_EXT_BODY
42 #endif
43 #include <gauche/extern.h> /* redefine SCM_EXTERN */
44
45 #include "ctrie.h"
46
47 typedef struct SparseTableRec {
48 SCM_HEADER;
49 CompactTrie trie;
50 u_long numEntries;
51 u_long (*hashfn)(ScmObj key);
52 int (*cmpfn)(ScmObj a, ScmObj b);
53 ScmComparator *comparator; /* only used for generic table */
54 } SparseTable;
55
56 SCM_CLASS_DECL(Scm_SparseTableClass);
57 #define SCM_CLASS_SPARSE_TABLE (&Scm_SparseTableClass)
58 #define SPARSE_TABLE(obj) ((SparseTable*)(obj))
59 #define SPARSE_TABLE_P(obj) SCM_XTYPEP(obj, SCM_CLASS_SPARSE_TABLE)
60
61 extern ScmObj MakeSparseTable(ScmHashType type, ScmComparator *data,
62 u_long flags);
63 extern ScmObj SparseTableRef(SparseTable *st, ScmObj key, ScmObj fallback);
64 extern ScmObj SparseTableSet(SparseTable *st, ScmObj key,
65 ScmObj value, int flags);
66 extern ScmObj SparseTableDelete(SparseTable *st, ScmObj key);
67 extern void SparseTableClear(SparseTable *st);
68 extern ScmObj SparseTableCopy(const SparseTable *st);
69
70 extern void SparseTableDump(SparseTable *sv);
71 extern void SparseTableCheck(SparseTable *sv);
72
73 /* Iterator */
74 typedef struct SparseTableIterRec {
75 SparseTable *st;
76 CompactTrieIter ctit;
77 ScmObj chain;
78 int end;
79 } SparseTableIter;
80
81 extern void SparseTableIterInit(SparseTableIter *it, SparseTable *st);
82 extern ScmObj SparseTableIterNext(SparseTableIter *it);
83
84 extern void Scm_Init_sptab(ScmModule *mod);
85
86 #endif /*GAUCHE_SPTAB_H*/