blob: d7321116bc063147a3de90d154d8fdd04f2805c6 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_ARRAY_H__
20#define __PJ_ARRAY_H__
21
22/**
23 * @file array.h
24 * @brief PJLIB Array helper.
25 */
26#include <pj/types.h>
27
28PJ_BEGIN_DECL
29
30/**
31 * @defgroup PJ_ARRAY Array helper.
32 * @ingroup PJ_DS
33 * @{
34 *
35 * This module provides helper to manipulate array of elements of any size.
36 * It provides most used array operations such as insert, erase, and search.
37 */
38
39/**
40 * Insert value to the array at the given position, and rearrange the
41 * remaining nodes after the position.
42 *
43 * @param array the array.
44 * @param elem_size the size of the individual element.
45 * @param count the current number of elements in the array.
46 * @param pos the position where the new element is put.
47 * @param value the value to copy to the new element.
48 */
49PJ_DECL(void) pj_array_insert( void *array,
50 unsigned elem_size,
51 unsigned count,
52 unsigned pos,
53 const void *value);
54
55/**
56 * Erase a value from the array at given position, and rearrange the remaining
57 * elements post the erased element.
58 *
59 * @param array the array.
60 * @param elem_size the size of the individual element.
61 * @param count the current number of elements in the array.
62 * @param pos the index/position to delete.
63 */
64PJ_DECL(void) pj_array_erase( void *array,
65 unsigned elem_size,
66 unsigned count,
67 unsigned pos);
68
69/**
70 * Search the first value in the array according to matching function.
71 *
72 * @param array the array.
73 * @param elem_size the individual size of the element.
74 * @param count the number of elements.
75 * @param matching the matching function, which MUST return PJ_SUCCESS if
76 * the specified element match.
77 * @param result the pointer to the value found.
78 *
79 * @return PJ_SUCCESS if value is found, otherwise the error code.
80 */
81PJ_DECL(pj_status_t) pj_array_find( const void *array,
82 unsigned elem_size,
83 unsigned count,
84 pj_status_t (*matching)(const void *value),
85 void **result);
86
87/**
88 * @}
89 */
90
91PJ_END_DECL
92
93
94#endif /* __PJ_ARRAY_H__ */
95