source: trunk/libtransmission/list.h @ 7469

Last change on this file since 7469 was 7469, checked in by charles, 13 years ago

(trunk libT) speed improvments from wereHamster

  • Property svn:keywords set to Date Rev Author Id
File size: 2.9 KB
Line 
1/*
2 * This file Copyright (C) 2007-2008 Charles Kerr <charles@transmissionbt.com>
3 *
4 * This file is licensed by the GPL version 2.  Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: list.h 7469 2008-12-22 19:16:06Z charles $
11 */
12
13#ifndef __TRANSMISSION__
14#error only libtransmission should #include this header.
15#endif
16
17#ifndef TR_LIST_H
18#define TR_LIST_H
19
20typedef struct tr_list
21{
22    void *  data;
23    struct tr_list  * next;
24    struct tr_list  * prev;
25}
26tr_list;
27
28typedef int ( *TrListCompareFunc )( const void * a, const void * b );
29typedef void ( *TrListForeachFunc )( void * );
30
31int      tr_list_size( const tr_list * list );
32
33void     tr_list_free( tr_list **        list,
34                       TrListForeachFunc data_free_func );
35
36void     tr_list_append( tr_list ** list,
37                         void *     data );
38
39void     tr_list_prepend( tr_list ** list,
40                          void *     data );
41
42void*    tr_list_pop_front( tr_list ** list );
43
44void*    tr_list_remove_data( tr_list **   list,
45                              const void * data );
46
47void*    tr_list_remove( tr_list **        list,
48                         const void *      b,
49                         TrListCompareFunc compare_func );
50
51tr_list* tr_list_find( tr_list *         list,
52                       const void *      b,
53                       TrListCompareFunc compare_func );
54
55
56/*
57 * Double-linked list with easy memory management and fast
58 * insert/remove operations
59 */
60
61struct __tr_list
62{
63    struct __tr_list * next, * prev;
64};
65
66#define __tr_list_entry(ptr, type, member) ({            \
67    const struct __tr_list *__mptr = (ptr);              \
68    (void *)( (char *)__mptr - offsetof(type,member) );  \
69})
70
71typedef int  ( *__tr_list_cmp_t ) ( const void * a, const void * b );
72typedef void ( *__tr_list_free_t )( void * );
73
74
75/**
76 *    __tr_list_init()
77 *
78 * Init @head as an empty list.
79 */
80void
81__tr_list_init( struct __tr_list * head );
82
83
84/**
85 *    __tr_list_insert()
86 *
87 * Insert @list between @prev and @next.
88 */
89void
90__tr_list_insert( struct __tr_list * list,
91                  struct __tr_list * prev,
92                  struct __tr_list * next);
93
94/**
95 *    __tr_list_splice()
96 *
97 * Connect @prev with @next, removing any nodes that were
98 * in between.
99 */
100void
101__tr_list_splice( struct __tr_list * prev,
102                  struct __tr_list * next);
103
104/**
105 *    __tr_list_append()
106 *
107 * Append @list to the end of @head.
108 */
109void
110__tr_list_append( struct __tr_list * head,
111                  struct __tr_list * list);
112
113/**
114 *    __tr_list_remove()
115 *
116 * Remove @head from the list it is in.
117 */
118void
119__tr_list_remove( struct __tr_list * head );
120
121/**
122 *    __tr_list_destroy()
123 *
124 * Destroy the list and free all nodes
125 */
126void
127__tr_list_destroy( struct __tr_list * head,
128                   __tr_list_free_t   func);
129
130#endif /* TR_LIST_H */
131
Note: See TracBrowser for help on using the repository browser.