/* GLIB - Library of useful routines for C programming * Copyright (C) 2001 Joshua Nathaniel Pritikin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include #ifndef __G_RING_H__ #define __G_RING_H__ // G_BEGIN_DECLS typedef struct _GRing GRing; struct _GRing { gpointer data; GRing *next; GRing *prev; }; /* GList look-alike */ #define g_ring_alloc() ((GRing *) g_list_alloc()) void g_ring_free (GRing *ring); void g_ring_free_1 (GRing *ring); GRing * g_ring_append (GRing * head, gpointer data); GRing * g_ring_prepend (GRing * head, gpointer data); GRing * g_ring_insert (GRing * head, gpointer data, gint position); GRing * g_ring_insert_sorted (GRing * head, gpointer data, GCompareDataFunc func, gpointer user_data); GRing * g_ring_concat (GRing *head1, GRing *head2); GRing * g_ring_remove (GRing * head, gconstpointer data); GRing * g_ring_remove_all (GRing * head, gconstpointer data); GRing * g_ring_remove_link (GRing *head, GRing *ring); GRing * g_ring_delete_link (GRing *head, GRing *ring); GRing * g_ring_reverse (GRing *head); GRing * g_ring_copy (GRing *head); GRing * g_ring_nth (GRing *ring, guint n); GRing * g_ring_nth_prev (GRing *head, guint n); GRing * g_ring_find (GRing * head, gconstpointer data); GRing * g_ring_find_nearby (GRing * head, gconstpointer data); GRing * g_ring_find_custom (GRing * head, GCompareFunc func, gpointer user_data); GRing * g_ring_find_nearby_custom (GRing * head, GCompareFunc func, gpointer user_data); gint g_ring_position (GRing *head, GRing *ring); gint g_ring_index (GRing * head, gconstpointer data); #define g_ring_first(head) (head) #define g_ring_last(head) ((head)->prev) guint g_ring_length (GRing *head); void g_ring_foreach (GRing ** head, GFunc func, gpointer user_data); GRing * g_ring_sort (GRing * head, GCompareFunc compare_func); GRing * g_ring_sort_with_data (GRing * head, GCompareDataFunc compare_func, gpointer user_data); gpointer g_ring_nth_data (GRing * ring, guint n); /* GQueue look-alike */ gpointer g_ring_pop_head (GRing **head); gpointer g_ring_pop_tail (GRing **head); /* works for GList too :-) */ #define g_ring_prev(head, ring) ((ring)->prev != (head)? (ring)->prev : NULL) #define g_ring_next(head, ring) ((ring)->next != (head)? (ring)->next : NULL) // G_END_DECLS #endif /* __G_RING_H__ */