source: trunk/libtransmission/ptrarray.h @ 6953

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

(libT) a small, simple memory optimization

  • Property svn:keywords set to Date Rev Author Id
File size: 3.4 KB
RevLine 
[5389]1/******************************************************************************
2 * $Id: ptrarray.h 6953 2008-10-25 02:15:37Z charles $
3 *
[4404]4 * This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com>
[2757]5 *
[5389]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:
[2843]12 *
[5389]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 *****************************************************************************/
[2757]24
[5389]25#ifndef _TR_PTR_ARRAY_H_
26#define _TR_PTR_ARRAY_H_
[2757]27
28/**
29 * A simple pointer array that resizes itself dynamically.
30 */
[3105]31typedef struct tr_ptrArray tr_ptrArray;
[2757]32
[6795]33typedef void ( *PtrArrayForeachFunc )( void * );
[3242]34
[6795]35tr_ptrArray * tr_ptrArrayNew( void );
[2757]36
[6795]37tr_ptrArray * tr_ptrArrayDup( tr_ptrArray* );
38
39void          tr_ptrArrayForeach(
40                        tr_ptrArray*,
41    PtrArrayForeachFunc func );
42
[6953]43void          tr_ptrArrayFree( tr_ptrArray         * array,
44                               PtrArrayForeachFunc   func );
[6795]45
[6953]46void*         tr_ptrArrayNth( tr_ptrArray   * array,
47                              int             nth );
[6795]48
[6953]49void*         tr_ptrArrayBack( tr_ptrArray  * array );
[6795]50
[6953]51void**        tr_ptrArrayPeek( tr_ptrArray  * array,
52                               int          * size );
[6795]53
[6953]54void**        tr_ptrArrayBase( tr_ptrArray  * array );
[6795]55
[6953]56void          tr_ptrArrayClear( tr_ptrArray * array );
[6795]57
[6953]58int           tr_ptrArrayInsert( tr_ptrArray * array,
59                                 void        * insertMe,
60                                 int           pos );
[6795]61
[6953]62int           tr_ptrArrayAppend( tr_ptrArray * array,
63                                 void        * appendMe );
[6795]64
[6953]65void*         tr_ptrArrayPop( tr_ptrArray    * array );
[6795]66
[6953]67void          tr_ptrArrayErase( tr_ptrArray  * array,
68                                int            begin,
69                                int            end );
[6795]70
71int           tr_ptrArraySize( const tr_ptrArray* );
72
73int           tr_ptrArrayEmpty( const tr_ptrArray* );
74
[6953]75int           tr_ptrArrayInsertSorted( tr_ptrArray * array,
76                                       void        * value,
77                                       int compare(const void*, const void*) );
[6795]78
[6953]79void*         tr_ptrArrayRemoveSorted( tr_ptrArray * array,
80                                       void        * value,
81                                       int compare(const void*, const void*) );
[6795]82
[6953]83void*         tr_ptrArrayFindSorted( tr_ptrArray * array,
84                                     const void  * key,
85                                     int compare(const void*, const void*) );
[6795]86
[2757]87#endif
Note: See TracBrowser for help on using the repository browser.