libalpm
Arch Linux Package Manager Library
alpm_list.h
Go to the documentation of this file.
00001 /*
00002  *  alpm_list.h
00003  *
00004  *  Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
00005  *  Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 #ifndef _ALPM_LIST_H
00021 #define _ALPM_LIST_H
00022 
00023 #include <stdlib.h> /* size_t */
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 /**
00030  * @brief Linked list type used by libalpm.
00031  *
00032  * It is exposed so front ends can use it to prevent the need to reimplement
00033  * lists of their own; however, it is not required that the front end uses
00034  * it.
00035  */
00036 typedef struct __alpm_list_t {
00037     /** data held by the list node */
00038     void *data;
00039     /** pointer to the previous node */
00040     struct __alpm_list_t *prev;
00041     /** pointer to the next node */
00042     struct __alpm_list_t *next;
00043 } alpm_list_t;
00044 
00045 #define FREELIST(p) do { alpm_list_free_inner(p, free); alpm_list_free(p); p = NULL; } while(0)
00046 
00047 typedef void (*alpm_list_fn_free)(void *); /* item deallocation callback */
00048 typedef int (*alpm_list_fn_cmp)(const void *, const void *); /* item comparison callback */
00049 
00050 /* allocation */
00051 void alpm_list_free(alpm_list_t *list);
00052 void alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn);
00053 
00054 /* item mutators */
00055 alpm_list_t *alpm_list_add(alpm_list_t *list, void *data);
00056 alpm_list_t *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cmp fn);
00057 alpm_list_t *alpm_list_join(alpm_list_t *first, alpm_list_t *second);
00058 alpm_list_t *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn);
00059 alpm_list_t *alpm_list_msort(alpm_list_t *list, size_t n, alpm_list_fn_cmp fn);
00060 alpm_list_t *alpm_list_remove_item(alpm_list_t *haystack, alpm_list_t *item);
00061 alpm_list_t *alpm_list_remove(alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data);
00062 alpm_list_t *alpm_list_remove_str(alpm_list_t *haystack, const char *needle, char **data);
00063 alpm_list_t *alpm_list_remove_dupes(const alpm_list_t *list);
00064 alpm_list_t *alpm_list_strdup(const alpm_list_t *list);
00065 alpm_list_t *alpm_list_copy(const alpm_list_t *list);
00066 alpm_list_t *alpm_list_copy_data(const alpm_list_t *list, size_t size);
00067 alpm_list_t *alpm_list_reverse(alpm_list_t *list);
00068 
00069 /* item accessors */
00070 alpm_list_t *alpm_list_nth(const alpm_list_t *list, size_t n);
00071 alpm_list_t *alpm_list_next(const alpm_list_t *list);
00072 alpm_list_t *alpm_list_previous(const alpm_list_t *list);
00073 alpm_list_t *alpm_list_last(const alpm_list_t *list);
00074 
00075 /* misc */
00076 size_t alpm_list_count(const alpm_list_t *list);
00077 void *alpm_list_find(const alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn);
00078 void *alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle);
00079 char *alpm_list_find_str(const alpm_list_t *haystack, const char *needle);
00080 alpm_list_t *alpm_list_diff(const alpm_list_t *lhs, const alpm_list_t *rhs, alpm_list_fn_cmp fn);
00081 void alpm_list_diff_sorted(const alpm_list_t *left, const alpm_list_t *right,
00082         alpm_list_fn_cmp fn, alpm_list_t **onlyleft, alpm_list_t **onlyright);
00083 void *alpm_list_to_array(const alpm_list_t *list, size_t n, size_t size);
00084 
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088 #endif /* _ALPM_LIST_H */
00089 
00090 /* vim: set ts=2 sw=2 noet: */