3 ### Symbol table, using universal hashing
5 ### (c) 2005 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to mLib.
12 ### mLib/Python is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### mLib/Python is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with mLib/Python; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 cdef struct _sym_entry:
30 cdef class SymTable (_Mapping):
32 SymTable([DICT], **KW)
34 A mapping keyed by strings.
39 cdef int _init(me) except -1:
41 cdef void *_find(me, object key, unsigned *f) except NULL:
44 cdef _sym_entry *e = NULL
45 TEXT_PTRLEN(key, &p, &n)
47 e = <_sym_entry *>sym_find(&me._t, <char *>p, n, 0, NULL)
51 e = <_sym_entry *>sym_find(&me._t, <char *>p, n, PSIZEOF(e), f)
55 cdef object _key(me, void *e):
56 return TEXT_FROMSTRLEN(SYM_NAME(e), SYM_LEN(e))
57 cdef object _value(me, void *e):
58 cdef _sym_entry *ee = <_sym_entry *>e
61 cdef void _setval(me, void *e, object val):
62 cdef _sym_entry *ee = <_sym_entry *>e
65 ee.v = <PyObject *>val
67 cdef void _del(me, void *e):
68 cdef _sym_entry *ee = <_sym_entry *>e
71 sym_remove(&me._t, <void *>ee)
72 cdef _MapIterator _iter(me):
75 cdef class _SymIter (_MapIterator):
78 def __cinit__(me, SymTable t not None):
80 sym_mkiter(&me.i, &me.t._t)
82 return sym_next(&me.i)
84 ###----- That's all, folks --------------------------------------------------