Changeset 4b1c6a4b in mainline
- Timestamp:
- 2019-08-03T08:40:30Z (5 years ago)
- Children:
- 7671231
- Parents:
- 8432ae1
- git-author:
- Michal Koutny <xm.koutny+hos@…> (2015-04-25 00:30:34)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 08:40:30)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
r8432ae1 r4b1c6a4b 251 251 $(USPACE_PATH)/lib/c/test-libc \ 252 252 $(USPACE_PATH)/lib/label/test-liblabel \ 253 $(USPACE_PATH)/lib/conf/test-libconf \ 253 254 $(USPACE_PATH)/lib/posix/test-libposix \ 254 255 $(USPACE_PATH)/lib/sif/test-libsif \ -
uspace/lib/c/generic/adt/dyn_array.c
r8432ae1 r4b1c6a4b 45 45 46 46 47 static void dyn_array_clear(dyn_array_t *da) 48 { 49 da->size = 0; 50 } 47 51 48 52 49 static int dyn_array_realloc(dyn_array_t *da, size_t capacity) … … 80 77 } 81 78 79 /** Clear dynamic array (empty) */ 80 void dyn_array_clear(dyn_array_t *da) 81 { 82 da->size = 0; 83 } 84 82 85 int _dyn_array_initialize(dyn_array_t *da, size_t item_size, size_t capacity) 83 86 { 84 87 da->_item_size = item_size; 85 88 da->_data = NULL; 86 89 87 90 da->capacity = 0; 88 91 da->size = 0; -
uspace/lib/c/include/adt/dyn_array.h
r8432ae1 r4b1c6a4b 97 97 /** Dynamic array iteration 98 98 * 99 * @param[in] it name of variable used as iterator, it's pointer to @p type 99 * @param[in] dyn_array dyn_array_t (not pointer) 100 * @param[in] it name of variable used as iterator, it's pointer 101 * to @p type 100 102 */ 101 103 #define dyn_array_foreach(dyn_array, type, it) \ … … 103 105 it != ((type *)(dyn_array)._data + (dyn_array).size); ++it) 104 106 107 /** Find first occurence of value 108 * 109 * @param[in] dyn_array dyn_array_t * 110 * @param[in] value value to search for 111 * 112 * @return index of found value or size of array when no found 113 */ 114 #define dyn_array_find(dyn_array, type, value) \ 115 ({ \ 116 size_t _result = (dyn_array)->size; \ 117 dyn_array_foreach(*(dyn_array), type, _it) { \ 118 if (*_it == value) { \ 119 _result = _it - (type *)(dyn_array)->_data; \ 120 break; \ 121 } \ 122 } \ 123 _result; \ 124 }) 105 125 106 126 extern void dyn_array_destroy(dyn_array_t *); 107 127 extern void dyn_array_remove(dyn_array_t *, size_t); 128 void dyn_array_clear(dyn_array_t *); 108 129 109 130 extern int _dyn_array_initialize(dyn_array_t *, size_t, size_t); -
uspace/lib/c/test/dyn_array.c
r8432ae1 r4b1c6a4b 124 124 } 125 125 126 PCUT_TEST(find) { 127 dyn_array_append(&da, data_t, 10); 128 dyn_array_append(&da, data_t, 11); 129 dyn_array_append(&da, data_t, 12); 130 dyn_array_append(&da, data_t, 99); 131 132 PCUT_ASSERT_INT_EQUALS(0, dyn_array_find(&da, data_t, 10)); 133 PCUT_ASSERT_INT_EQUALS(3, dyn_array_find(&da, data_t, 99)); 134 PCUT_ASSERT_INT_EQUALS(4, dyn_array_find(&da, data_t, 666)); 135 } 126 136 127 137 PCUT_EXPORT(dyn_array);
Note:
See TracChangeset
for help on using the changeset viewer.