2007-01-19 04:28:44 -05:00
|
|
|
/*
|
2007-03-29 00:40:49 -04:00
|
|
|
* alpm_list.h
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2011-01-05 23:45:15 -05:00
|
|
|
* Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2007-01-19 04:28:44 -05:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-01-19 04:28:44 -05:00
|
|
|
*/
|
|
|
|
#ifndef _ALPM_LIST_H
|
|
|
|
#define _ALPM_LIST_H
|
|
|
|
|
2008-02-15 21:57:30 -05:00
|
|
|
#include <stdlib.h> /* size_t */
|
|
|
|
|
2007-03-29 00:40:49 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Linked list type used by libalpm.
|
|
|
|
*
|
|
|
|
* It is exposed so front ends can use it to prevent the need to reimplement
|
|
|
|
* lists of their own; however, it is not required that the front end uses
|
|
|
|
* it.
|
|
|
|
*/
|
2007-10-14 18:29:32 -04:00
|
|
|
typedef struct __alpm_list_t {
|
2007-03-29 00:40:49 -04:00
|
|
|
/** data held by the list node */
|
2007-01-19 04:28:44 -05:00
|
|
|
void *data;
|
2007-03-29 00:40:49 -04:00
|
|
|
/** pointer to the previous node */
|
2007-01-19 04:28:44 -05:00
|
|
|
struct __alpm_list_t *prev;
|
2007-03-29 00:40:49 -04:00
|
|
|
/** pointer to the next node */
|
2007-01-19 04:28:44 -05:00
|
|
|
struct __alpm_list_t *next;
|
2007-10-14 18:29:32 -04:00
|
|
|
} alpm_list_t;
|
2007-01-19 04:28:44 -05:00
|
|
|
|
2007-04-28 03:54:25 -04:00
|
|
|
#define FREELIST(p) do { alpm_list_free_inner(p, free); alpm_list_free(p); p = NULL; } while(0)
|
2007-01-19 04:28:44 -05:00
|
|
|
|
|
|
|
typedef void (*alpm_list_fn_free)(void *); /* item deallocation callback */
|
|
|
|
typedef int (*alpm_list_fn_cmp)(const void *, const void *); /* item comparison callback */
|
|
|
|
|
|
|
|
/* allocation */
|
2007-01-24 03:51:50 -05:00
|
|
|
void alpm_list_free(alpm_list_t *list);
|
|
|
|
void alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn);
|
2007-01-19 04:28:44 -05:00
|
|
|
|
|
|
|
/* item mutators */
|
|
|
|
alpm_list_t *alpm_list_add(alpm_list_t *list, void *data);
|
|
|
|
alpm_list_t *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cmp fn);
|
2007-11-20 03:11:40 -05:00
|
|
|
alpm_list_t *alpm_list_join(alpm_list_t *first, alpm_list_t *second);
|
2007-02-13 03:15:38 -05:00
|
|
|
alpm_list_t *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn);
|
2010-12-08 00:13:36 -05:00
|
|
|
alpm_list_t *alpm_list_msort(alpm_list_t *list, size_t n, alpm_list_fn_cmp fn);
|
2011-02-02 21:46:28 -05:00
|
|
|
alpm_list_t *alpm_list_remove_item(alpm_list_t *haystack, alpm_list_t *item);
|
2007-03-03 03:13:59 -05:00
|
|
|
alpm_list_t *alpm_list_remove(alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data);
|
Cleanup usages of alpm_list_find and alpm_list_remove.
* remove obsolete and unused *_cmp helper functions like deppkg_cmp and
_alpm_grp_cmp
* new alpm_list_remove_str function, used 6 times in handle.c
* remove _alpm_prov_cmp / _alpm_db_whatprovides and replace them by
a more general alpm_find_pkg_satisfiers with a cleaner implementation.
before: alpm_db_whatprovides(db, targ)
after: alpm_find_pkg_satisfiers(alpm_db_getpkgcache(db), targ)
* remove satisfycmp and replace alpm_list_find + satisfycmp usage by
_alpm_find_dep_satisfiers.
before : alpm_list_find(_alpm_db_get_pkgcache(db), dep, satisfycmp)
after : _alpm_find_dep_satisfiers(_alpm_db_get_pkgcache(db), dep)
* remove _alpm_pkgname_pkg_cmp, which was used with alpm_list_remove, and
use _alpm_pkg_find + alpm_list_remove with _alpm_pkg_cmp instead.
This commit actually get rids of all complicated and asymmetric _cmp
functions. I first thought these functions were worth it, be caused it
allowed us to reuse list_find and list_remove. But this was at the detriment
of the clarity and also the ease of use of these functions, dangerous
because of their asymmetricity.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-05-10 12:47:42 -04:00
|
|
|
alpm_list_t *alpm_list_remove_str(alpm_list_t *haystack, const char *needle, char **data);
|
2007-06-05 17:34:33 -04:00
|
|
|
alpm_list_t *alpm_list_remove_dupes(const alpm_list_t *list);
|
|
|
|
alpm_list_t *alpm_list_strdup(const alpm_list_t *list);
|
2007-10-19 13:17:51 -04:00
|
|
|
alpm_list_t *alpm_list_copy(const alpm_list_t *list);
|
2007-11-14 23:51:16 -05:00
|
|
|
alpm_list_t *alpm_list_copy_data(const alpm_list_t *list, size_t size);
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *alpm_list_reverse(alpm_list_t *list);
|
|
|
|
|
|
|
|
/* item accessors */
|
2007-06-05 17:34:33 -04:00
|
|
|
alpm_list_t *alpm_list_first(const alpm_list_t *list);
|
2010-12-08 00:13:36 -05:00
|
|
|
alpm_list_t *alpm_list_nth(const alpm_list_t *list, size_t n);
|
2007-06-05 17:34:33 -04:00
|
|
|
alpm_list_t *alpm_list_next(const alpm_list_t *list);
|
2011-07-02 20:10:36 -04:00
|
|
|
alpm_list_t *alpm_list_previous(const alpm_list_t *list, const alpm_list_t *node);
|
2007-06-05 17:34:33 -04:00
|
|
|
alpm_list_t *alpm_list_last(const alpm_list_t *list);
|
2007-01-19 04:28:44 -05:00
|
|
|
void *alpm_list_getdata(const alpm_list_t *entry);
|
|
|
|
|
|
|
|
/* misc */
|
2010-12-08 00:13:36 -05:00
|
|
|
size_t alpm_list_count(const alpm_list_t *list);
|
2007-12-02 17:48:12 -05:00
|
|
|
void *alpm_list_find(const alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn);
|
|
|
|
void *alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle);
|
|
|
|
char *alpm_list_find_str(const alpm_list_t *haystack, const char *needle);
|
2007-06-05 17:34:33 -04:00
|
|
|
alpm_list_t *alpm_list_diff(const alpm_list_t *lhs, const alpm_list_t *rhs, alpm_list_fn_cmp fn);
|
2010-03-24 01:22:23 -04:00
|
|
|
void alpm_list_diff_sorted(const alpm_list_t *left, const alpm_list_t *right,
|
2009-10-10 20:38:33 -04:00
|
|
|
alpm_list_fn_cmp fn, alpm_list_t **onlyleft, alpm_list_t **onlyright);
|
2007-01-19 04:28:44 -05:00
|
|
|
|
2007-03-29 00:40:49 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2007-01-19 04:28:44 -05:00
|
|
|
#endif /* _ALPM_LIST_H */
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|