idtree.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef CCAN_IDTREE_H
  2. #define CCAN_IDTREE_H
  3. #include <stdbool.h>
  4. /**
  5. * idtree_new - create an idr_context
  6. * @mem_ctx: talloc parent to allocate from (may be NULL).
  7. *
  8. * Allocate an empty id tree. You can free it with talloc_free().
  9. */
  10. struct idtree *idtree_new(void *mem_ctx);
  11. /**
  12. * idtree_add - get lowest available id, and assign a pointer to it.
  13. * @idtree: the tree to allocate from
  14. * @ptr: the non-NULL pointer to associate with the id
  15. * @limit: the maximum id to allocate (ie. INT_MAX means no limit).
  16. *
  17. * This returns a non-negative id number, or -1 if all are taken.
  18. */
  19. int idtree_add(struct idtree *idtree, const void *ptr, int limit);
  20. /**
  21. * idtree_add_above - get lowest available id, starting at a given value.
  22. * @idtree: the tree to allocate from
  23. * @ptr: the non-NULL pointer to associate with the id
  24. * @starting_id: the minimum id value to consider.
  25. * @limit: the maximum id to allocate (ie. INT_MAX means no limit).
  26. *
  27. * This returns a non-negative id number, or -1 if all are taken.
  28. */
  29. int idtree_add_above(struct idtree *idtree, const void *ptr,
  30. int starting_id, int limit);
  31. /**
  32. * idtree_lookup - look up a given id
  33. * @idtree: the tree to look in
  34. * @id: the id to look up
  35. *
  36. * Returns NULL if the value is not found, otherwise the pointer value
  37. * set with the idtree_add()/idtree_add_above().
  38. */
  39. void *idtree_lookup(const struct idtree *idtree, int id);
  40. /**
  41. * idtree_remove - remove a given id.
  42. * @idtree: the tree to remove from
  43. * @id: the id to remove.
  44. *
  45. * Returns false if the id was not in the tree.
  46. */
  47. bool idtree_remove(struct idtree *idtree, int id);
  48. #endif /* CCAN_IDTREE_H */