1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
1297
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
240
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
1
|
29 #endif |
|
30 |
3013
|
31 #include <cassert> |
1962
|
32 #include <cctype> |
3013
|
33 #include <climits> |
|
34 |
|
35 #include <iomanip.h> |
1962
|
36 |
2926
|
37 #include "glob-match.h" |
1755
|
38 #include "str-vec.h" |
|
39 |
1352
|
40 #include "error.h" |
2979
|
41 #include "oct-lvalue.h" |
2975
|
42 #include "ov.h" |
3013
|
43 #include "pager.h" |
1755
|
44 #include "symtab.h" |
1
|
45 #include "utils.h" |
1352
|
46 #include "variables.h" |
1
|
47 |
3013
|
48 octave_allocator |
|
49 symbol_record::symbol_def::allocator (sizeof (symbol_record::symbol_def)); |
195
|
50 |
767
|
51 // Individual records in a symbol table. |
|
52 |
3013
|
53 // XXX FIXME XXX -- there are lots of places below where we should |
|
54 // probably be temporarily ignoring interrupts. |
1
|
55 |
572
|
56 void |
1755
|
57 symbol_record::rename (const string& new_name) |
572
|
58 { |
2791
|
59 if (! read_only_error ("rename")) |
|
60 nm = new_name; |
572
|
61 } |
|
62 |
3013
|
63 void |
|
64 symbol_record::define (const octave_value& v, unsigned int sym_type) |
195
|
65 { |
3013
|
66 if (! (is_variable () && read_only_error ("redefine"))) |
|
67 { |
|
68 if (is_function ()) |
|
69 push_def (new symbol_def ()); |
195
|
70 |
3013
|
71 if (definition->type () == symbol_record::BUILTIN_VARIABLE) |
|
72 sym_type = symbol_record::BUILTIN_VARIABLE; |
1
|
73 |
3013
|
74 definition->define (v, sym_type); |
195
|
75 } |
|
76 } |
|
77 |
|
78 void |
3013
|
79 symbol_record::define_builtin_var (const octave_value& v) |
195
|
80 { |
3013
|
81 define (v, symbol_record::BUILTIN_VARIABLE); |
195
|
82 |
3013
|
83 if (chg_fcn) |
|
84 chg_fcn (); |
1
|
85 } |
|
86 |
3013
|
87 bool |
|
88 symbol_record::define_as_fcn (const octave_value& v) |
1
|
89 { |
3013
|
90 bool retval = false; |
1
|
91 |
3013
|
92 if (! (is_variable () || read_only_error ("redefine"))) |
195
|
93 { |
3013
|
94 replace_all_defs (new symbol_def (v, symbol_record::BUILTIN_FUNCTION)); |
2893
|
95 |
3013
|
96 retval = true; |
1
|
97 } |
|
98 |
2893
|
99 return retval; |
2390
|
100 } |
|
101 |
3013
|
102 bool |
|
103 symbol_record::define (octave_function *f, unsigned int sym_type) |
1
|
104 { |
3013
|
105 bool retval = false; |
2949
|
106 |
3013
|
107 if (! read_only_error ("redefine")) |
|
108 { |
|
109 octave_value tmp (f); |
|
110 |
|
111 replace_all_defs (new symbol_def (tmp, sym_type)); |
|
112 |
|
113 retval = true; |
|
114 } |
2949
|
115 |
|
116 return retval; |
1
|
117 } |
|
118 |
|
119 void |
195
|
120 symbol_record::clear (void) |
1
|
121 { |
195
|
122 if (linked_to_global) |
1
|
123 { |
3013
|
124 if (--definition->count <= 0) |
|
125 delete definition; |
|
126 |
|
127 definition = new symbol_def (); |
|
128 |
195
|
129 linked_to_global = 0; |
1
|
130 } |
2846
|
131 else if (! tagged_static) |
195
|
132 { |
3013
|
133 remove_top_def (); |
|
134 |
|
135 if (! definition) |
|
136 definition = new symbol_def (); |
195
|
137 } |
1
|
138 } |
|
139 |
|
140 void |
3013
|
141 symbol_record::alias (symbol_record *s, bool /* force */) |
1
|
142 { |
3013
|
143 chg_fcn = s->chg_fcn; |
195
|
144 |
3013
|
145 replace_all_defs (s->definition); |
|
146 |
|
147 definition->count++; |
1
|
148 } |
|
149 |
|
150 void |
|
151 symbol_record::mark_as_formal_parameter (void) |
|
152 { |
3013
|
153 if (is_linked_to_global ()) |
|
154 error ("can't mark global variable `%s' as function parameter", |
|
155 nm.c_str ()); |
|
156 else if (is_static ()) |
|
157 error ("can't mark static variable `%s' as function paraemter", |
|
158 nm.c_str ()); |
|
159 else |
|
160 formal_param = 1; |
1
|
161 } |
|
162 |
|
163 void |
195
|
164 symbol_record::mark_as_linked_to_global (void) |
122
|
165 { |
2975
|
166 if (is_formal_parameter ()) |
|
167 error ("can't make function parameter `%s' global", nm.c_str ()); |
|
168 else if (is_static ()) |
|
169 error ("can't make static variable `%s' global", nm.c_str ()); |
|
170 else |
|
171 linked_to_global = 1; |
122
|
172 } |
|
173 |
2846
|
174 void |
|
175 symbol_record::mark_as_static (void) |
|
176 { |
|
177 if (is_linked_to_global ()) |
2975
|
178 error ("can't make global variable `%s' static", nm.c_str ()); |
2846
|
179 else if (is_formal_parameter ()) |
2975
|
180 error ("can't make formal parameter `%s' static", nm.c_str ()); |
2846
|
181 else |
|
182 tagged_static = 1; |
|
183 } |
|
184 |
2856
|
185 bool |
3013
|
186 symbol_record::hides_fcn (void) const |
2846
|
187 { |
3013
|
188 bool retval = false; |
|
189 |
|
190 if (is_variable () && is_defined ()) |
|
191 { |
|
192 symbol_def *hidden_def = definition->next_elem; |
|
193 |
|
194 if (hidden_def && hidden_def->is_builtin_function ()) |
|
195 retval = true; |
|
196 } |
|
197 |
|
198 return retval; |
|
199 } |
|
200 |
|
201 bool |
|
202 symbol_record::hides_builtin (void) const |
|
203 { |
|
204 bool retval = false; |
|
205 |
|
206 if (is_variable () && is_defined ()) |
|
207 { |
|
208 symbol_def *hidden_def = definition->next_elem; |
|
209 |
|
210 if (hidden_def && hidden_def->is_user_function ()) |
|
211 retval = true; |
|
212 } |
|
213 |
|
214 return retval; |
2846
|
215 } |
|
216 |
2975
|
217 octave_value& |
|
218 symbol_record::variable_value (void) |
2390
|
219 { |
2975
|
220 static octave_value foo; |
2390
|
221 |
2975
|
222 return is_variable () ? def () : foo; |
2390
|
223 } |
|
224 |
2979
|
225 octave_lvalue |
2390
|
226 symbol_record::variable_reference (void) |
|
227 { |
|
228 if (is_function ()) |
|
229 clear (); |
|
230 |
|
231 if (! is_defined ()) |
|
232 { |
|
233 if (! (is_formal_parameter () || is_linked_to_global ())) |
|
234 link_to_builtin_variable (this); |
|
235 |
|
236 if (! is_defined ()) |
2975
|
237 { |
|
238 octave_value tmp; |
|
239 define (tmp); |
|
240 } |
2390
|
241 } |
|
242 |
3013
|
243 return octave_lvalue (&(def ()), chg_fcn); |
195
|
244 } |
|
245 |
220
|
246 void |
|
247 symbol_record::push_context (void) |
|
248 { |
2846
|
249 if (! is_static ()) |
|
250 { |
|
251 context.push (definition); |
3013
|
252 |
|
253 definition = new symbol_def (); |
395
|
254 |
2893
|
255 global_link_context.push (static_cast<unsigned int> (linked_to_global)); |
3013
|
256 |
2846
|
257 linked_to_global = 0; |
|
258 } |
220
|
259 } |
|
260 |
|
261 void |
|
262 symbol_record::pop_context (void) |
|
263 { |
1653
|
264 // It is possible for context to be empty if new symbols have been |
|
265 // inserted in the symbol table during recursive calls. This can |
|
266 // happen as a result of calls to eval() and feval(). |
220
|
267 |
1653
|
268 if (! context.empty ()) |
220
|
269 { |
3013
|
270 replace_all_defs (context.pop ()); |
1653
|
271 |
|
272 linked_to_global = global_link_context.pop (); |
220
|
273 } |
|
274 } |
|
275 |
3013
|
276 void |
|
277 symbol_record::print_symbol_info_line (ostream& os) |
|
278 { |
|
279 os << (is_read_only () ? " r-" : " rw") |
|
280 << (is_eternal () ? "-" : "d") |
|
281 #if 0 |
|
282 << (hides_fcn () ? "f" : (hides_builtin () ? "F" : "-")) |
|
283 #endif |
|
284 << " " |
|
285 << setiosflags (ios::left) << setw (24) << type_name () . c_str (); |
|
286 |
|
287 os << resetiosflags (ios::left); |
|
288 |
|
289 int nr = rows (); |
|
290 int nc = columns (); |
|
291 |
|
292 if (nr < 0) |
|
293 os << " -"; |
|
294 else |
|
295 os << setiosflags (ios::right) << setw (7) << nr; |
|
296 |
|
297 if (nc < 0) |
|
298 os << " -"; |
|
299 else |
|
300 os << setiosflags (ios::right) << setw (7) << nc; |
|
301 |
|
302 os << resetiosflags (ios::right); |
|
303 |
|
304 os << " " << name () << "\n"; |
|
305 } |
|
306 |
|
307 bool |
2791
|
308 symbol_record::read_only_error (const char *action) |
195
|
309 { |
|
310 if (is_read_only ()) |
|
311 { |
|
312 if (is_variable ()) |
3013
|
313 ::error ("can't %s read-only constant `%s'", action, nm.c_str ()); |
195
|
314 else if (is_function ()) |
3013
|
315 ::error ("can't %s read-only function `%s'", action, nm.c_str ()); |
1045
|
316 else |
3013
|
317 ::error ("can't %s read-only symbol `%s'", action, nm.c_str ()); |
195
|
318 |
3013
|
319 return true; |
195
|
320 } |
|
321 else |
3013
|
322 return false; |
195
|
323 } |
|
324 |
|
325 void |
|
326 symbol_record::push_def (symbol_def *sd) |
|
327 { |
530
|
328 if (! sd) |
195
|
329 return; |
|
330 |
3013
|
331 assert (definition == 0 || definition->next_elem == 0); |
|
332 |
195
|
333 sd->next_elem = definition; |
3013
|
334 |
195
|
335 definition = sd; |
|
336 } |
|
337 |
3013
|
338 void |
|
339 symbol_record::remove_top_def (void) |
195
|
340 { |
|
341 symbol_def *top = definition; |
|
342 |
3013
|
343 definition = definition->next_elem; |
2404
|
344 |
3013
|
345 if (--top->count <= 0) |
|
346 delete top; |
195
|
347 } |
|
348 |
3013
|
349 void |
|
350 symbol_record::replace_all_defs (symbol_def *sd) |
195
|
351 { |
3013
|
352 while (definition) |
|
353 remove_top_def (); |
2404
|
354 |
3013
|
355 push_def (sd); |
195
|
356 } |
|
357 |
767
|
358 // A symbol table. |
1
|
359 |
|
360 symbol_record * |
2856
|
361 symbol_table::lookup (const string& nm, bool insert, bool warn) |
1
|
362 { |
3013
|
363 unsigned int index = hash (nm); |
1
|
364 |
|
365 symbol_record *ptr = table[index].next (); |
|
366 |
530
|
367 while (ptr) |
1
|
368 { |
1755
|
369 if (ptr->name () == nm) |
1
|
370 return ptr; |
3013
|
371 |
1
|
372 ptr = ptr->next (); |
|
373 } |
|
374 |
|
375 if (insert) |
|
376 { |
3013
|
377 symbol_record *sr = new symbol_record (nm, table[index].next ()); |
|
378 |
|
379 table[index].chain (sr); |
|
380 |
|
381 return sr; |
1
|
382 } |
|
383 else if (warn) |
1755
|
384 warning ("lookup: symbol`%s' not found", nm.c_str ()); |
1
|
385 |
530
|
386 return 0; |
1
|
387 } |
|
388 |
|
389 void |
1755
|
390 symbol_table::rename (const string& old_name, const string& new_name) |
572
|
391 { |
3013
|
392 unsigned int index = hash (old_name); |
572
|
393 |
|
394 symbol_record *prev = &table[index]; |
|
395 symbol_record *ptr = prev->next (); |
|
396 |
|
397 while (ptr) |
|
398 { |
1755
|
399 if (ptr->name () == old_name) |
572
|
400 { |
|
401 ptr->rename (new_name); |
|
402 |
2791
|
403 if (! error_state) |
|
404 { |
|
405 prev->chain (ptr->next ()); |
|
406 |
3013
|
407 index = hash (new_name); |
3125
|
408 ptr->chain (table[index].next ()); |
2791
|
409 table[index].chain (ptr); |
|
410 |
|
411 return; |
|
412 } |
|
413 |
|
414 break; |
572
|
415 } |
|
416 |
|
417 prev = ptr; |
|
418 ptr = ptr->next (); |
|
419 } |
|
420 |
1755
|
421 error ("unable to rename `%s' to `%s'", old_name.c_str (), |
|
422 new_name.c_str ()); |
572
|
423 } |
|
424 |
|
425 void |
2856
|
426 symbol_table::clear (bool clear_user_functions) |
1
|
427 { |
3013
|
428 for (unsigned int i = 0; i < table_size; i++) |
1
|
429 { |
169
|
430 symbol_record *ptr = table[i].next (); |
1
|
431 |
530
|
432 while (ptr) |
169
|
433 { |
195
|
434 if (ptr->is_user_variable () |
|
435 || (clear_user_functions && ptr->is_user_function ())) |
|
436 { |
|
437 ptr->clear (); |
|
438 } |
|
439 |
169
|
440 ptr = ptr->next (); |
1
|
441 } |
|
442 } |
|
443 } |
|
444 |
3013
|
445 bool |
2856
|
446 symbol_table::clear (const string& nm, bool clear_user_functions) |
1
|
447 { |
3013
|
448 unsigned int index = hash (nm); |
1
|
449 |
195
|
450 symbol_record *ptr = table[index].next (); |
1
|
451 |
530
|
452 while (ptr) |
1
|
453 { |
1755
|
454 if (ptr->name () == nm |
195
|
455 && (ptr->is_user_variable () |
|
456 || (clear_user_functions && ptr->is_user_function ()))) |
1
|
457 { |
195
|
458 ptr->clear (); |
3013
|
459 return true; |
1
|
460 } |
195
|
461 ptr = ptr->next (); |
1
|
462 } |
|
463 |
3013
|
464 return false; |
1
|
465 } |
|
466 |
|
467 int |
164
|
468 symbol_table::size (void) const |
1
|
469 { |
|
470 int count = 0; |
3013
|
471 |
|
472 for (unsigned int i = 0; i < table_size; i++) |
1
|
473 { |
|
474 symbol_record *ptr = table[i].next (); |
3013
|
475 |
530
|
476 while (ptr) |
1
|
477 { |
|
478 count++; |
|
479 ptr = ptr->next (); |
|
480 } |
|
481 } |
3013
|
482 |
1
|
483 return count; |
|
484 } |
|
485 |
3013
|
486 static bool |
|
487 matches_patterns (const string& name, const string_vector& pats) |
1
|
488 { |
3013
|
489 int npats = pats.length (); |
1
|
490 |
3013
|
491 if (npats == 0) |
|
492 return true; |
|
493 |
|
494 glob_match pattern (pats); |
|
495 |
|
496 return pattern.match (name); |
1
|
497 } |
|
498 |
3013
|
499 Array<symbol_record *> |
|
500 symbol_table::symbol_list (int& count, const string_vector& pats, |
|
501 unsigned int type, unsigned int scope) const |
1
|
502 { |
115
|
503 count = 0; |
3013
|
504 |
1
|
505 int n = size (); |
3013
|
506 |
1
|
507 if (n == 0) |
530
|
508 return 0; |
1
|
509 |
3013
|
510 Array<symbol_record *> symbols (n); |
|
511 |
|
512 for (unsigned int i = 0; i < table_size; i++) |
1
|
513 { |
|
514 symbol_record *ptr = table[i].next (); |
3013
|
515 |
530
|
516 while (ptr) |
1
|
517 { |
|
518 assert (count < n); |
867
|
519 |
2893
|
520 unsigned int my_scope = ptr->is_linked_to_global () + 1; // Tricky... |
867
|
521 |
2893
|
522 unsigned int my_type = ptr->type (); |
867
|
523 |
1755
|
524 string my_name = ptr->name (); |
867
|
525 |
|
526 if ((type & my_type) && (scope & my_scope) |
3013
|
527 && matches_patterns (my_name, pats)) |
|
528 symbols(count++) = ptr; |
605
|
529 |
1
|
530 ptr = ptr->next (); |
|
531 } |
|
532 } |
1755
|
533 |
|
534 symbols.resize (count); |
1
|
535 |
3013
|
536 return symbols; |
|
537 } |
|
538 |
|
539 string_vector |
|
540 symbol_table::name_list (int& count, const string_vector& pats, bool sort, |
|
541 unsigned int type, unsigned int scope) const |
|
542 { |
|
543 Array<symbol_record *> symbols |
|
544 = symbol_list (count, pats, type, scope); |
|
545 |
|
546 string_vector names; |
|
547 |
|
548 int n = symbols.length (); |
|
549 |
|
550 if (n > 0) |
|
551 { |
|
552 names.resize (n); |
|
553 |
|
554 for (int i = 0; i < n; i++) |
|
555 names[i] = symbols(i)->name (); |
|
556 } |
|
557 |
|
558 if (sort) |
|
559 names.qsort (); |
|
560 |
|
561 return names; |
|
562 } |
|
563 |
|
564 static int |
|
565 maybe_list_cmp_fcn (symbol_record **a_arg, symbol_record **b_arg) |
|
566 { |
|
567 string a = (*a_arg)->name (); |
|
568 string b = (*b_arg)->name (); |
|
569 |
|
570 return a.compare (b); |
|
571 } |
1
|
572 |
3013
|
573 int |
|
574 symbol_table::maybe_list (const char *header, const string_vector& argv, |
|
575 ostream& os, bool show_verbose, |
|
576 unsigned type, unsigned scope) |
|
577 { |
|
578 int count; |
|
579 |
|
580 int status = 0; |
|
581 |
|
582 if (show_verbose) |
|
583 { |
|
584 Array<symbol_record *> symbols = symbol_list (count, argv, type, scope); |
|
585 |
|
586 int len = symbols.length (); |
|
587 |
|
588 if (len > 0 && count > 0) |
|
589 { |
|
590 os << "\n" << header << "\n\n" |
|
591 << "prot type rows cols name\n" |
|
592 << "==== ==== ==== ==== ====\n"; |
|
593 |
|
594 symbols.qsort (maybe_list_cmp_fcn); |
|
595 |
|
596 for (int i = 0; i < len; i++) |
|
597 symbols(i)->print_symbol_info_line (os); |
|
598 |
|
599 status = 1; |
|
600 } |
|
601 } |
|
602 else |
|
603 { |
|
604 string_vector symbols = name_list (count, argv, 1, type, scope); |
|
605 |
|
606 if (symbols.length () > 0 && count > 0) |
|
607 { |
|
608 os << "\n" << header << "\n\n"; |
|
609 |
|
610 symbols.list_in_columns (os); |
|
611 |
|
612 status = 1; |
|
613 } |
|
614 } |
|
615 |
|
616 return status; |
1
|
617 } |
|
618 |
605
|
619 symbol_record ** |
2893
|
620 symbol_table::glob (int& count, const string& pat, unsigned int type, |
|
621 unsigned int scope) const |
605
|
622 { |
|
623 count = 0; |
|
624 int n = size (); |
|
625 if (n == 0) |
|
626 return 0; |
|
627 |
|
628 symbol_record **symbols = new symbol_record * [n+1]; |
3013
|
629 |
|
630 for (unsigned int i = 0; i < table_size; i++) |
605
|
631 { |
|
632 symbol_record *ptr = table[i].next (); |
3013
|
633 |
605
|
634 while (ptr) |
|
635 { |
|
636 assert (count < n); |
|
637 |
2893
|
638 unsigned int my_scope = ptr->is_linked_to_global () + 1; // Tricky... |
605
|
639 |
2893
|
640 unsigned int my_type = ptr->type (); |
605
|
641 |
1792
|
642 glob_match pattern (pat); |
1755
|
643 |
605
|
644 if ((type & my_type) && (scope & my_scope) |
1792
|
645 && pattern.match (ptr->name ())) |
605
|
646 { |
|
647 symbols[count++] = ptr; |
|
648 } |
|
649 |
|
650 ptr = ptr->next (); |
|
651 } |
|
652 } |
|
653 symbols[count] = 0; |
|
654 |
|
655 return symbols; |
|
656 } |
|
657 |
220
|
658 void |
|
659 symbol_table::push_context (void) |
|
660 { |
3013
|
661 for (unsigned int i = 0; i < table_size; i++) |
220
|
662 { |
|
663 symbol_record *ptr = table[i].next (); |
|
664 |
530
|
665 while (ptr) |
220
|
666 { |
|
667 ptr->push_context (); |
|
668 ptr = ptr->next (); |
|
669 } |
|
670 } |
|
671 } |
|
672 |
|
673 void |
|
674 symbol_table::pop_context (void) |
|
675 { |
3013
|
676 for (unsigned int i = 0; i < table_size; i++) |
220
|
677 { |
|
678 symbol_record *ptr = table[i].next (); |
|
679 |
530
|
680 while (ptr) |
220
|
681 { |
|
682 ptr->pop_context (); |
|
683 ptr = ptr->next (); |
|
684 } |
|
685 } |
|
686 } |
|
687 |
3013
|
688 void |
|
689 symbol_table::print_stats (void) |
|
690 { |
|
691 int count = 0; |
|
692 int empty_chains = 0; |
|
693 int max_chain_length = 0; |
|
694 int min_chain_length = INT_MAX; |
|
695 |
|
696 for (unsigned int i = 0; i < table_size; i++) |
|
697 { |
|
698 int num_this_chain = 0; |
|
699 |
|
700 symbol_record *ptr = table[i].next (); |
|
701 |
|
702 if (ptr) |
|
703 octave_stdout << "chain number " << i << ":\n"; |
|
704 else |
|
705 { |
|
706 empty_chains++; |
|
707 min_chain_length = 0; |
|
708 } |
|
709 |
|
710 while (ptr) |
|
711 { |
|
712 num_this_chain++; |
|
713 |
|
714 octave_stdout << " " << ptr->name () << "\n"; |
|
715 |
|
716 ptr = ptr->next (); |
|
717 } |
|
718 |
|
719 count += num_this_chain; |
|
720 |
|
721 if (num_this_chain > max_chain_length) |
|
722 max_chain_length = num_this_chain; |
|
723 |
|
724 if (num_this_chain < min_chain_length) |
|
725 min_chain_length = num_this_chain; |
|
726 |
|
727 if (num_this_chain > 0) |
|
728 octave_stdout << "\n"; |
|
729 } |
|
730 |
|
731 octave_stdout << "max chain length: " << max_chain_length << "\n"; |
|
732 octave_stdout << "min chain length: " << min_chain_length << "\n"; |
|
733 octave_stdout << "empty chains: " << empty_chains << "\n"; |
|
734 octave_stdout << "total chains: " << table_size << "\n"; |
|
735 octave_stdout << "total symbols: " << count << "\n"; |
|
736 } |
|
737 |
1
|
738 // Chris Torek's fave hash function. |
|
739 |
|
740 unsigned int |
1755
|
741 symbol_table::hash (const string& str) |
1
|
742 { |
2893
|
743 unsigned int h = 0; |
3013
|
744 |
2893
|
745 for (unsigned int i = 0; i < str.length (); i++) |
1755
|
746 h = h * 33 + str[i]; |
1
|
747 |
3013
|
748 return h & (table_size - 1); |
2790
|
749 } |
|
750 |
1
|
751 /* |
|
752 ;;; Local Variables: *** |
|
753 ;;; mode: C++ *** |
|
754 ;;; End: *** |
|
755 */ |