priority-table.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2023 Red Hat
  4. */
  5. #ifndef VDO_PRIORITY_TABLE_H
  6. #define VDO_PRIORITY_TABLE_H
  7. #include <linux/list.h>
  8. /*
  9. * A priority_table is a simple implementation of a priority queue for entries with priorities that
  10. * are small non-negative integer values. It implements the obvious priority queue operations of
  11. * enqueuing an entry and dequeuing an entry with the maximum priority. It also supports removing
  12. * an arbitrary entry. The priority of an entry already in the table can be changed by removing it
  13. * and re-enqueuing it with a different priority. All operations have O(1) complexity.
  14. *
  15. * The links for the table entries must be embedded in the entries themselves. Lists are used to
  16. * link entries in the table and no wrapper type is declared, so an existing list entry in an
  17. * object can also be used to queue it in a priority_table, assuming the field is not used for
  18. * anything else while so queued.
  19. *
  20. * The table is implemented as an array of queues (circular lists) indexed by priority, along with
  21. * a hint for which queues are non-empty. Steven Skiena calls a very similar structure a "bounded
  22. * height priority queue", but given the resemblance to a hash table, "priority table" seems both
  23. * shorter and more apt, if somewhat novel.
  24. */
  25. struct priority_table;
  26. int __must_check vdo_make_priority_table(unsigned int max_priority,
  27. struct priority_table **table_ptr);
  28. void vdo_free_priority_table(struct priority_table *table);
  29. void vdo_priority_table_enqueue(struct priority_table *table, unsigned int priority,
  30. struct list_head *entry);
  31. void vdo_reset_priority_table(struct priority_table *table);
  32. struct list_head * __must_check vdo_priority_table_dequeue(struct priority_table *table);
  33. void vdo_priority_table_remove(struct priority_table *table, struct list_head *entry);
  34. bool __must_check vdo_is_priority_table_empty(struct priority_table *table);
  35. #endif /* VDO_PRIORITY_TABLE_H */