array.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 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. * @file array.h
  23. * @brief PJLIB Array helper.
  24. */
  25. #include <pj/types.h>
  26. PJ_BEGIN_DECL
  27. /**
  28. * @defgroup PJ_ARRAY Array helper.
  29. * @ingroup PJ_DS
  30. * @{
  31. *
  32. * This module provides helper to manipulate array of elements of any size.
  33. * It provides most used array operations such as insert, erase, and search.
  34. */
  35. /**
  36. * Insert value to the array at the given position, and rearrange the
  37. * remaining nodes after the position.
  38. *
  39. * @param array the array.
  40. * @param elem_size the size of the individual element.
  41. * @param count the CURRENT number of elements in the array.
  42. * @param pos the position where the new element is put.
  43. * @param value the value to copy to the new element.
  44. */
  45. PJ_DECL(void) pj_array_insert( void *array,
  46. unsigned elem_size,
  47. unsigned count,
  48. unsigned pos,
  49. const void *value);
  50. /**
  51. * Erase a value from the array at given position, and rearrange the remaining
  52. * elements post the erased element.
  53. *
  54. * @param array the array.
  55. * @param elem_size the size of the individual element.
  56. * @param count the current number of elements in the array.
  57. * @param pos the index/position to delete.
  58. */
  59. PJ_DECL(void) pj_array_erase( void *array,
  60. unsigned elem_size,
  61. unsigned count,
  62. unsigned pos);
  63. /**
  64. * Search the first value in the array according to matching function.
  65. *
  66. * @param array the array.
  67. * @param elem_size the individual size of the element.
  68. * @param count the number of elements.
  69. * @param matching the matching function, which MUST return PJ_SUCCESS if
  70. * the specified element match.
  71. * @param result the pointer to the value found.
  72. *
  73. * @return PJ_SUCCESS if value is found, otherwise the error code.
  74. */
  75. PJ_DECL(pj_status_t) pj_array_find( const void *array,
  76. unsigned elem_size,
  77. unsigned count,
  78. pj_status_t (*matching)(const void *value),
  79. void **result);
  80. /**
  81. * @}
  82. */
  83. PJ_END_DECL
  84. #endif /* __PJ_ARRAY_H__ */