source: trunk/libtransmission/ptrarray.h @ 7524

Last change on this file since 7524 was 7524, checked in by charles, 12 years ago

(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_ptrArray, contain the tr_ptrArray directly rather than a pointer to one allocated elsewhere on the heap.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.7 KB
Line 
1/******************************************************************************
2 * $Id: ptrarray.h 7524 2008-12-29 08:54:36Z charles $
3 *
4 * This file Copyright (C) 2007-2008 Charles Kerr <charles@transmissionbt.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef __TRANSMISSION__
26#error only libtransmission should #include this header.
27#endif
28
29#ifndef _TR_PTR_ARRAY_H_
30#define _TR_PTR_ARRAY_H_
31
32/**
33 * A simple pointer array that resizes itself dynamically.
34 */
35typedef struct tr_ptrArray
36{
37    void ** items;
38    int     n_items;
39    int     n_alloc;
40}
41tr_ptrArray;
42
43#define TR_PTR_ARRAY_DATA( A ) ((A)->items)
44#define TR_PTR_ARRAY_LENGTH( A ) ((A)->n_items)
45
46typedef void ( *PtrArrayForeachFunc )( void * );
47
48extern const tr_ptrArray TR_PTR_ARRAY_INIT;
49
50void          tr_ptrArrayDestruct( tr_ptrArray*, PtrArrayForeachFunc func );
51
52tr_ptrArray * tr_ptrArrayNew( void );
53
54tr_ptrArray * tr_ptrArrayDup( tr_ptrArray* );
55
56void          tr_ptrArrayForeach( tr_ptrArray         * array,
57                                  PtrArrayForeachFunc   func );
58
59void          tr_ptrArrayFree( tr_ptrArray         * array,
60                               PtrArrayForeachFunc   func );
61
62void*         tr_ptrArrayNth( tr_ptrArray   * array,
63                              int             nth );
64
65void*         tr_ptrArrayBack( tr_ptrArray  * array );
66
67void**        tr_ptrArrayPeek( tr_ptrArray  * array,
68                               int          * size );
69
70void**        tr_ptrArrayBase( tr_ptrArray  * array );
71
72void          tr_ptrArrayClear( tr_ptrArray * array );
73
74int           tr_ptrArrayInsert( tr_ptrArray * array,
75                                 void        * insertMe,
76                                 int           pos );
77
78int           tr_ptrArrayAppend( tr_ptrArray * array,
79                                 void        * appendMe );
80
81void*         tr_ptrArrayPop( tr_ptrArray    * array );
82
83void          tr_ptrArrayErase( tr_ptrArray  * array,
84                                int            begin,
85                                int            end );
86
87int           tr_ptrArraySize( const tr_ptrArray* );
88
89int           tr_ptrArrayEmpty( const tr_ptrArray* );
90
91int           tr_ptrArrayInsertSorted( tr_ptrArray * array,
92                                       void        * value,
93                                       int compare(const void*, const void*) );
94
95void*         tr_ptrArrayRemoveSorted( tr_ptrArray * array,
96                                       void        * value,
97                                       int compare(const void*, const void*) );
98
99void*         tr_ptrArrayFindSorted( tr_ptrArray * array,
100                                     const void  * key,
101                                     int compare(const void*, const void*) );
102
103#endif
Note: See TracBrowser for help on using the repository browser.