Index Map

An indexmap is basically a managed array of pointers, but it allows you to derive relatively quickly the index from a pointer in the array. More...

+ Collaboration diagram for Index Map:

Data Structures

struct  t_indexmap_entry
 An indexmap element. More...
struct  t_indexmap
 An indexmap object. More...

Functions

t_indexmapindexmap_new (void)
 Create a new indexmap object.
void indexmap_append (t_indexmap *x, void *data)
 Add an item to an indexmap.
t_max_err indexmap_move (t_indexmap *x, void *data, long newindex)
 Move an item to a different position in an indexmap.
t_max_err indexmap_delete (t_indexmap *x, void *data)
 Delete a specified item from an indexmap.
t_max_err indexmap_delete_index (t_indexmap *x, long index)
 Delete an item from the indexmap by index.
t_max_err indexmap_delete_multi (t_indexmap *x, long count, void **pdata)
 Delete multiple specified items from an indexmap.
t_max_err indexmap_delete_index_multi (t_indexmap *x, long count, long *indices)
 Delete multiple items from an indexmap by index.
void * indexmap_datafromindex (t_indexmap *x, long index)
 Get an item from an indexmap by index.
t_max_err indexmap_indexfromdata (t_indexmap *x, void *data, long *index)
 Find the index of an item given a pointer to the item.
long indexmap_getsize (t_indexmap *x)
 Return the number of items in an indexmap.
void indexmap_clear (t_indexmap *x)
 Delete all items in an indexmap.
void indexmap_sort (t_indexmap *x, t_cmpfn fn)
 Sort the items in an indexmap.

Detailed Description

An indexmap is basically a managed array of pointers, but it allows you to derive relatively quickly the index from a pointer in the array.

The index is assumed to be 0-N (where N is the current size of the array). You can sort the data and retain access to an index from the data relatively quickly. There is a hashtab which holds pieces of memory that hold indices that can be referenced by the data pointer. There is also an array of data pointers -- this is in "index" order. When operations take place on the array (insert, delete, sort), the pointers in the hashtab are updated with new indices.


Function Documentation

void indexmap_append ( t_indexmap x,
void *  data 
)

Add an item to an indexmap.

Parameters:
xThe indexmap instance.
dataThe item to add.
void indexmap_clear ( t_indexmap x)

Delete all items in an indexmap.

Parameters:
xThe indexmap instance.
void* indexmap_datafromindex ( t_indexmap x,
long  index 
)

Get an item from an indexmap by index.

Parameters:
xThe indexmap instance.
indexThe index from which to fetch a stored item.
Returns:
The item stored at the specified index.
t_max_err indexmap_delete ( t_indexmap x,
void *  data 
)

Delete a specified item from an indexmap.

Parameters:
xThe indexmap instance.
dataThe item pointer to remove from the indexmap.
Returns:
A Max error code.
t_max_err indexmap_delete_index ( t_indexmap x,
long  index 
)

Delete an item from the indexmap by index.

Parameters:
xThe indexmap instance.
indexThe index of the item to remove from the indexmap.
Returns:
A Max error code.
t_max_err indexmap_delete_index_multi ( t_indexmap x,
long  count,
long *  indices 
)

Delete multiple items from an indexmap by index.

Parameters:
xThe indexmap instance.
countThe number of items to remove from the indexmap.
indicesThe address of the first of an array of index numbers to remove the indexmap.
Returns:
A Max error code.
t_max_err indexmap_delete_multi ( t_indexmap x,
long  count,
void **  pdata 
)

Delete multiple specified items from an indexmap.

Parameters:
xThe indexmap instance.
countThe number of items to remove from the indexmap.
pdataThe address of the first of an array of item pointers to remove from the indexmap.
Returns:
A Max error code.
long indexmap_getsize ( t_indexmap x)

Return the number of items in an indexmap.

Parameters:
xThe indexmap instance.
Returns:
The number of items in the indexmap.
t_max_err indexmap_indexfromdata ( t_indexmap x,
void *  data,
long *  index 
)

Find the index of an item given a pointer to the item.

Parameters:
xThe indexmap instance.
dataThe item whose index you wish to look up.
indexThe address of a variable to hold the retrieved index.
Returns:
A Max error code.
t_max_err indexmap_move ( t_indexmap x,
void *  data,
long  newindex 
)

Move an item to a different position in an indexmap.

Parameters:
xThe indexmap instance.
dataThe item in the indexmap to move.
newindexThe new index to which to move the item.
Returns:
A Max error code.
t_indexmap* indexmap_new ( void  )

Create a new indexmap object.

Returns:
Pointer to the new indexmap object.
void indexmap_sort ( t_indexmap x,
t_cmpfn  fn 
)

Sort the items in an indexmap.

Item are sorted using a t_cmpfn function that is passed in as an argument.

Parameters:
xThe indexmap instance.
fnThe function used to sort the list.
See also:
linklist_sort()