mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 23:18:52 +00:00
queuearray: make _find() find the value if no compare function is provided
Allow NULL as compare function for direct value lookup. https://bugzilla.gnome.org/show_bug.cgi?id=692691
This commit is contained in:
parent
8ea19a48ce
commit
ae8940e6f7
1 changed files with 22 additions and 7 deletions
|
@ -287,11 +287,17 @@ gst_queue_array_drop_element (GstQueueArray * array, guint idx)
|
||||||
/**
|
/**
|
||||||
* gst_queue_array_find:
|
* gst_queue_array_find:
|
||||||
* @array: a #GstQueueArray object
|
* @array: a #GstQueueArray object
|
||||||
* @func: comparison function
|
* @func: (allow-none): comparison function, or %NULL to find @data by value
|
||||||
* @data: data for comparison function
|
* @data: data for comparison function
|
||||||
*
|
*
|
||||||
* Finds an element in the queue @array by comparing every element
|
* Finds an element in the queue @array, either by comparing every element
|
||||||
* with @func and returning the index of the found element.
|
* with @func or by looking up @data if no compare function @func is provided,
|
||||||
|
* and returning the index of the found element.
|
||||||
|
*
|
||||||
|
* Note that the index is not 0-based, but an internal index number with a
|
||||||
|
* random offset. The index can be used in connection with
|
||||||
|
* gst_queue_array_drop_element(). FIXME: return index 0-based and make
|
||||||
|
* _drop_element() take a 0-based index.
|
||||||
*
|
*
|
||||||
* Returns: Index of the found element or -1 if nothing was found.
|
* Returns: Index of the found element or -1 if nothing was found.
|
||||||
*
|
*
|
||||||
|
@ -302,10 +308,19 @@ gst_queue_array_find (GstQueueArray * array, GCompareFunc func, gpointer data)
|
||||||
{
|
{
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
|
if (func != NULL) {
|
||||||
/* Scan from head to tail */
|
/* Scan from head to tail */
|
||||||
for (i = 0; i < array->length; i++)
|
for (i = 0; i < array->length; i++) {
|
||||||
if (func (array->array[(i + array->head) % array->size], data) == 0)
|
if (func (array->array[(i + array->head) % array->size], data) == 0)
|
||||||
return (i + array->head) % array->size;
|
return (i + array->head) % array->size;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < array->length; i++) {
|
||||||
|
if (array->array[(i + array->head) % array->size] == data)
|
||||||
|
return (i + array->head) % array->size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue