• Home
  • Raw
  • Download

Lines Matching full:queue

4  * GQueue: Double ended queue implementation, piggy backed on GList.
26 * SECTION:queue
28 * @Short_description: double-ended queue data structure
31 * queue data structure. Internally, GQueue uses the same data structure
40 * For a thread-safe queue, use #GAsyncQueue.
52 * To free the entire queue, use g_queue_free().
76 * @queue: a #GQueue
79 * if @queue was created with g_queue_new(). If queue elements contain
82 * If queue elements contain dynamically-allocated memory, you should
86 g_queue_free (GQueue *queue) in g_queue_free() argument
88 g_return_if_fail (queue != NULL); in g_queue_free()
90 g_list_free (queue->head); in g_queue_free()
91 g_slice_free (GQueue, queue); in g_queue_free()
96 * @queue: a pointer to a #GQueue
102 * @free_func should not modify the queue (eg, by removing the freed
108 g_queue_free_full (GQueue *queue, in g_queue_free_full() argument
111 g_queue_foreach (queue, (GFunc) free_func, NULL); in g_queue_free_full()
112 g_queue_free (queue); in g_queue_free_full()
117 * @queue: an uninitialized #GQueue
127 g_queue_init (GQueue *queue) in g_queue_init() argument
129 g_return_if_fail (queue != NULL); in g_queue_init()
131 queue->head = queue->tail = NULL; in g_queue_init()
132 queue->length = 0; in g_queue_init()
137 * @queue: a #GQueue
139 * Removes all the elements in @queue. If queue elements contain
145 g_queue_clear (GQueue *queue) in g_queue_clear() argument
147 g_return_if_fail (queue != NULL); in g_queue_clear()
149 g_list_free (queue->head); in g_queue_clear()
150 g_queue_init (queue); in g_queue_clear()
155 * @queue: a pointer to a #GQueue
164 g_queue_clear_full (GQueue *queue, in g_queue_clear_full() argument
167 g_return_if_fail (queue != NULL); in g_queue_clear_full()
170 g_queue_foreach (queue, (GFunc) free_func, NULL); in g_queue_clear_full()
172 g_queue_clear (queue); in g_queue_clear_full()
177 * @queue: a #GQueue.
179 * Returns %TRUE if the queue is empty.
181 * Returns: %TRUE if the queue is empty
184 g_queue_is_empty (GQueue *queue) in g_queue_is_empty() argument
186 g_return_val_if_fail (queue != NULL, TRUE); in g_queue_is_empty()
188 return queue->head == NULL; in g_queue_is_empty()
193 * @queue: a #GQueue
195 * Returns the number of items in @queue.
197 * Returns: the number of items in @queue
202 g_queue_get_length (GQueue *queue) in g_queue_get_length() argument
204 g_return_val_if_fail (queue != NULL, 0); in g_queue_get_length()
206 return queue->length; in g_queue_get_length()
211 * @queue: a #GQueue
213 * Reverses the order of the items in @queue.
218 g_queue_reverse (GQueue *queue) in g_queue_reverse() argument
220 g_return_if_fail (queue != NULL); in g_queue_reverse()
222 queue->tail = queue->head; in g_queue_reverse()
223 queue->head = g_list_reverse (queue->head); in g_queue_reverse()
228 * @queue: a #GQueue
230 * Copies a @queue. Note that is a shallow copy. If the elements in the
231 * queue consist of pointers to data, the pointers are copied, but the
234 * Returns: a copy of @queue
239 g_queue_copy (GQueue *queue) in g_queue_copy() argument
244 g_return_val_if_fail (queue != NULL, NULL); in g_queue_copy()
248 for (list = queue->head; list != NULL; list = list->next) in g_queue_copy()
256 * @queue: a #GQueue
260 * Calls @func for each element in the queue passing @user_data to the
263 * It is safe for @func to remove the element from @queue, but it must
264 * not modify any part of the queue after that element.
269 g_queue_foreach (GQueue *queue, in g_queue_foreach() argument
275 g_return_if_fail (queue != NULL); in g_queue_foreach()
278 list = queue->head; in g_queue_foreach()
289 * @queue: a #GQueue
292 * Finds the first link in @queue which contains @data.
294 * Returns: the first link in @queue which contains @data
299 g_queue_find (GQueue *queue, in g_queue_find() argument
302 g_return_val_if_fail (queue != NULL, NULL); in g_queue_find()
304 return g_list_find (queue->head, data); in g_queue_find()
309 * @queue: a #GQueue
315 * desired element. It iterates over the queue, calling the given function
325 g_queue_find_custom (GQueue *queue, in g_queue_find_custom() argument
329 g_return_val_if_fail (queue != NULL, NULL); in g_queue_find_custom()
332 return g_list_find_custom (queue->head, data, func); in g_queue_find_custom()
337 * @queue: a #GQueue
338 * @compare_func: the #GCompareDataFunc used to sort @queue. This function
339 * is passed two elements of the queue and should return 0 if they are
344 * Sorts @queue using @compare_func.
349 g_queue_sort (GQueue *queue, in g_queue_sort() argument
353 g_return_if_fail (queue != NULL); in g_queue_sort()
356 queue->head = g_list_sort_with_data (queue->head, compare_func, user_data); in g_queue_sort()
357 queue->tail = g_list_last (queue->head); in g_queue_sort()
362 * @queue: a #GQueue.
365 * Adds a new element at the head of the queue.
368 g_queue_push_head (GQueue *queue, in g_queue_push_head() argument
371 g_return_if_fail (queue != NULL); in g_queue_push_head()
373 queue->head = g_list_prepend (queue->head, data); in g_queue_push_head()
374 if (!queue->tail) in g_queue_push_head()
375 queue->tail = queue->head; in g_queue_push_head()
376 queue->length++; in g_queue_push_head()
381 * @queue: a #GQueue
384 * larger than the number of elements in the @queue, the element is
385 * added to the end of the queue.
387 * Inserts a new element into @queue at the given position.
392 g_queue_push_nth (GQueue *queue, in g_queue_push_nth() argument
396 g_return_if_fail (queue != NULL); in g_queue_push_nth()
398 if (n < 0 || (guint) n >= queue->length) in g_queue_push_nth()
400 g_queue_push_tail (queue, data); in g_queue_push_nth()
404 g_queue_insert_before (queue, g_queue_peek_nth_link (queue, n), data); in g_queue_push_nth()
409 * @queue: a #GQueue
412 * Adds a new element at the head of the queue.
415 g_queue_push_head_link (GQueue *queue, in g_queue_push_head_link() argument
418 g_return_if_fail (queue != NULL); in g_queue_push_head_link()
423 link->next = queue->head; in g_queue_push_head_link()
424 if (queue->head) in g_queue_push_head_link()
425 queue->head->prev = link; in g_queue_push_head_link()
427 queue->tail = link; in g_queue_push_head_link()
428 queue->head = link; in g_queue_push_head_link()
429 queue->length++; in g_queue_push_head_link()
434 * @queue: a #GQueue
437 * Adds a new element at the tail of the queue.
440 g_queue_push_tail (GQueue *queue, in g_queue_push_tail() argument
443 g_return_if_fail (queue != NULL); in g_queue_push_tail()
445 queue->tail = g_list_append (queue->tail, data); in g_queue_push_tail()
446 if (queue->tail->next) in g_queue_push_tail()
447 queue->tail = queue->tail->next; in g_queue_push_tail()
449 queue->head = queue->tail; in g_queue_push_tail()
450 queue->length++; in g_queue_push_tail()
455 * @queue: a #GQueue
458 * Adds a new element at the tail of the queue.
461 g_queue_push_tail_link (GQueue *queue, in g_queue_push_tail_link() argument
464 g_return_if_fail (queue != NULL); in g_queue_push_tail_link()
469 link->prev = queue->tail; in g_queue_push_tail_link()
470 if (queue->tail) in g_queue_push_tail_link()
471 queue->tail->next = link; in g_queue_push_tail_link()
473 queue->head = link; in g_queue_push_tail_link()
474 queue->tail = link; in g_queue_push_tail_link()
475 queue->length++; in g_queue_push_tail_link()
480 * @queue: a #GQueue
482 * the number of elements in @queue, the link is added to the end of
483 * @queue.
484 * @link_: the link to add to @queue
486 * Inserts @link into @queue at the given position.
491 g_queue_push_nth_link (GQueue *queue, in g_queue_push_nth_link() argument
498 g_return_if_fail (queue != NULL); in g_queue_push_nth_link()
501 if (n < 0 || (guint) n >= queue->length) in g_queue_push_nth_link()
503 g_queue_push_tail_link (queue, link_); in g_queue_push_nth_link()
507 g_assert (queue->head); in g_queue_push_nth_link()
508 g_assert (queue->tail); in g_queue_push_nth_link()
510 next = g_queue_peek_nth_link (queue, n); in g_queue_push_nth_link()
520 if (queue->head->prev) in g_queue_push_nth_link()
521 queue->head = queue->head->prev; in g_queue_push_nth_link()
523 /* The case where we’re pushing @link_ at the end of @queue is handled above in g_queue_push_nth_link()
525 * queue->tail. */ in g_queue_push_nth_link()
526 g_assert (queue->tail->next == NULL); in g_queue_push_nth_link()
528 queue->length++; in g_queue_push_nth_link()
533 * @queue: a #GQueue
535 * Removes the first element of the queue and returns its data.
537 * Returns: the data of the first element in the queue, or %NULL
538 * if the queue is empty
541 g_queue_pop_head (GQueue *queue) in g_queue_pop_head() argument
543 g_return_val_if_fail (queue != NULL, NULL); in g_queue_pop_head()
545 if (queue->head) in g_queue_pop_head()
547 GList *node = queue->head; in g_queue_pop_head()
550 queue->head = node->next; in g_queue_pop_head()
551 if (queue->head) in g_queue_pop_head()
552 queue->head->prev = NULL; in g_queue_pop_head()
554 queue->tail = NULL; in g_queue_pop_head()
556 queue->length--; in g_queue_pop_head()
566 * @queue: a #GQueue
568 * Removes and returns the first element of the queue.
570 * Returns: the #GList element at the head of the queue, or %NULL
571 * if the queue is empty
574 g_queue_pop_head_link (GQueue *queue) in g_queue_pop_head_link() argument
576 g_return_val_if_fail (queue != NULL, NULL); in g_queue_pop_head_link()
578 if (queue->head) in g_queue_pop_head_link()
580 GList *node = queue->head; in g_queue_pop_head_link()
582 queue->head = node->next; in g_queue_pop_head_link()
583 if (queue->head) in g_queue_pop_head_link()
585 queue->head->prev = NULL; in g_queue_pop_head_link()
589 queue->tail = NULL; in g_queue_pop_head_link()
590 queue->length--; in g_queue_pop_head_link()
600 * @queue: a #GQueue
602 * Returns the first link in @queue.
604 * Returns: the first link in @queue, or %NULL if @queue is empty
609 g_queue_peek_head_link (GQueue *queue) in g_queue_peek_head_link() argument
611 g_return_val_if_fail (queue != NULL, NULL); in g_queue_peek_head_link()
613 return queue->head; in g_queue_peek_head_link()
618 * @queue: a #GQueue
620 * Returns the last link in @queue.
622 * Returns: the last link in @queue, or %NULL if @queue is empty
627 g_queue_peek_tail_link (GQueue *queue) in g_queue_peek_tail_link() argument
629 g_return_val_if_fail (queue != NULL, NULL); in g_queue_peek_tail_link()
631 return queue->tail; in g_queue_peek_tail_link()
636 * @queue: a #GQueue
638 * Removes the last element of the queue and returns its data.
640 * Returns: the data of the last element in the queue, or %NULL
641 * if the queue is empty
644 g_queue_pop_tail (GQueue *queue) in g_queue_pop_tail() argument
646 g_return_val_if_fail (queue != NULL, NULL); in g_queue_pop_tail()
648 if (queue->tail) in g_queue_pop_tail()
650 GList *node = queue->tail; in g_queue_pop_tail()
653 queue->tail = node->prev; in g_queue_pop_tail()
654 if (queue->tail) in g_queue_pop_tail()
655 queue->tail->next = NULL; in g_queue_pop_tail()
657 queue->head = NULL; in g_queue_pop_tail()
658 queue->length--; in g_queue_pop_tail()
669 * @queue: a #GQueue
672 * Removes the @n'th element of @queue and returns its data.
674 * Returns: the element's data, or %NULL if @n is off the end of @queue
679 g_queue_pop_nth (GQueue *queue, in g_queue_pop_nth() argument
685 g_return_val_if_fail (queue != NULL, NULL); in g_queue_pop_nth()
687 if (n >= queue->length) in g_queue_pop_nth()
690 nth_link = g_queue_peek_nth_link (queue, n); in g_queue_pop_nth()
693 g_queue_delete_link (queue, nth_link); in g_queue_pop_nth()
700 * @queue: a #GQueue
702 * Removes and returns the last element of the queue.
704 * Returns: the #GList element at the tail of the queue, or %NULL
705 * if the queue is empty
708 g_queue_pop_tail_link (GQueue *queue) in g_queue_pop_tail_link() argument
710 g_return_val_if_fail (queue != NULL, NULL); in g_queue_pop_tail_link()
712 if (queue->tail) in g_queue_pop_tail_link()
714 GList *node = queue->tail; in g_queue_pop_tail_link()
716 queue->tail = node->prev; in g_queue_pop_tail_link()
717 if (queue->tail) in g_queue_pop_tail_link()
719 queue->tail->next = NULL; in g_queue_pop_tail_link()
723 queue->head = NULL; in g_queue_pop_tail_link()
724 queue->length--; in g_queue_pop_tail_link()
734 * @queue: a #GQueue
739 * Returns: the @n'th link, or %NULL if @n is off the end of @queue
744 g_queue_pop_nth_link (GQueue *queue, in g_queue_pop_nth_link() argument
749 g_return_val_if_fail (queue != NULL, NULL); in g_queue_pop_nth_link()
751 if (n >= queue->length) in g_queue_pop_nth_link()
754 link = g_queue_peek_nth_link (queue, n); in g_queue_pop_nth_link()
755 g_queue_unlink (queue, link); in g_queue_pop_nth_link()
762 * @queue: a #GQueue
773 g_queue_peek_nth_link (GQueue *queue, in g_queue_peek_nth_link() argument
779 g_return_val_if_fail (queue != NULL, NULL); in g_queue_peek_nth_link()
781 if (n >= queue->length) in g_queue_peek_nth_link()
784 if (n > queue->length / 2) in g_queue_peek_nth_link()
786 n = queue->length - n - 1; in g_queue_peek_nth_link()
788 link = queue->tail; in g_queue_peek_nth_link()
794 link = queue->head; in g_queue_peek_nth_link()
804 * @queue: a #GQueue
807 * Returns the position of @link_ in @queue.
810 * not part of @queue
815 g_queue_link_index (GQueue *queue, in g_queue_link_index() argument
818 g_return_val_if_fail (queue != NULL, -1); in g_queue_link_index()
820 return g_list_position (queue->head, link_); in g_queue_link_index()
825 * @queue: a #GQueue
826 * @link_: a #GList link that must be part of @queue
828 * Unlinks @link_ so that it will no longer be part of @queue.
831 * @link_ must be part of @queue.
836 g_queue_unlink (GQueue *queue, in g_queue_unlink() argument
839 g_return_if_fail (queue != NULL); in g_queue_unlink()
842 if (link_ == queue->tail) in g_queue_unlink()
843 queue->tail = queue->tail->prev; in g_queue_unlink()
845 queue->head = g_list_remove_link (queue->head, link_); in g_queue_unlink()
846 queue->length--; in g_queue_unlink()
851 * @queue: a #GQueue
852 * @link_: a #GList link that must be part of @queue
854 * Removes @link_ from @queue and frees it.
856 * @link_ must be part of @queue.
861 g_queue_delete_link (GQueue *queue, in g_queue_delete_link() argument
864 g_return_if_fail (queue != NULL); in g_queue_delete_link()
867 g_queue_unlink (queue, link_); in g_queue_delete_link()
873 * @queue: a #GQueue
875 * Returns the first element of the queue.
877 * Returns: the data of the first element in the queue, or %NULL
878 * if the queue is empty
881 g_queue_peek_head (GQueue *queue) in g_queue_peek_head() argument
883 g_return_val_if_fail (queue != NULL, NULL); in g_queue_peek_head()
885 return queue->head ? queue->head->data : NULL; in g_queue_peek_head()
890 * @queue: a #GQueue
892 * Returns the last element of the queue.
894 * Returns: the data of the last element in the queue, or %NULL
895 * if the queue is empty
898 g_queue_peek_tail (GQueue *queue) in g_queue_peek_tail() argument
900 g_return_val_if_fail (queue != NULL, NULL); in g_queue_peek_tail()
902 return queue->tail ? queue->tail->data : NULL; in g_queue_peek_tail()
907 * @queue: a #GQueue
910 * Returns the @n'th element of @queue.
912 * Returns: the data for the @n'th element of @queue,
913 * or %NULL if @n is off the end of @queue
918 g_queue_peek_nth (GQueue *queue, in g_queue_peek_nth() argument
923 g_return_val_if_fail (queue != NULL, NULL); in g_queue_peek_nth()
925 link = g_queue_peek_nth_link (queue, n); in g_queue_peek_nth()
935 * @queue: a #GQueue
938 * Returns the position of the first element in @queue which contains @data.
940 * Returns: the position of the first element in @queue which
941 * contains @data, or -1 if no element in @queue contains @data
946 g_queue_index (GQueue *queue, in g_queue_index() argument
949 g_return_val_if_fail (queue != NULL, -1); in g_queue_index()
951 return g_list_index (queue->head, data); in g_queue_index()
956 * @queue: a #GQueue
959 * Removes the first element in @queue that contains @data.
961 * Returns: %TRUE if @data was found and removed from @queue
966 g_queue_remove (GQueue *queue, in g_queue_remove() argument
971 g_return_val_if_fail (queue != NULL, FALSE); in g_queue_remove()
973 link = g_list_find (queue->head, data); in g_queue_remove()
976 g_queue_delete_link (queue, link); in g_queue_remove()
983 * @queue: a #GQueue
986 * Remove all elements whose data equals @data from @queue.
988 * Returns: the number of elements removed from @queue
993 g_queue_remove_all (GQueue *queue, in g_queue_remove_all() argument
999 g_return_val_if_fail (queue != NULL, 0); in g_queue_remove_all()
1001 old_length = queue->length; in g_queue_remove_all()
1003 list = queue->head; in g_queue_remove_all()
1009 g_queue_delete_link (queue, list); in g_queue_remove_all()
1014 return (old_length - queue->length); in g_queue_remove_all()
1019 * @queue: a #GQueue
1020 * @sibling: (nullable): a #GList link that must be part of @queue, or %NULL to
1021 * push at the tail of the queue.
1024 * Inserts @data into @queue before @sibling.
1026 * @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the
1027 * data at the tail of the queue.
1032 g_queue_insert_before (GQueue *queue, in g_queue_insert_before() argument
1036 g_return_if_fail (queue != NULL); in g_queue_insert_before()
1044 g_queue_push_tail (queue, data); in g_queue_insert_before()
1048 queue->head = g_list_insert_before (queue->head, sibling, data); in g_queue_insert_before()
1049 queue->length++; in g_queue_insert_before()
1055 * @queue: a #GQueue
1056 * @sibling: (nullable): a #GList link that must be part of @queue, or %NULL to
1057 * push at the tail of the queue.
1060 * Inserts @link_ into @queue before @sibling.
1062 * @sibling must be part of @queue.
1067 g_queue_insert_before_link (GQueue *queue, in g_queue_insert_before_link() argument
1071 g_return_if_fail (queue != NULL); in g_queue_insert_before_link()
1082 g_queue_push_tail_link (queue, link_); in g_queue_insert_before_link()
1086 queue->head = g_list_insert_before_link (queue->head, sibling, link_); in g_queue_insert_before_link()
1087 queue->length++; in g_queue_insert_before_link()
1093 * @queue: a #GQueue
1094 * @sibling: (nullable): a #GList link that must be part of @queue, or %NULL to
1095 * push at the head of the queue.
1098 * Inserts @data into @queue after @sibling.
1100 * @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the
1101 * data at the head of the queue.
1106 g_queue_insert_after (GQueue *queue, in g_queue_insert_after() argument
1110 g_return_if_fail (queue != NULL); in g_queue_insert_after()
1113 g_queue_push_head (queue, data); in g_queue_insert_after()
1115 g_queue_insert_before (queue, sibling->next, data); in g_queue_insert_after()
1120 * @queue: a #GQueue
1121 * @sibling: (nullable): a #GList link that must be part of @queue, or %NULL to
1122 * push at the head of the queue.
1125 * Inserts @link_ into @queue after @sibling.
1127 * @sibling must be part of @queue.
1132 g_queue_insert_after_link (GQueue *queue, in g_queue_insert_after_link() argument
1136 g_return_if_fail (queue != NULL); in g_queue_insert_after_link()
1142 g_queue_push_head_link (queue, link_); in g_queue_insert_after_link()
1144 g_queue_insert_before_link (queue, sibling->next, link_); in g_queue_insert_after_link()
1149 * @queue: a #GQueue
1151 * @func: the #GCompareDataFunc used to compare elements in the queue. It is
1152 * called with two elements of the @queue and @user_data. It should
1158 * Inserts @data into @queue using @func to determine the new position.
1163 g_queue_insert_sorted (GQueue *queue, in g_queue_insert_sorted() argument
1170 g_return_if_fail (queue != NULL); in g_queue_insert_sorted()
1172 list = queue->head; in g_queue_insert_sorted()
1176 g_queue_insert_before (queue, list, data); in g_queue_insert_sorted()