| 1 | /*---------------------------------------------------------------------------- |
| 2 | ChucK Strongly-timed Audio Programming Language |
| 3 | Compiler, Virtual Machine, and Synthesis Engine |
| 4 | |
| 5 | Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved. |
| 6 | http://chuck.stanford.edu/ |
| 7 | http://chuck.cs.princeton.edu/ |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the dual-license terms of EITHER the MIT License OR the GNU |
| 11 | General Public License (the latter as published by the Free Software |
| 12 | Foundation; either version 2 of the License or, at your option, any |
| 13 | later version). |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful and/or |
| 16 | interesting, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 17 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | MIT Licence and/or the GNU General Public License for details. |
| 19 | |
| 20 | You should have received a copy of the MIT License and the GNU General |
| 21 | Public License (GPL) along with this program; a copy of the GPL can also |
| 22 | be obtained by writing to the Free Software Foundation, Inc., 59 Temple |
| 23 | Place, Suite 330, Boston, MA 02111-1307 U.S.A. |
| 24 | -----------------------------------------------------------------------------*/ |
| 25 | |
| 26 | //----------------------------------------------------------------------------- |
| 27 | // file: chuck_table.h |
| 28 | // desc: chuck table |
| 29 | // |
| 30 | // No algorithm should use these functions directly, because |
| 31 | // programming with void* is too error-prone. Instead, |
| 32 | // each module should make "wrapper" functions that take |
| 33 | // well-typed arguments and call the TAB_ functions. |
| 34 | // |
| 35 | // copyright (c) 1997 Andrew W. Appel. |
| 36 | // |
| 37 | // original author: Andrew Appel ([email protected]) |
| 38 | // modified: Ge Wang ([email protected]) |
| 39 | // date: Autumn 2002 |
| 40 | //----------------------------------------------------------------------------- |
| 41 | #ifndef __CHUCK_TABLE_H__ |
| 42 | #define __CHUCK_TABLE_H__ |
| 43 | |
| 44 | |
| 45 | typedef struct TAB_table_ * TAB_table; |
| 46 | typedef long (* TAB_eq_func)( void * lhs, void * rhs ); |
| 47 | typedef long (* TAB_hash_func)( void * key ); |
| 48 | |
| 49 | /* Make a new table mapping "keys" to "values". */ |
| 50 | TAB_table TAB_empty(void); |
| 51 | TAB_table TAB_empty2(unsigned long size); |
| 52 | TAB_table TAB_empty3( TAB_eq_func eq, TAB_hash_func hash, unsigned int size ); |
| 53 | void TAB_delete( TAB_table t ); |
| 54 | |
| 55 | /* Enter the mapping "key"->"value" into table "t", |
| 56 | * shadowing but not destroying any previous binding for "key". */ |
| 57 | void TAB_enter(TAB_table t, void *key, void *value); |
| 58 | |
| 59 | /* Look up the most recent binding for "key" in table "t" */ |
| 60 | void *TAB_look(TAB_table t, void *key); |
| 61 | |
| 62 | /* Pop the most recent binding and return its key. |
| 63 | * This may expose another binding for the same key, if there was one. */ |
| 64 | void *TAB_pop(TAB_table t); |
| 65 | void *TAB_topv(TAB_table t); |
| 66 | |
| 67 | |
| 68 | /* Call "show" on every "key"->"value" pair in the table, |
| 69 | * including shadowed bindings, in order from the most |
| 70 | * recent binding of any key to the oldest binding in the table */ |
| 71 | void TAB_dump(TAB_table t, void (*show)(void *key, void *value)); |
| 72 | |
| 73 | /* str eq function */ |
| 74 | long str_eq( void * lhs, void * rhs ); |
| 75 | long str_hash( void * key ); |
| 76 | |
| 77 | #endif |