1 /* Routines for name->symbol lookups in GDB.
3 Copyright (C) 2003, 2007 Free Software Foundation, Inc.
5 Contributed by David Carlton <carlton@bactrian.org> and by Kealia,
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
26 #include "gdb_obstack.h"
29 #include "gdb_assert.h"
30 #include "dictionary.h"
32 /* This file implements dictionaries, which are tables that associate
33 symbols to names. They are represented by an opaque type 'struct
34 dictionary'. That type has various internal implementations, which
35 you can choose between depending on what properties you need
36 (e.g. fast lookup, order-preserving, expandable).
38 Each dictionary starts with a 'virtual function table' that
39 contains the functions that actually implement the various
40 operations that dictionaries provide. (Note, however, that, for
41 the sake of client code, we also provide some functions that can be
42 implemented generically in terms of the functions in the vtable.)
44 To add a new dictionary implementation <impl>, what you should do
47 * Add a new element DICT_<IMPL> to dict_type.
49 * Create a new structure dictionary_<impl>. If your new
50 implementation is a variant of an existing one, make sure that
51 their structs have the same initial data members. Define accessor
52 macros for your new data members.
54 * Implement all the functions in dict_vector as static functions,
55 whose name is the same as the corresponding member of dict_vector
56 plus _<impl>. You don't have to do this for those members where
57 you can reuse existing generic functions
58 (e.g. add_symbol_nonexpandable, free_obstack) or in the case where
59 your new implementation is a variant of an existing implementation
60 and where the variant doesn't affect the member function in
63 * Define a static const struct dict_vector dict_<impl>_vector.
65 * Define a function dict_create_<impl> to create these
66 gizmos. Add its declaration to dictionary.h.
68 To add a new operation <op> on all existing implementations, what
71 * Add a new member <op> to struct dict_vector.
73 * If there is useful generic behavior <op>, define a static
74 function <op>_something_informative that implements that behavior.
75 (E.g. add_symbol_nonexpandable, free_obstack.)
77 * For every implementation <impl> that should have its own specific
78 behavior for <op>, define a static function <op>_<impl>
81 * Modify all existing dict_vector_<impl>'s to include the appropriate
84 * Define a function dict_<op> that looks up <op> in the dict_vector
85 and calls the appropriate function. Add a declaration for
86 dict_<op> to dictionary.h.
90 /* An enum representing the various implementations of dictionaries.
91 Used only for debugging. */
95 /* Symbols are stored in a fixed-size hash table. */
97 /* Symbols are stored in an expandable hash table. */
98 DICT_HASHED_EXPANDABLE
,
99 /* Symbols are stored in a fixed-size array. */
101 /* Symbols are stored in an expandable array. */
102 DICT_LINEAR_EXPANDABLE
105 /* The virtual function table. */
109 /* The type of the dictionary. This is only here to make debugging
110 a bit easier; it's not actually used. */
112 /* The function to free a dictionary. */
113 void (*free
) (struct dictionary
*dict
);
114 /* Add a symbol to a dictionary, if possible. */
115 void (*add_symbol
) (struct dictionary
*dict
, struct symbol
*sym
);
116 /* Iterator functions. */
117 struct symbol
*(*iterator_first
) (const struct dictionary
*dict
,
118 struct dict_iterator
*iterator
);
119 struct symbol
*(*iterator_next
) (struct dict_iterator
*iterator
);
120 /* Functions to iterate over symbols with a given name. */
121 struct symbol
*(*iter_name_first
) (const struct dictionary
*dict
,
123 struct dict_iterator
*iterator
);
124 struct symbol
*(*iter_name_next
) (const char *name
,
125 struct dict_iterator
*iterator
);
126 /* A size function, for maint print symtabs. */
127 int (*size
) (const struct dictionary
*dict
);
130 /* Now comes the structs used to store the data for different
131 implementations. If two implementations have data in common, put
132 the common data at the top of their structs, ordered in the same
135 struct dictionary_hashed
138 struct symbol
**buckets
;
141 struct dictionary_hashed_expandable
143 /* How many buckets we currently have. */
145 struct symbol
**buckets
;
146 /* How many syms we currently have; we need this so we will know
147 when to add more buckets. */
151 struct dictionary_linear
154 struct symbol
**syms
;
157 struct dictionary_linear_expandable
159 /* How many symbols we currently have. */
161 struct symbol
**syms
;
162 /* How many symbols we can store before needing to reallocate. */
166 /* And now, the star of our show. */
170 const struct dict_vector
*vector
;
173 struct dictionary_hashed hashed
;
174 struct dictionary_hashed_expandable hashed_expandable
;
175 struct dictionary_linear linear
;
176 struct dictionary_linear_expandable linear_expandable
;
181 /* Accessor macros. */
183 #define DICT_VECTOR(d) (d)->vector
185 /* These can be used for DICT_HASHED_EXPANDABLE, too. */
187 #define DICT_HASHED_NBUCKETS(d) (d)->data.hashed.nbuckets
188 #define DICT_HASHED_BUCKETS(d) (d)->data.hashed.buckets
189 #define DICT_HASHED_BUCKET(d,i) DICT_HASHED_BUCKETS (d) [i]
191 #define DICT_HASHED_EXPANDABLE_NSYMS(d) (d)->data.hashed_expandable.nsyms
193 /* These can be used for DICT_LINEAR_EXPANDABLEs, too. */
195 #define DICT_LINEAR_NSYMS(d) (d)->data.linear.nsyms
196 #define DICT_LINEAR_SYMS(d) (d)->data.linear.syms
197 #define DICT_LINEAR_SYM(d,i) DICT_LINEAR_SYMS (d) [i]
199 #define DICT_LINEAR_EXPANDABLE_CAPACITY(d) \
200 (d)->data.linear_expandable.capacity
202 /* The initial size of a DICT_*_EXPANDABLE dictionary. */
204 #define DICT_EXPANDABLE_INITIAL_CAPACITY 10
206 /* This calculates the number of buckets we'll use in a hashtable,
207 given the number of symbols that it will contain. */
209 #define DICT_HASHTABLE_SIZE(n) ((n)/5 + 1)
211 /* Accessor macros for dict_iterators; they're here rather than
212 dictionary.h because code elsewhere should treat dict_iterators as
215 /* The dictionary that the iterator is associated to. */
216 #define DICT_ITERATOR_DICT(iter) (iter)->dict
217 /* For linear dictionaries, the index of the last symbol returned; for
218 hashed dictionaries, the bucket of the last symbol returned. */
219 #define DICT_ITERATOR_INDEX(iter) (iter)->index
220 /* For hashed dictionaries, this points to the last symbol returned;
221 otherwise, this is unused. */
222 #define DICT_ITERATOR_CURRENT(iter) (iter)->current
224 /* Declarations of functions for vectors. */
226 /* Functions that might work across a range of dictionary types. */
228 static void add_symbol_nonexpandable (struct dictionary
*dict
,
231 static void free_obstack (struct dictionary
*dict
);
233 /* Functions for DICT_HASHED and DICT_HASHED_EXPANDABLE
236 static struct symbol
*iterator_first_hashed (const struct dictionary
*dict
,
237 struct dict_iterator
*iterator
);
239 static struct symbol
*iterator_next_hashed (struct dict_iterator
*iterator
);
241 static struct symbol
*iter_name_first_hashed (const struct dictionary
*dict
,
243 struct dict_iterator
*iterator
);
245 static struct symbol
*iter_name_next_hashed (const char *name
,
246 struct dict_iterator
*iterator
);
248 /* Functions only for DICT_HASHED. */
250 static int size_hashed (const struct dictionary
*dict
);
252 /* Functions only for DICT_HASHED_EXPANDABLE. */
254 static void free_hashed_expandable (struct dictionary
*dict
);
256 static void add_symbol_hashed_expandable (struct dictionary
*dict
,
259 static int size_hashed_expandable (const struct dictionary
*dict
);
261 /* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE
264 static struct symbol
*iterator_first_linear (const struct dictionary
*dict
,
265 struct dict_iterator
*iterator
);
267 static struct symbol
*iterator_next_linear (struct dict_iterator
*iterator
);
269 static struct symbol
*iter_name_first_linear (const struct dictionary
*dict
,
271 struct dict_iterator
*iterator
);
273 static struct symbol
*iter_name_next_linear (const char *name
,
274 struct dict_iterator
*iterator
);
276 static int size_linear (const struct dictionary
*dict
);
278 /* Functions only for DICT_LINEAR_EXPANDABLE. */
280 static void free_linear_expandable (struct dictionary
*dict
);
282 static void add_symbol_linear_expandable (struct dictionary
*dict
,
285 /* Various vectors that we'll actually use. */
287 static const struct dict_vector dict_hashed_vector
=
289 DICT_HASHED
, /* type */
290 free_obstack
, /* free */
291 add_symbol_nonexpandable
, /* add_symbol */
292 iterator_first_hashed
, /* iteractor_first */
293 iterator_next_hashed
, /* iterator_next */
294 iter_name_first_hashed
, /* iter_name_first */
295 iter_name_next_hashed
, /* iter_name_next */
296 size_hashed
, /* size */
299 static const struct dict_vector dict_hashed_expandable_vector
=
301 DICT_HASHED_EXPANDABLE
, /* type */
302 free_hashed_expandable
, /* free */
303 add_symbol_hashed_expandable
, /* add_symbol */
304 iterator_first_hashed
, /* iteractor_first */
305 iterator_next_hashed
, /* iterator_next */
306 iter_name_first_hashed
, /* iter_name_first */
307 iter_name_next_hashed
, /* iter_name_next */
308 size_hashed_expandable
, /* size */
311 static const struct dict_vector dict_linear_vector
=
313 DICT_LINEAR
, /* type */
314 free_obstack
, /* free */
315 add_symbol_nonexpandable
, /* add_symbol */
316 iterator_first_linear
, /* iteractor_first */
317 iterator_next_linear
, /* iterator_next */
318 iter_name_first_linear
, /* iter_name_first */
319 iter_name_next_linear
, /* iter_name_next */
320 size_linear
, /* size */
323 static const struct dict_vector dict_linear_expandable_vector
=
325 DICT_LINEAR_EXPANDABLE
, /* type */
326 free_linear_expandable
, /* free */
327 add_symbol_linear_expandable
, /* add_symbol */
328 iterator_first_linear
, /* iteractor_first */
329 iterator_next_linear
, /* iterator_next */
330 iter_name_first_linear
, /* iter_name_first */
331 iter_name_next_linear
, /* iter_name_next */
332 size_linear
, /* size */
335 /* Declarations of helper functions (i.e. ones that don't go into
338 static struct symbol
*iterator_hashed_advance (struct dict_iterator
*iter
);
340 static void insert_symbol_hashed (struct dictionary
*dict
,
343 static void expand_hashtable (struct dictionary
*dict
);
345 /* The creation functions. */
347 /* Create a dictionary implemented via a fixed-size hashtable. All
348 memory it uses is allocated on OBSTACK; the environment is
349 initialized from SYMBOL_LIST. */
352 dict_create_hashed (struct obstack
*obstack
,
353 const struct pending
*symbol_list
)
355 struct dictionary
*retval
;
356 int nsyms
= 0, nbuckets
, i
;
357 struct symbol
**buckets
;
358 const struct pending
*list_counter
;
360 retval
= obstack_alloc (obstack
, sizeof (struct dictionary
));
361 DICT_VECTOR (retval
) = &dict_hashed_vector
;
363 /* Calculate the number of symbols, and allocate space for them. */
364 for (list_counter
= symbol_list
;
365 list_counter
!= NULL
;
366 list_counter
= list_counter
->next
)
368 nsyms
+= list_counter
->nsyms
;
370 nbuckets
= DICT_HASHTABLE_SIZE (nsyms
);
371 DICT_HASHED_NBUCKETS (retval
) = nbuckets
;
372 buckets
= obstack_alloc (obstack
, nbuckets
* sizeof (struct symbol
*));
373 memset (buckets
, 0, nbuckets
* sizeof (struct symbol
*));
374 DICT_HASHED_BUCKETS (retval
) = buckets
;
376 /* Now fill the buckets. */
377 for (list_counter
= symbol_list
;
378 list_counter
!= NULL
;
379 list_counter
= list_counter
->next
)
381 for (i
= list_counter
->nsyms
- 1; i
>= 0; --i
)
383 insert_symbol_hashed (retval
, list_counter
->symbol
[i
]);
390 /* Create a dictionary implemented via a hashtable that grows as
391 necessary. The dictionary is initially empty; to add symbols to
392 it, call dict_add_symbol(). Call dict_free() when you're done with
395 extern struct dictionary
*
396 dict_create_hashed_expandable (void)
398 struct dictionary
*retval
;
400 retval
= xmalloc (sizeof (struct dictionary
));
401 DICT_VECTOR (retval
) = &dict_hashed_expandable_vector
;
402 DICT_HASHED_NBUCKETS (retval
) = DICT_EXPANDABLE_INITIAL_CAPACITY
;
403 DICT_HASHED_BUCKETS (retval
) = xcalloc (DICT_EXPANDABLE_INITIAL_CAPACITY
,
404 sizeof (struct symbol
*));
405 DICT_HASHED_EXPANDABLE_NSYMS (retval
) = 0;
410 /* Create a dictionary implemented via a fixed-size array. All memory
411 it uses is allocated on OBSTACK; the environment is initialized
412 from the SYMBOL_LIST. The symbols are ordered in the same order
413 that they're found in SYMBOL_LIST. */
416 dict_create_linear (struct obstack
*obstack
,
417 const struct pending
*symbol_list
)
419 struct dictionary
*retval
;
421 struct symbol
**syms
;
422 const struct pending
*list_counter
;
424 retval
= obstack_alloc (obstack
, sizeof (struct dictionary
));
425 DICT_VECTOR (retval
) = &dict_linear_vector
;
427 /* Calculate the number of symbols, and allocate space for them. */
428 for (list_counter
= symbol_list
;
429 list_counter
!= NULL
;
430 list_counter
= list_counter
->next
)
432 nsyms
+= list_counter
->nsyms
;
434 DICT_LINEAR_NSYMS (retval
) = nsyms
;
435 syms
= obstack_alloc (obstack
, nsyms
* sizeof (struct symbol
*));
436 DICT_LINEAR_SYMS (retval
) = syms
;
438 /* Now fill in the symbols. Start filling in from the back, so as
439 to preserve the original order of the symbols. */
440 for (list_counter
= symbol_list
, j
= nsyms
- 1;
441 list_counter
!= NULL
;
442 list_counter
= list_counter
->next
)
444 for (i
= list_counter
->nsyms
- 1;
448 syms
[j
] = list_counter
->symbol
[i
];
455 /* Create a dictionary implemented via an array that grows as
456 necessary. The dictionary is initially empty; to add symbols to
457 it, call dict_add_symbol(). Call dict_free() when you're done with
461 dict_create_linear_expandable (void)
463 struct dictionary
*retval
;
465 retval
= xmalloc (sizeof (struct dictionary
));
466 DICT_VECTOR (retval
) = &dict_linear_expandable_vector
;
467 DICT_LINEAR_NSYMS (retval
) = 0;
468 DICT_LINEAR_EXPANDABLE_CAPACITY (retval
)
469 = DICT_EXPANDABLE_INITIAL_CAPACITY
;
470 DICT_LINEAR_SYMS (retval
)
471 = xmalloc (DICT_LINEAR_EXPANDABLE_CAPACITY (retval
)
472 * sizeof (struct symbol
*));
477 /* The functions providing the dictionary interface. */
479 /* Free the memory used by a dictionary that's not on an obstack. (If
483 dict_free (struct dictionary
*dict
)
485 (DICT_VECTOR (dict
))->free (dict
);
488 /* Add SYM to DICT. DICT had better be expandable. */
491 dict_add_symbol (struct dictionary
*dict
, struct symbol
*sym
)
493 (DICT_VECTOR (dict
))->add_symbol (dict
, sym
);
496 /* Initialize ITERATOR to point at the first symbol in DICT, and
497 return that first symbol, or NULL if DICT is empty. */
500 dict_iterator_first (const struct dictionary
*dict
,
501 struct dict_iterator
*iterator
)
503 return (DICT_VECTOR (dict
))->iterator_first (dict
, iterator
);
506 /* Advance ITERATOR, and return the next symbol, or NULL if there are
510 dict_iterator_next (struct dict_iterator
*iterator
)
512 return (DICT_VECTOR (DICT_ITERATOR_DICT (iterator
)))
513 ->iterator_next (iterator
);
517 dict_iter_name_first (const struct dictionary
*dict
,
519 struct dict_iterator
*iterator
)
521 return (DICT_VECTOR (dict
))->iter_name_first (dict
, name
, iterator
);
525 dict_iter_name_next (const char *name
, struct dict_iterator
*iterator
)
527 return (DICT_VECTOR (DICT_ITERATOR_DICT (iterator
)))
528 ->iter_name_next (name
, iterator
);
532 dict_size (const struct dictionary
*dict
)
534 return (DICT_VECTOR (dict
))->size (dict
);
537 /* Now come functions (well, one function, currently) that are
538 implemented generically by means of the vtable. Typically, they're
541 /* Test to see if DICT is empty. */
544 dict_empty (struct dictionary
*dict
)
546 struct dict_iterator iter
;
548 return (dict_iterator_first (dict
, &iter
) == NULL
);
552 /* The functions implementing the dictionary interface. */
554 /* Generic functions, where appropriate. */
557 free_obstack (struct dictionary
*dict
)
563 add_symbol_nonexpandable (struct dictionary
*dict
, struct symbol
*sym
)
565 internal_error (__FILE__
, __LINE__
,
566 _("dict_add_symbol: non-expandable dictionary"));
569 /* Functions for DICT_HASHED and DICT_HASHED_EXPANDABLE. */
571 static struct symbol
*
572 iterator_first_hashed (const struct dictionary
*dict
,
573 struct dict_iterator
*iterator
)
575 DICT_ITERATOR_DICT (iterator
) = dict
;
576 DICT_ITERATOR_INDEX (iterator
) = -1;
577 return iterator_hashed_advance (iterator
);
580 static struct symbol
*
581 iterator_next_hashed (struct dict_iterator
*iterator
)
583 const struct dictionary
*dict
= DICT_ITERATOR_DICT (iterator
);
586 next
= DICT_ITERATOR_CURRENT (iterator
)->hash_next
;
589 return iterator_hashed_advance (iterator
);
592 DICT_ITERATOR_CURRENT (iterator
) = next
;
597 static struct symbol
*
598 iterator_hashed_advance (struct dict_iterator
*iterator
)
600 const struct dictionary
*dict
= DICT_ITERATOR_DICT (iterator
);
601 int nbuckets
= DICT_HASHED_NBUCKETS (dict
);
604 for (i
= DICT_ITERATOR_INDEX (iterator
) + 1; i
< nbuckets
; ++i
)
606 struct symbol
*sym
= DICT_HASHED_BUCKET (dict
, i
);
610 DICT_ITERATOR_INDEX (iterator
) = i
;
611 DICT_ITERATOR_CURRENT (iterator
) = sym
;
619 static struct symbol
*
620 iter_name_first_hashed (const struct dictionary
*dict
,
622 struct dict_iterator
*iterator
)
624 unsigned int hash_index
625 = msymbol_hash_iw (name
) % DICT_HASHED_NBUCKETS (dict
);
628 DICT_ITERATOR_DICT (iterator
) = dict
;
630 /* Loop through the symbols in the given bucket, breaking when SYM
631 first matches. If SYM never matches, it will be set to NULL;
632 either way, we have the right return value. */
634 for (sym
= DICT_HASHED_BUCKET (dict
, hash_index
);
636 sym
= sym
->hash_next
)
638 /* Warning: the order of arguments to strcmp_iw matters! */
639 if (strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
646 DICT_ITERATOR_CURRENT (iterator
) = sym
;
650 static struct symbol
*
651 iter_name_next_hashed (const char *name
, struct dict_iterator
*iterator
)
655 for (next
= DICT_ITERATOR_CURRENT (iterator
)->hash_next
;
657 next
= next
->hash_next
)
659 if (strcmp_iw (SYMBOL_SEARCH_NAME (next
), name
) == 0)
663 DICT_ITERATOR_CURRENT (iterator
) = next
;
668 /* Insert SYM into DICT. */
671 insert_symbol_hashed (struct dictionary
*dict
,
674 unsigned int hash_index
;
675 struct symbol
**buckets
= DICT_HASHED_BUCKETS (dict
);
677 hash_index
= (msymbol_hash_iw (SYMBOL_SEARCH_NAME (sym
))
678 % DICT_HASHED_NBUCKETS (dict
));
679 sym
->hash_next
= buckets
[hash_index
];
680 buckets
[hash_index
] = sym
;
684 size_hashed (const struct dictionary
*dict
)
686 return DICT_HASHED_NBUCKETS (dict
);
689 /* Functions only for DICT_HASHED_EXPANDABLE. */
692 free_hashed_expandable (struct dictionary
*dict
)
694 xfree (DICT_HASHED_BUCKETS (dict
));
699 add_symbol_hashed_expandable (struct dictionary
*dict
,
702 int nsyms
= ++DICT_HASHED_EXPANDABLE_NSYMS (dict
);
704 if (DICT_HASHTABLE_SIZE (nsyms
) > DICT_HASHED_NBUCKETS (dict
))
705 expand_hashtable (dict
);
707 insert_symbol_hashed (dict
, sym
);
708 DICT_HASHED_EXPANDABLE_NSYMS (dict
) = nsyms
;
712 size_hashed_expandable (const struct dictionary
*dict
)
714 return DICT_HASHED_EXPANDABLE_NSYMS (dict
);
718 expand_hashtable (struct dictionary
*dict
)
720 int old_nbuckets
= DICT_HASHED_NBUCKETS (dict
);
721 struct symbol
**old_buckets
= DICT_HASHED_BUCKETS (dict
);
722 int new_nbuckets
= 2*old_nbuckets
+ 1;
723 struct symbol
**new_buckets
= xcalloc (new_nbuckets
,
724 sizeof (struct symbol
*));
727 DICT_HASHED_NBUCKETS (dict
) = new_nbuckets
;
728 DICT_HASHED_BUCKETS (dict
) = new_buckets
;
730 for (i
= 0; i
< old_nbuckets
; ++i
) {
731 struct symbol
*sym
, *next_sym
;
733 sym
= old_buckets
[i
];
735 for (next_sym
= sym
->hash_next
;
737 next_sym
= sym
->hash_next
) {
738 insert_symbol_hashed (dict
, sym
);
742 insert_symbol_hashed (dict
, sym
);
749 /* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE. */
751 static struct symbol
*
752 iterator_first_linear (const struct dictionary
*dict
,
753 struct dict_iterator
*iterator
)
755 DICT_ITERATOR_DICT (iterator
) = dict
;
756 DICT_ITERATOR_INDEX (iterator
) = 0;
757 return DICT_LINEAR_NSYMS (dict
) ? DICT_LINEAR_SYM (dict
, 0) : NULL
;
760 static struct symbol
*
761 iterator_next_linear (struct dict_iterator
*iterator
)
763 const struct dictionary
*dict
= DICT_ITERATOR_DICT (iterator
);
765 if (++DICT_ITERATOR_INDEX (iterator
) >= DICT_LINEAR_NSYMS (dict
))
768 return DICT_LINEAR_SYM (dict
, DICT_ITERATOR_INDEX (iterator
));
771 static struct symbol
*
772 iter_name_first_linear (const struct dictionary
*dict
,
774 struct dict_iterator
*iterator
)
776 DICT_ITERATOR_DICT (iterator
) = dict
;
777 DICT_ITERATOR_INDEX (iterator
) = -1;
779 return iter_name_next_linear (name
, iterator
);
782 static struct symbol
*
783 iter_name_next_linear (const char *name
, struct dict_iterator
*iterator
)
785 const struct dictionary
*dict
= DICT_ITERATOR_DICT (iterator
);
786 int i
, nsyms
= DICT_LINEAR_NSYMS (dict
);
787 struct symbol
*sym
, *retval
= NULL
;
789 for (i
= DICT_ITERATOR_INDEX (iterator
) + 1; i
< nsyms
; ++i
)
791 sym
= DICT_LINEAR_SYM (dict
, i
);
792 if (strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
799 DICT_ITERATOR_INDEX (iterator
) = i
;
805 size_linear (const struct dictionary
*dict
)
807 return DICT_LINEAR_NSYMS (dict
);
810 /* Functions only for DICT_LINEAR_EXPANDABLE. */
813 free_linear_expandable (struct dictionary
*dict
)
815 xfree (DICT_LINEAR_SYMS (dict
));
821 add_symbol_linear_expandable (struct dictionary
*dict
,
824 int nsyms
= ++DICT_LINEAR_NSYMS (dict
);
826 /* Do we have enough room? If not, grow it. */
827 if (nsyms
> DICT_LINEAR_EXPANDABLE_CAPACITY (dict
)) {
828 DICT_LINEAR_EXPANDABLE_CAPACITY (dict
) *= 2;
829 DICT_LINEAR_SYMS (dict
)
830 = xrealloc (DICT_LINEAR_SYMS (dict
),
831 DICT_LINEAR_EXPANDABLE_CAPACITY (dict
)
832 * sizeof (struct symbol
*));
835 DICT_LINEAR_SYM (dict
, nsyms
- 1) = sym
;