aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2022-01-16 10:41:49 +0100
committerThomas Schmucker <ts@its1.de>2022-01-16 10:41:49 +0100
commitfb0e8a6fa561cd2a518b6a65f50e8179a19985cc (patch)
treef9784621dbd6dcfd9faa8ca3194dfac826d8aa2a
parent2a32335f1ff91e96fd6a09819317f77d6b8bf285 (diff)
downloaddata-structures-fb0e8a6fa561cd2a518b6a65f50e8179a19985cc.tar.gz
data-structures-fb0e8a6fa561cd2a518b6a65f50e8179a19985cc.tar.bz2
data-structures-fb0e8a6fa561cd2a518b6a65f50e8179a19985cc.zip
feat: überflüssig Klammern bei sizeof-Operator entfernt
-rw-r--r--allocator.h5
-rw-r--r--arraylist.c8
-rw-r--r--queue.c2
-rw-r--r--rb.c4
-rw-r--r--ringbuff.c6
-rw-r--r--stack.c2
-rw-r--r--stack2.c4
-rw-r--r--tree.c4
8 files changed, 13 insertions, 22 deletions
diff --git a/allocator.h b/allocator.h
index fc28833..d47af52 100644
--- a/allocator.h
+++ b/allocator.h
@@ -1,5 +1,4 @@
1#ifndef ITS1_ALLOCATOR_H_INCLUDED 1#pragma once
2#define ITS1_ALLOCATOR_H_INCLUDED
3 2
4#include <stddef.h> /* size_t */ 3#include <stddef.h> /* size_t */
5 4
@@ -29,5 +28,3 @@ void *its1_malloc_zero(struct its1_allocator *allocator, size_t n);
29 28
30#define NEW(ptr) ((ptr) = ALLOCATE(sizeof *(ptr))) 29#define NEW(ptr) ((ptr) = ALLOCATE(sizeof *(ptr)))
31#define NEW0(ptr) ((ptr) = ALLOCATE_ZERO(sizeof *(ptr))) 30#define NEW0(ptr) ((ptr) = ALLOCATE_ZERO(sizeof *(ptr)))
32
33#endif
diff --git a/arraylist.c b/arraylist.c
index cb23e94..f010d07 100644
--- a/arraylist.c
+++ b/arraylist.c
@@ -115,7 +115,7 @@ ArrayList_insertAt(struct ArrayList *arrayList, size_t idx, T *ptr)
115 115
116 memmove(&arrayList->array[idx + 1], 116 memmove(&arrayList->array[idx + 1],
117 &arrayList->array[idx], 117 &arrayList->array[idx],
118 (arrayList->size - idx) * sizeof(arrayList->array[0])); 118 (arrayList->size - idx) * sizeof arrayList->array[0]);
119 arrayList->array[idx] = ptr; 119 arrayList->array[idx] = ptr;
120 ++arrayList->size; 120 ++arrayList->size;
121} 121}
@@ -158,7 +158,7 @@ ArrayList_removeAt(struct ArrayList *arrayList, size_t idx, void clear_func(T *,
158#if defined(ARRAYLIST_KEEP_ORDER) 158#if defined(ARRAYLIST_KEEP_ORDER)
159 memmove(&arrayList->arrayList[idx], 159 memmove(&arrayList->arrayList[idx],
160 &arrayList->arrayList[idx + 1], 160 &arrayList->arrayList[idx + 1],
161 (arrayList->size - (idx + 1)) * sizeof(arrayList->arrayList[0])); 161 (arrayList->size - (idx + 1)) * sizeof arrayList->arrayList[0]);
162#else 162#else
163 arrayList->array[idx] = arrayList->array[arrayList->size - 1]; 163 arrayList->array[idx] = arrayList->array[arrayList->size - 1];
164#endif 164#endif
@@ -196,7 +196,7 @@ ArrayList_sort(struct ArrayList *arrayList, int cmp(const T *, const T *, void *
196 }; 196 };
197 197
198 // Das vollständige qsort_x()-Drama: https://stackoverflow.com/a/46042467 198 // Das vollständige qsort_x()-Drama: https://stackoverflow.com/a/46042467
199 qsort_r(arrayList->array, arrayList->size, sizeof(arrayList->array[0]), &context, ArrayList_qsortHelper); 199 qsort_r(arrayList->array, arrayList->size, sizeof arrayList->array[0], &context, ArrayList_qsortHelper);
200} 200}
201 201
202bool 202bool
@@ -243,7 +243,7 @@ ArrayList_binarySearch(struct ArrayList *arrayList, void *key, int cmp(void *, c
243 .args = args 243 .args = args
244 }; 244 };
245 245
246 T **pos = bsearch(&context, arrayList->array, arrayList->size, sizeof(arrayList->array[0]), ArrayList_bsearchHelper); 246 T **pos = bsearch(&context, arrayList->array, arrayList->size, sizeof arrayList->array[0], ArrayList_bsearchHelper);
247 if ( pos ) { 247 if ( pos ) {
248 *loc = (size_t)(pos - arrayList->array); 248 *loc = (size_t)(pos - arrayList->array);
249 return true; 249 return true;
diff --git a/queue.c b/queue.c
index 8533691..6a472ee 100644
--- a/queue.c
+++ b/queue.c
@@ -33,7 +33,7 @@ queue_put(struct queue *queue, T data)
33{ 33{
34 struct queue_item *new_item; 34 struct queue_item *new_item;
35 35
36 if ( (new_item = malloc(sizeof(*new_item))) != NULL ) { 36 if ( (new_item = malloc(sizeof *new_item)) != NULL ) {
37 struct queue_item *tmp = queue->tail; 37 struct queue_item *tmp = queue->tail;
38 new_item->data = data; 38 new_item->data = data;
39 new_item->next = NULL; 39 new_item->next = NULL;
diff --git a/rb.c b/rb.c
index ac21ec8..7c2d2c1 100644
--- a/rb.c
+++ b/rb.c
@@ -189,7 +189,7 @@ verify_property_5_helper(node n, int black_count, int *path_black_count)
189rbtree 189rbtree
190rbtree_create() 190rbtree_create()
191{ 191{
192 rbtree t = malloc(sizeof(struct rbtree_t)); 192 rbtree t = malloc(sizeof *t);
193 t->root = NULL; 193 t->root = NULL;
194 verify_properties(t); 194 verify_properties(t);
195 return t; 195 return t;
@@ -198,7 +198,7 @@ rbtree_create()
198node 198node
199new_node(void *key, void *value, color node_color, node left, node right) 199new_node(void *key, void *value, color node_color, node left, node right)
200{ 200{
201 node result = malloc(sizeof(struct rbtree_node_t)); 201 node result = malloc(sizeof *result);
202 result->key = key; 202 result->key = key;
203 result->value = value; 203 result->value = value;
204 result->color = node_color; 204 result->color = node_color;
diff --git a/ringbuff.c b/ringbuff.c
index 2cd0062..1294b3b 100644
--- a/ringbuff.c
+++ b/ringbuff.c
@@ -107,12 +107,6 @@ ring_get(struct ring_buffer *rb, T *data)
107/* -->8-- */ 107/* -->8-- */
108 108
109void 109void
110f()
111{
112 ERROR("");
113}
114
115void
116debug_print(const char *msg, struct ring_buffer *rb) 110debug_print(const char *msg, struct ring_buffer *rb)
117{ 111{
118 printf("%s: head: %zu, tail: %zu\n", msg, rb->head, rb->tail); 112 printf("%s: head: %zu, tail: %zu\n", msg, rb->head, rb->tail);
diff --git a/stack.c b/stack.c
index 162324e..48b9eba 100644
--- a/stack.c
+++ b/stack.c
@@ -33,7 +33,7 @@ stack_push(struct stack *stack, T data)
33{ 33{
34 struct stack_item *new_item; 34 struct stack_item *new_item;
35 35
36 if ( (new_item = malloc(sizeof(*new_item))) != NULL ) { 36 if ( (new_item = malloc(sizeof *new_item)) != NULL ) {
37 new_item->data = data; 37 new_item->data = data;
38 new_item->next = stack->head; 38 new_item->next = stack->head;
39 stack->head = new_item; 39 stack->head = new_item;
diff --git a/stack2.c b/stack2.c
index aa5d6ed..5f4ba41 100644
--- a/stack2.c
+++ b/stack2.c
@@ -28,7 +28,7 @@ bool
28stack_push(struct stack *stack, T data) 28stack_push(struct stack *stack, T data)
29{ 29{
30 if ( stack->array == NULL ) { 30 if ( stack->array == NULL ) {
31 if ( (stack->array = malloc(10 * sizeof(*stack->array))) != NULL ) { 31 if ( (stack->array = malloc(10 * sizeof *stack->array)) != NULL ) {
32 stack->sz = 10; 32 stack->sz = 10;
33 stack->p = 0; 33 stack->p = 0;
34 } 34 }
@@ -42,7 +42,7 @@ stack_push(struct stack *stack, T data)
42 size_t new_sz; 42 size_t new_sz;
43 T * new_array; 43 T * new_array;
44 44
45 if ( (new_array = realloc(stack->array, (new_sz = (stack->sz * 3 / 2)) * sizeof(*stack->array))) != NULL ) { 45 if ( (new_array = realloc(stack->array, (new_sz = (stack->sz * 3 / 2)) * sizeof *stack->array)) != NULL ) {
46 stack->array = new_array; 46 stack->array = new_array;
47 stack->sz = new_sz; 47 stack->sz = new_sz;
48 } 48 }
diff --git a/tree.c b/tree.c
index e6ee86e..93690e2 100644
--- a/tree.c
+++ b/tree.c
@@ -340,7 +340,7 @@ stack_push(struct stack *stack, struct tree_node *data)
340{ 340{
341 struct stack_item *new_item; 341 struct stack_item *new_item;
342 342
343 if ( (new_item = malloc(sizeof(*new_item))) ) { 343 if ( (new_item = malloc(sizeof *new_item)) ) {
344 new_item->data = data; 344 new_item->data = data;
345 new_item->next = stack->head; 345 new_item->next = stack->head;
346 stack->head = new_item; 346 stack->head = new_item;
@@ -426,7 +426,7 @@ queue_put(struct queue *queue, struct tree_node *data)
426{ 426{
427 struct queue_item *new_item; 427 struct queue_item *new_item;
428 428
429 if ( (new_item = malloc(sizeof(*new_item))) ) { 429 if ( (new_item = malloc(sizeof *new_item)) ) {
430 struct queue_item *tail; 430 struct queue_item *tail;
431 431
432 tail = queue->tail; 432 tail = queue->tail;