aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2020-08-15 14:32:59 +0200
committerThomas Schmucker <ts@its1.de>2020-08-15 14:32:59 +0200
commita1979af4de4c3f2d6a3cea3d3181170b67647143 (patch)
treefacff42eca8c44db47421a1d98e53d6aeacbbcd9
parent861f4a49a425dcf052fc36cef963a99d82a9c974 (diff)
downloaddata-structures-a1979af4de4c3f2d6a3cea3d3181170b67647143.tar.gz
data-structures-a1979af4de4c3f2d6a3cea3d3181170b67647143.tar.bz2
data-structures-a1979af4de4c3f2d6a3cea3d3181170b67647143.zip
vereinfache das Kopieren der Chunkzeiger.
-rw-r--r--deque.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/deque.c b/deque.c
index a4fbc1b..f1da207 100644
--- a/deque.c
+++ b/deque.c
@@ -71,9 +71,12 @@ grow_map(struct deque *d)
71 T ** map = calloc(capacity, sizeof *map); 71 T ** map = calloc(capacity, sizeof *map);
72 72
73 // copy elements 73 // copy elements
74 size_t i; 74 size_t i, j;
75 for ( i = 0; i != d->map_capacity; ++i ) { 75 for ( i = 0, j = d->map_begin; i != d->map_capacity; ++i, ++j ) {
76 map[i] = d->map[(i + d->map_begin) % d->map_capacity]; 76 if ( j == d->map_capacity ) {
77 j = 0;
78 }
79 map[i] = d->map[j];
77 } 80 }
78 81
79 // initialize the rest (new) elements with NULL 82 // initialize the rest (new) elements with NULL
@@ -280,15 +283,6 @@ main(void)
280 283
281 deque_init(&c); 284 deque_init(&c);
282 285
283 for ( int i = 0; i != 100; ++i ) {
284 deque_push_back(&c, i);
285 //deque_show(&c);
286 }
287
288 for ( int i = 0; i != 100; ++i ) {
289 deque_push_front(&c, 1000 + i);
290 }
291
292 T data; 286 T data;
293 while ( deque_pop_front(&c, &data) ) { 287 while ( deque_pop_front(&c, &data) ) {
294 printf("%u, ", data); 288 printf("%u, ", data);