diff options
| author | Thomas Schmucker <ts@its1.de> | 2021-12-30 11:01:32 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2021-12-30 11:01:32 +0100 |
| commit | 214f0923ba2981649f14ec3761662332df446d9d (patch) | |
| tree | a400269f616ed53cf378b7ac77bf1f486113c796 /arraylist.c | |
| parent | 5e696c74c9649b0e54133d46a3ae92e5ce0632fb (diff) | |
| download | data-structures-214f0923ba2981649f14ec3761662332df446d9d.tar.gz data-structures-214f0923ba2981649f14ec3761662332df446d9d.tar.bz2 data-structures-214f0923ba2981649f14ec3761662332df446d9d.zip | |
code cleanup
Diffstat (limited to 'arraylist.c')
| -rw-r--r-- | arraylist.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/arraylist.c b/arraylist.c index a8cebb0..cb23e94 100644 --- a/arraylist.c +++ b/arraylist.c | |||
| @@ -91,6 +91,8 @@ ArrayList_growIfNeeded(struct ArrayList *arrayList) | |||
| 91 | 91 | ||
| 92 | assert(arrayList->array); | 92 | assert(arrayList->array); |
| 93 | } | 93 | } |
| 94 | |||
| 95 | assert(arrayList->capacity > arrayList->size); | ||
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | void | 98 | void |
| @@ -111,7 +113,9 @@ ArrayList_insertAt(struct ArrayList *arrayList, size_t idx, T *ptr) | |||
| 111 | 113 | ||
| 112 | ArrayList_growIfNeeded(arrayList); | 114 | ArrayList_growIfNeeded(arrayList); |
| 113 | 115 | ||
| 114 | memmove(&arrayList->array[idx + 1], &arrayList->array[idx], (arrayList->size - idx) * sizeof(arrayList->array[0])); | 116 | memmove(&arrayList->array[idx + 1], |
| 117 | &arrayList->array[idx], | ||
| 118 | (arrayList->size - idx) * sizeof(arrayList->array[0])); | ||
| 115 | arrayList->array[idx] = ptr; | 119 | arrayList->array[idx] = ptr; |
| 116 | ++arrayList->size; | 120 | ++arrayList->size; |
| 117 | } | 121 | } |
| @@ -152,7 +156,9 @@ ArrayList_removeAt(struct ArrayList *arrayList, size_t idx, void clear_func(T *, | |||
| 152 | } | 156 | } |
| 153 | 157 | ||
| 154 | #if defined(ARRAYLIST_KEEP_ORDER) | 158 | #if defined(ARRAYLIST_KEEP_ORDER) |
| 155 | memmove(&arrayList->arrayList[idx], &arrayList->arrayList[idx + 1], (arrayList->size - (idx + 1)) * sizeof(arrayList->arrayList[0])); | 159 | memmove(&arrayList->arrayList[idx], |
| 160 | &arrayList->arrayList[idx + 1], | ||
| 161 | (arrayList->size - (idx + 1)) * sizeof(arrayList->arrayList[0])); | ||
| 156 | #else | 162 | #else |
| 157 | arrayList->array[idx] = arrayList->array[arrayList->size - 1]; | 163 | arrayList->array[idx] = arrayList->array[arrayList->size - 1]; |
| 158 | #endif | 164 | #endif |
