dtsize.c 597 B

123456789101112131415161718192021222324252627282930
  1. #include <cdt/dthdr.h>
  2. /* Return the # of objects in the dictionary
  3. **
  4. ** Written by Kiem-Phong Vo (5/25/96)
  5. */
  6. static int treecount(Dtlink_t* e)
  7. { return e ? treecount(e->left) + treecount(e->right) + 1 : 0;
  8. }
  9. int dtsize(Dt_t* dt)
  10. {
  11. Dtlink_t* t;
  12. int size;
  13. UNFLATTEN(dt);
  14. if(dt->data->size < 0) /* !(dt->data->type&(DT_SET|DT_BAG)) */
  15. { if(dt->data->type&(DT_OSET|DT_OBAG))
  16. dt->data->size = treecount(dt->data->here);
  17. else if(dt->data->type&DT_QUEUE)
  18. { for(size = 0, t = dt->data->head; t; t = t->right)
  19. size += 1;
  20. dt->data->size = size;
  21. }
  22. }
  23. return dt->data->size;
  24. }