github.com/256dpi/max-go@v0.7.0/lib/max/indexmap.h (about)

     1  // indexmap.h copyright 2007 Cycling '74 all rights reserved
     2  
     3  #ifndef _INDEXMAP_H_
     4  #define _INDEXMAP_H_
     5  
     6  #include "ext_prefix.h"
     7  #include "ext_mess.h"
     8  #include "ext_hashtab.h"
     9  
    10  BEGIN_USING_C_LINKAGE
    11  
    12  #if !defined( _EXT_SYSTHREAD_H_ ) && !defined ( _SYSTHREAD_H_ )
    13  typedef void *t_systhread_mutex;
    14  #endif
    15  
    16  /** An indexmap element. This struct is provided for debugging convenience, 
    17  	but should be considered opaque and is subject to change without notice. 
    18  
    19  	@ingroup indexmap
    20  	@see t_indexmap
    21  */
    22  typedef struct _indexmap_entry
    23  {
    24  	long	e_index;
    25  	void	*e_data;
    26  	long	e_mark;
    27  } t_indexmap_entry;
    28  
    29  
    30  /** An indexmap object. This struct is provided for debugging convenience, 
    31  	but should be considered opaque and is subject to change without notice. 
    32  
    33  	@ingroup indexmap
    34  	@see t_indexmap_entry
    35  */
    36  typedef struct _indexmap
    37  {
    38  	t_object m_ob;
    39  	t_hashtab *m_data2index;			// convert from a data reference to an indexmap_entry (and hence index)
    40  	t_indexmap_entry **m_index2data;	// convert from an index to a data reference
    41  	long m_i2dsize;						// size of index2data array
    42  	long m_count;						// how many items
    43  	t_systhread_mutex m_mutex;			// protector
    44  } t_indexmap;
    45  
    46  
    47  // private -- initialize the indexmap class
    48  void indexmap_initclass(void);
    49  
    50  
    51  /** Create a new indexmap object.
    52  
    53  	@ingroup indexmap
    54  	@return Pointer to the new indexmap object.
    55  */
    56  t_indexmap *indexmap_new(void);
    57  
    58  
    59  /** Add an item to an indexmap.
    60  
    61  	@ingroup		indexmap
    62  	@param	x		The indexmap instance.
    63  	@param	data	The item to add.
    64  */
    65  void indexmap_append(t_indexmap *x, void *data);
    66  
    67  
    68  /** Move an item to a different position in an indexmap.
    69  
    70  	@ingroup			indexmap
    71  	@param	x			The indexmap instance.
    72  	@param	data		The item in the indexmap to move.
    73  	@param	newindex	The new index to which to move the item.
    74  	@return				A Max error code.
    75  */
    76  t_max_err indexmap_move(t_indexmap *x, void *data, long newindex);
    77  
    78  
    79  /** Delete a specified item from an indexmap.
    80  
    81  	@ingroup		indexmap
    82  	@param	x		The indexmap instance.
    83  	@param	data	The item pointer to remove from the indexmap.
    84  	@return			A Max error code.
    85  */
    86  t_max_err indexmap_delete(t_indexmap *x, void *data);
    87  
    88  
    89  /** Delete an item from the indexmap by index.
    90  
    91  	@ingroup 		indexmap
    92  	@param	x		The indexmap instance.
    93  	@param	index	The index of the item to remove from the indexmap.
    94  	@return			A Max error code.
    95  */
    96  t_max_err indexmap_delete_index(t_indexmap *x, long index);
    97  
    98  
    99  /** Delete multiple specified items from an indexmap.
   100  
   101  	@ingroup		indexmap
   102  	@param	x		The indexmap instance.
   103  	@param	count	The number of items to remove from the indexmap.
   104  	@param	pdata	The address of the first of an array of item pointers to remove from the indexmap.
   105  	@return			A Max error code.
   106  */
   107  t_max_err indexmap_delete_multi(t_indexmap *x, long count, void **pdata);
   108  
   109  
   110  /** Delete multiple items from an indexmap by index.
   111  
   112  	@ingroup		indexmap
   113  	@param	x		The indexmap instance.
   114  	@param	count	The number of items to remove from the indexmap.
   115  	@param	indices	The address of the first of an array of index numbers to remove the indexmap.
   116  	@return			A Max error code.
   117  */
   118  t_max_err indexmap_delete_index_multi(t_indexmap *x, long count, long *indices);
   119  
   120  
   121  /** Get an item from an indexmap by index.
   122  
   123  	@ingroup		indexmap
   124  	@param	x		The indexmap instance.
   125  	@param	index	The index from which to fetch a stored item.
   126  	@return			The item stored at the specified index.
   127  */
   128  void *indexmap_datafromindex(t_indexmap *x, long index);
   129  
   130  
   131  /** Find the index of an item given a pointer to the item.
   132  
   133  	@ingroup		indexmap
   134  	@param	x		The indexmap instance.
   135  	@param	data	The item whose index you wish to look up.
   136  	@param	index	The address of a variable to hold the retrieved index.
   137  	@return			A Max error code.
   138  */
   139  t_max_err indexmap_indexfromdata(t_indexmap *x, void *data, long *index);
   140  
   141  
   142  /** Return the number of items in an indexmap.
   143  
   144  	@ingroup	indexmap
   145  	@param	x	The indexmap instance.
   146  	@return		The number of items in the indexmap.
   147  */
   148  long indexmap_getsize(t_indexmap *x);
   149  
   150  
   151  /** Delete all items in an indexmap.
   152  
   153  	@ingroup	indexmap
   154  	@param	x	The indexmap instance.
   155  */
   156  void indexmap_clear(t_indexmap *x);
   157  
   158  
   159  /** Sort the items in an indexmap.
   160   	Item are sorted using a #t_cmpfn function that is passed in as an argument.
   161  
   162  	@ingroup indexmap
   163  	@param	x	The indexmap instance.
   164  	@param	fn	The function used to sort the list.
   165  	@see	linklist_sort()
   166  */
   167  void indexmap_sort(t_indexmap *x, t_cmpfn fn);
   168  
   169  void indexmap_insert(t_indexmap *x, long index, void *data);
   170  
   171  
   172  END_USING_C_LINKAGE
   173  
   174  #endif // _INDEXMAP_H_