Changeset dd5c623 in mainline
- Timestamp:
- 2019-08-03T09:44:51Z (5 years ago)
- Children:
- 4224ef7
- Parents:
- dda2602
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-05-08 11:21:11)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:44:51)
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/dyn_array.c
rdda2602 rdd5c623 73 73 assert(index < da->size); 74 74 _dyn_array_unshift(da, index, 1); 75 int rc = _dyn_array_reserve(da, da->size);75 int rc = dyn_array_reserve(da, da->size); 76 76 assert(rc == EOK); 77 77 } … … 83 83 } 84 84 85 int _dyn_array_initialize(dyn_array_t *da, size_t item_size, size_t capacity)86 {87 da->_item_size = item_size;88 da->_data = NULL;89 90 da->capacity = 0;91 da->size = 0;92 93 return _dyn_array_reserve(da, capacity);94 }95 96 85 /** Grows/shrinks array so that it effeciently stores desired capacity 97 86 * 98 87 * @param da 99 * @param[in] desired capacity of array 88 * @param[in] desired capacity of array (items) 100 89 * 101 90 * @return EOK 102 91 * @return ENOMEM 103 92 */ 104 int _dyn_array_reserve(dyn_array_t *da, size_t capacity)93 int dyn_array_reserve(dyn_array_t *da, size_t capacity) 105 94 { 106 95 const size_t factor = 2; … … 115 104 116 105 return dyn_array_realloc(da, new_capacity); 106 } 107 108 void _dyn_array_initialize(dyn_array_t *da, size_t item_size) 109 { 110 da->_item_size = item_size; 111 da->_data = NULL; 112 113 da->capacity = 0; 114 da->size = 0; 117 115 } 118 116 -
uspace/lib/c/include/adt/dyn_array.h
rdda2602 rdd5c623 55 55 * @param[in] capacity initial capacity of array 56 56 * 57 * @return EOK on success 58 * @return ENOMEM on low memory 57 * @return void 59 58 */ 60 #define dyn_array_initialize(dyn_array, type , capacity)\61 _dyn_array_initialize((dyn_array), sizeof(type) , capacity)59 #define dyn_array_initialize(dyn_array, type) \ 60 _dyn_array_initialize((dyn_array), sizeof(type)) 62 61 63 62 … … 78 77 size_t _index = (index); \ 79 78 dyn_array_t *_da = (dyn_array); \ 80 int rc = _dyn_array_reserve(_da, _da->size + 1); \79 int rc = dyn_array_reserve(_da, _da->size + 1); \ 81 80 if (!rc) { \ 82 81 _dyn_array_shift(_da, _index, 1); \ … … 127 126 extern void dyn_array_remove(dyn_array_t *, size_t); 128 127 void dyn_array_clear(dyn_array_t *); 128 extern int dyn_array_reserve(dyn_array_t *, size_t); 129 129 130 extern int _dyn_array_initialize(dyn_array_t *, size_t, size_t); 131 extern int _dyn_array_reserve(dyn_array_t *, size_t); 130 extern void _dyn_array_initialize(dyn_array_t *, size_t); 132 131 extern void _dyn_array_shift(dyn_array_t *, size_t, size_t); 133 132 extern void _dyn_array_unshift(dyn_array_t *, size_t, size_t); -
uspace/lib/c/test/dyn_array.c
rdda2602 rdd5c623 39 39 40 40 PCUT_TEST_BEFORE { 41 int rc = dyn_array_initialize(&da, data_t, 3); 41 dyn_array_initialize(&da, data_t); 42 int rc = dyn_array_reserve(&da, 3); 42 43 assert(rc == EOK); 43 44 } -
uspace/srv/sysman/job.c
rdda2602 rdd5c623 89 89 job_add_ref(job); 90 90 91 (void)dyn_array_initialize(&job->blocked_jobs, job_ptr_t, 0);91 dyn_array_initialize(&job->blocked_jobs, job_ptr_t); 92 92 job->blocking_jobs = 0; 93 93 job->blocking_job_failed = false; -
uspace/srv/sysman/sysman.c
rdda2602 rdd5c623 254 254 job_t *job = data; 255 255 dyn_array_t job_closure; 256 dyn_array_initialize(&job_closure, job_ptr_t , 0);256 dyn_array_initialize(&job_closure, job_ptr_t); 257 257 258 258 int rc = job_create_closure(job, &job_closure);
Note:
See TracChangeset
for help on using the changeset viewer.