usnic_uiom_interval_tree.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. *
  17. */
  18. #ifndef USNIC_UIOM_INTERVAL_TREE_H_
  19. #define USNIC_UIOM_INTERVAL_TREE_H_
  20. #include <linux/rbtree.h>
  21. struct usnic_uiom_interval_node {
  22. struct rb_node rb;
  23. struct list_head link;
  24. unsigned long start;
  25. unsigned long last;
  26. unsigned long __subtree_last;
  27. unsigned int ref_cnt;
  28. int flags;
  29. };
  30. extern void
  31. usnic_uiom_interval_tree_insert(struct usnic_uiom_interval_node *node,
  32. struct rb_root *root);
  33. extern void
  34. usnic_uiom_interval_tree_remove(struct usnic_uiom_interval_node *node,
  35. struct rb_root *root);
  36. extern struct usnic_uiom_interval_node *
  37. usnic_uiom_interval_tree_iter_first(struct rb_root *root,
  38. unsigned long start,
  39. unsigned long last);
  40. extern struct usnic_uiom_interval_node *
  41. usnic_uiom_interval_tree_iter_next(struct usnic_uiom_interval_node *node,
  42. unsigned long start, unsigned long last);
  43. /*
  44. * Inserts {start...last} into {root}. If there are overlaps,
  45. * nodes will be broken up and merged
  46. */
  47. int usnic_uiom_insert_interval(struct rb_root *root,
  48. unsigned long start, unsigned long last,
  49. int flags);
  50. /*
  51. * Removed {start...last} from {root}. The nodes removed are returned in
  52. * 'removed.' The caller is responsibile for freeing memory of nodes in
  53. * 'removed.'
  54. */
  55. void usnic_uiom_remove_interval(struct rb_root *root,
  56. unsigned long start, unsigned long last,
  57. struct list_head *removed);
  58. /*
  59. * Returns {start...last} - {root} (relative complement of {start...last} in
  60. * {root}) in diff_set sorted ascendingly
  61. */
  62. int usnic_uiom_get_intervals_diff(unsigned long start,
  63. unsigned long last, int flags,
  64. int flag_mask,
  65. struct rb_root *root,
  66. struct list_head *diff_set);
  67. /* Call this to free diff_set returned by usnic_uiom_get_intervals_diff */
  68. void usnic_uiom_put_interval_set(struct list_head *intervals);
  69. #endif /* USNIC_UIOM_INTERVAL_TREE_H_ */