Max 5 API Reference
00001 // indexmap.h copyright 2007 Cycling '74 all rights reserved 00002 00003 #ifndef _INDEXMAP_H_ 00004 #define _INDEXMAP_H_ 00005 00006 BEGIN_USING_C_LINKAGE 00007 00008 #ifndef _EXT_SYSTHREAD_H_ 00009 typedef void *t_systhread_mutex; 00010 #endif 00011 00012 /** An indexmap element. This struct is provided for debugging convenience, 00013 but should be considered opaque and is subject to change without notice. 00014 00015 @ingroup indexmap 00016 @see t_indexmap 00017 */ 00018 typedef struct _indexmap_entry 00019 { 00020 long e_index; 00021 void *e_data; 00022 long e_mark; 00023 } t_indexmap_entry; 00024 00025 00026 /** An indexmap object. This struct is provided for debugging convenience, 00027 but should be considered opaque and is subject to change without notice. 00028 00029 @ingroup indexmap 00030 @see t_indexmap_entry 00031 */ 00032 typedef struct _indexmap 00033 { 00034 t_object m_ob; 00035 t_hashtab *m_data2index; // convert from a data reference to an indexmap_entry (and hence index) 00036 t_indexmap_entry **m_index2data; // convert from an index to a data reference 00037 long m_i2dsize; // size of index2data array 00038 long m_count; // how many items 00039 t_systhread_mutex m_mutex; // protector 00040 } t_indexmap; 00041 00042 00043 // private -- initialize the indexmap class 00044 void indexmap_initclass(); 00045 00046 00047 /** Create a new indexmap object. 00048 00049 @ingroup indexmap 00050 @return Pointer to the new indexmap object. 00051 */ 00052 t_indexmap *indexmap_new(void); 00053 00054 00055 /** Add an item to an indexmap. 00056 00057 @ingroup indexmap 00058 @param x The indexmap instance. 00059 @param data The item to add. 00060 */ 00061 void indexmap_append(t_indexmap *x, void *data); 00062 00063 00064 /** Move an item to a different position in an indexmap. 00065 00066 @ingroup indexmap 00067 @param x The indexmap instance. 00068 @param data The item in the indexmap to move. 00069 @param newindex The new index to which to move the item. 00070 @return A Max error code. 00071 */ 00072 t_max_err indexmap_move(t_indexmap *x, void *data, long newindex); 00073 00074 00075 /** Delete a specified item from an indexmap. 00076 00077 @ingroup indexmap 00078 @param x The indexmap instance. 00079 @param data The item pointer to remove from the indexmap. 00080 @return A Max error code. 00081 */ 00082 t_max_err indexmap_delete(t_indexmap *x, void *data); 00083 00084 00085 /** Delete an item from the indexmap by index. 00086 00087 @ingroup indexmap 00088 @param x The indexmap instance. 00089 @param index The index of the item to remove from the indexmap. 00090 @return A Max error code. 00091 */ 00092 t_max_err indexmap_delete_index(t_indexmap *x, long index); 00093 00094 00095 /** Delete multiple specified items from an indexmap. 00096 00097 @ingroup indexmap 00098 @param x The indexmap instance. 00099 @param count The number of items to remove from the indexmap. 00100 @param pdata The address of the first of an array of item pointers to remove from the indexmap. 00101 @return A Max error code. 00102 */ 00103 t_max_err indexmap_delete_multi(t_indexmap *x, long count, void **pdata); 00104 00105 00106 /** Delete multiple items from an indexmap by index. 00107 00108 @ingroup indexmap 00109 @param x The indexmap instance. 00110 @param count The number of items to remove from the indexmap. 00111 @param indices The address of the first of an array of index numbers to remove the indexmap. 00112 @return A Max error code. 00113 */ 00114 t_max_err indexmap_delete_index_multi(t_indexmap *x, long count, long *indices); 00115 00116 00117 /** Get an item from an indexmap by index. 00118 00119 @ingroup indexmap 00120 @param x The indexmap instance. 00121 @param index The index from which to fetch a stored item. 00122 @return The item stored at the specified index. 00123 */ 00124 void *indexmap_datafromindex(t_indexmap *x, long index); 00125 00126 00127 /** Find the index of an item given a pointer to the item. 00128 00129 @ingroup indexmap 00130 @param x The indexmap instance. 00131 @param data The item whose index you wish to look up. 00132 @param index The address of a variable to hold the retrieved index. 00133 @return A Max error code. 00134 */ 00135 t_max_err indexmap_indexfromdata(t_indexmap *x, void *data, long *index); 00136 00137 00138 /** Return the number of items in an indexmap. 00139 00140 @ingroup indexmap 00141 @param x The indexmap instance. 00142 @return The number of items in the indexmap. 00143 */ 00144 long indexmap_getsize(t_indexmap *x); 00145 00146 00147 /** Delete all items in an indexmap. 00148 00149 @ingroup indexmap 00150 @param x The indexmap instance. 00151 */ 00152 void indexmap_clear(t_indexmap *x); 00153 00154 00155 /** Sort the items in an indexmap. 00156 Item are sorted using a #t_cmpfn function that is passed in as an argument. 00157 00158 @ingroup indexmap 00159 @param x The indexmap instance. 00160 @param fn The function used to sort the list. 00161 @see linklist_sort() 00162 */ 00163 void indexmap_sort(t_indexmap *x, t_cmpfn fn); 00164 00165 00166 END_USING_C_LINKAGE 00167 00168 #endif // _INDEXMAP_H_
Copyright © 2008, Cycling '74