Revision 9b0a0ba9 lib/slists.c

View differences:

lib/slists.c
150 150
  to->tail = q;
151 151
  s_merge((snode *) &l->null, (snode *) &to->null);
152 152
}
153

  
154
#ifdef TEST
155

  
156
#include "lib/resource.h"
157
#include <stdio.h>
158

  
159
void dump(char *c, slist *a)
160
{
161
  snode *x;
162

  
163
  puts(c);
164
  for(x=SHEAD(*a); x; x=x->next)
165
    {
166
      siterator *i, *j;
167
      printf("%p", x);
168
      j = (siterator *) x;
169
      for(i=x->readers; i; i=i->next)
170
	{
171
	  if (i->prev != j)
172
	    printf(" ???");
173
	  j = i;
174
	  printf(" [%p:%p]", i, i->node);
175
	}
176
      putchar('\n');
177
    }
178
  puts("---");
179
}
180

  
181
int main(void)
182
{
183
  slist a, b;
184
  snode *x, *y;
185
  siterator i, j;
186

  
187
  s_init_list(&a);
188
  s_init_list(&b);
189
  x = xmalloc(sizeof(*x));
190
  s_add_tail(&a, x);
191
  x = xmalloc(sizeof(*x));
192
  s_add_tail(&a, x);
193
  x = xmalloc(sizeof(*x));
194
  s_add_tail(&a, x);
195
  dump("1", &a);
196

  
197
  s_init(&i, &a);
198
  s_init(&j, &a);
199
  dump("2", &a);
200

  
201
  x = s_get(&i);
202
  printf("Got %p\n", x);
203
  dump("3", &a);
204

  
205
  s_put(&i, x->next);
206
  dump("4", &a);
207

  
208
  y = s_get(&j);
209
  while (y)
210
    {
211
      s_put(&j, y);
212
      dump("5*", &a);
213
      y = s_get(&j)->next;
214
    }
215

  
216
  dump("5 done", &a);
217

  
218
  s_rem_node(a.head->next);
219
  dump("6 (deletion)", &a);
220

  
221
  s_put(&i, s_get(&i)->next);
222
  dump("6 (relink)", &a);
223

  
224
  x = xmalloc(sizeof(*x));
225
  s_add_tail(&b, x);
226
  dump("7 (second list)", &b);
227

  
228
  s_add_tail_list(&b, &a);
229
  dump("8 (after merge)", &b);
230

  
231
  return 0;
232
}
233

  
234
#endif

Also available in: Unified diff