Commit 31411811 authored by conrad's avatar conrad

added oggz_table_remove function


git-svn-id: http://svn.annodex.net/liboggz/trunk@440 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 5c3f0c8e
......@@ -70,6 +70,16 @@ oggz_table_delete (OggzTable * table);
void *
oggz_table_insert (OggzTable * table, long key, void * data);
/**
* Remove the element of an OggzTable indexed by a given key
* \param table An OggzTable
* \param key a key
* \retval 0 Success
* \retval -1 Not found
*/
int
oggz_table_remove (OggzTable * table, long key);
/**
* Retrieve the element of an OggzTable indexed by a given key
* \param table An OggzTable
......@@ -89,11 +99,11 @@ int
oggz_table_size (OggzTable * table);
/**
* Retrieve the nth element of an OggzTable
* Retrieve the nth element of an OggzTable, and optionally its key
* \param table An OggzTable
* \param n An index into the \a table
* \param key Return value for key corresponding to nth data element
* of \a table
* \param key Return pointer for key corresponding to nth data element
* of \a table. Ignored if NULL.
* \returns The nth data element of \a table
* \retval NULL \a table is undefined, or \a n is out of range
*/
......
......@@ -47,6 +47,7 @@
oggz_table_new;
oggz_table_delete;
oggz_table_insert;
oggz_table_remove;
oggz_table_lookup;
oggz_table_size;
oggz_table_nth;
......
......@@ -106,6 +106,26 @@ oggz_table_insert (OggzTable * table, long key, void * data)
return data;
}
int
oggz_table_remove (OggzTable * table, long key)
{
void * old_data;
if ((old_data = oggz_table_lookup (table, key)) != NULL) {
if (oggz_vector_remove_l (table->keys, key) == NULL)
return -1;
if (oggz_vector_remove_p (table->data, old_data) == NULL) {
/* XXX: This error condition can only happen if the previous
* removal succeeded, and this removal failed, ie. there was
* an error reallocing table->data->data downwards. */
return -1;
}
}
return 0;
}
int
oggz_table_size (OggzTable * table)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment