2 * Regular Pattern Analyzer (RPA)
3 * Copyright (c) 2009-2010 Martin Stoilov
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Martin Stoilov <martin@rpasearch.com>
24 #include "rlib/rcarray.h"
25 #include "rlib/rhash.h"
26 #include "rlib/rlist.h"
27 #include "rlib/rstring.h"
29 #include "rlib/robject.h"
36 #define r_map_hashsize(__m__) (1 << (__m__)->nbits)
37 #define r_map_hashmask(__m__) (r_map_hashsize(__m__) - 1)
39 typedef struct rmap_s {
42 unsigned int elt_size;
50 rmap_t *r_map_create(unsigned int elt_size, unsigned int nbits);
51 void r_map_destroy(rmap_t *array);
52 long r_map_lookup(rmap_t *map, long current, const char *name, rsize_t namesize);
53 long r_map_lookup_s(rmap_t *map, long current, const char *name);
54 long r_map_taillookup(rmap_t *map, long current, const char *name, rsize_t namesize);
55 long r_map_taillookup_s(rmap_t *map, long current, const char *name);
56 long r_map_lookup_d(rmap_t *map, long current, double name);
57 long r_map_lookup_l(rmap_t *map, long current, long name);
58 long r_map_add(rmap_t *map, const char *name, rsize_t namesize, rconstpointer pval);
59 long r_map_add_s(rmap_t *map, const char *name, rconstpointer pval);
60 long r_map_add_d(rmap_t *map, double name, rconstpointer pval);
61 long r_map_add_l(rmap_t *map, long name, rconstpointer pval);
64 * The following functions allow the created keys (rstring_t objects) to be added to
65 * GC list and not being destroyed by the rmap_t, but leave it to the users of rmap_t
66 * to decide when to destroy those keys. These is useful for scripting languages with
67 * GC memory management. Another possibility would be to get the key as a rstrit_t* and
68 * make rmap_t completely get out of the memory management business.
70 long r_map_gckey_add(rmap_t *map, rgc_t* gc, const char *name, rsize_t namesize, rconstpointer pval);
71 long r_map_gckey_add_s(rmap_t *map, rgc_t* gc, const char *name, rconstpointer pval);
72 long r_map_gckey_add_d(rmap_t *map, rgc_t* gc, double name, rconstpointer pval);
73 long r_map_gckey_add_l(rmap_t *map, rgc_t* gc, long name, rconstpointer pval);
74 long r_map_setvalue(rmap_t *map, long index, rconstpointer pval);
75 rstring_t *r_map_key(rmap_t *map, unsigned long index);
76 rpointer r_map_value(rmap_t *map, unsigned long index);
77 int r_map_delete(rmap_t *map, unsigned long index);
79 long r_map_first(rmap_t *map);
80 long r_map_last(rmap_t *map);
81 long r_map_next(rmap_t *map, long current);
82 long r_map_prev(rmap_t *map, long current);