iOS/Csound iOS Swift Examples/Csound iOS SwiftExamples/csound-iOS/headers/csound_data_structures.h
raw symbols SCIP| 1 | /* |
| 2 | csound_data_structures.h: |
| 3 | |
| 4 | Copyright (C) 2013 Steven Yi |
| 5 | |
| 6 | This file is part of Csound. |
| 7 | |
| 8 | The Csound Library is free software; you can redistribute it |
| 9 | and/or modify it under the terms of the GNU Lesser General Public |
| 10 | License as published by the Free Software Foundation; either |
| 11 | version 2.1 of the License, or (at your option) any later version. |
| 12 | |
| 13 | Csound is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU Lesser General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU Lesser General Public |
| 19 | License along with Csound; if not, write to the Free Software |
| 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 | 02110-1301 USA |
| 22 | */ |
| 23 | |
| 24 | #ifndef __CSOUND_DATA_STRUCTURES_H |
| 25 | #define __CSOUND_DATA_STRUCTURES_H |
| 26 | |
| 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | #define HASH_SIZE 4099 |
| 32 | |
| 33 | typedef struct _cons { |
| 34 | void* value; // should be car, but using value |
| 35 | struct _cons* next; // should be cdr, but to follow csound |
| 36 | // linked list conventions |
| 37 | } CONS_CELL; |
| 38 | |
| 39 | typedef struct _cs_hash_bucket_item { |
| 40 | char* key; |
| 41 | void* value; |
| 42 | struct _cs_hash_bucket_item* next; |
| 43 | } CS_HASH_TABLE_ITEM; |
| 44 | |
| 45 | typedef struct _cs_hash_table { |
| 46 | CS_HASH_TABLE_ITEM* buckets[HASH_SIZE]; |
| 47 | } CS_HASH_TABLE; |
| 48 | |
| 49 | /* FUNCTIONS FOR CONS CELL */ |
| 50 | |
| 51 | /** Given a value and CONS_CELL, create a new CONS_CELL that holds the |
| 52 | value, then set the ->next value to the passed-in cons cell. This |
| 53 | operation effectively appends a value to the head of cons list. The |
| 54 | function returns the head of the cons list. It is safe to pass in |
| 55 | a NULL for the cons argument; the returned value will be just the |
| 56 | newly generated cons cell. */ |
| 57 | PUBLIC CONS_CELL* cs_cons(CSOUND* csound, void* val, CONS_CELL* cons); |
| 58 | |
| 59 | /** Appends the cons2 CONS_CELL list to the tail of the cons1 */ |
| 60 | PUBLIC CONS_CELL* cs_cons_append(CONS_CELL* cons1, CONS_CELL* cons2); |
| 61 | |
| 62 | /** Returns length of CONS_CELL list */ |
| 63 | PUBLIC int cs_cons_length(CONS_CELL* head); |
| 64 | |
| 65 | /** Frees CONS_CELL list but does not free ->value pointers */ |
| 66 | PUBLIC void cs_cons_free(CSOUND* csound, CONS_CELL* head); |
| 67 | |
| 68 | /** Frees CONS_CELL list also frees ->value pointers */ |
| 69 | PUBLIC void cs_cons_free_complete(CSOUND* csound, CONS_CELL* head); |
| 70 | |
| 71 | /* FUNCTIONS FOR HASH SET */ |
| 72 | |
| 73 | /** Create CS_HASH_TABLE */ |
| 74 | PUBLIC CS_HASH_TABLE* cs_hash_table_create(CSOUND* csound); |
| 75 | |
| 76 | /** Retreive void* value for given char* key. Returns NULL if no |
| 77 | items founds for key. */ |
| 78 | PUBLIC void* cs_hash_table_get(CSOUND* csound, |
| 79 | CS_HASH_TABLE* hashTable, char* key); |
| 80 | |
| 81 | /** Retreive char* key from internal hash item for given char* key. |
| 82 | Useful when using CS_HASH_TABLE as a Set<String> type. Returns |
| 83 | NULL if there is no entry for given key. */ |
| 84 | PUBLIC char* cs_hash_table_get_key(CSOUND* csound, |
| 85 | CS_HASH_TABLE* hashTable, char* key); |
| 86 | |
| 87 | /** Adds an entry into the hashtable using the given key and value. |
| 88 | If an existing entry is found, overwrites the value for that key with |
| 89 | the new value passed in. */ |
| 90 | PUBLIC void cs_hash_table_put(CSOUND* csound, |
| 91 | CS_HASH_TABLE* hashTable, char* key, void* value); |
| 92 | |
| 93 | /** Adds an entry into the hashtable using the given key and NULL |
| 94 | value. Returns the internal char* used for the hash item key. */ |
| 95 | PUBLIC char* cs_hash_table_put_key(CSOUND* csound, |
| 96 | CS_HASH_TABLE* hashTable, char* key); |
| 97 | |
| 98 | /** Removes an entry from the hashtable using the given key. If no |
| 99 | entry found for key, simply returns. Calls mfree on the table |
| 100 | item. */ |
| 101 | PUBLIC void cs_hash_table_remove(CSOUND* csound, |
| 102 | CS_HASH_TABLE* hashTable, char* key); |
| 103 | |
| 104 | /** Merges in all items from the the source table into the target |
| 105 | table. Entries with identical keys from the source table will |
| 106 | replace entries in the target table. Note: wipes out source table. */ |
| 107 | PUBLIC void cs_hash_table_merge(CSOUND* csound, |
| 108 | CS_HASH_TABLE* target, CS_HASH_TABLE* source); |
| 109 | |
| 110 | /** Returns char* keys as a cons list */ |
| 111 | PUBLIC CONS_CELL* cs_hash_table_keys(CSOUND* csound, CS_HASH_TABLE* hashTable); |
| 112 | |
| 113 | /** Returns void* values as a cons list */ |
| 114 | PUBLIC CONS_CELL* cs_hash_table_values(CSOUND* csound, CS_HASH_TABLE* hashTable); |
| 115 | |
| 116 | /** Frees hash table and hash table items using mfree. Does not call |
| 117 | free on ->value pointer. */ |
| 118 | PUBLIC void cs_hash_table_free(CSOUND* csound, CS_HASH_TABLE* hashTable); |
| 119 | |
| 120 | /** Frees hash table and hash table keys using mfree. Does call mfree |
| 121 | on ->value pointer. */ |
| 122 | PUBLIC void cs_hash_table_mfree_complete(CSOUND* csound, CS_HASH_TABLE* hashTable); |
| 123 | |
| 124 | /** Frees hash table hash table keys using mfree. Does call free on |
| 125 | ->value pointer. */ |
| 126 | PUBLIC void cs_hash_table_free_complete(CSOUND* csound, CS_HASH_TABLE* hashTable); |
| 127 | |
| 128 | #ifdef __cplusplus |
| 129 | } |
| 130 | #endif |
| 131 | |
| 132 | #endif |