int-map.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2023 Red Hat
  4. */
  5. #ifndef VDO_INT_MAP_H
  6. #define VDO_INT_MAP_H
  7. #include <linux/compiler.h>
  8. #include <linux/types.h>
  9. /**
  10. * DOC: int_map
  11. *
  12. * An int_map associates pointers (void *) with integer keys (u64). NULL pointer values are
  13. * not supported.
  14. *
  15. * The map is implemented as hash table, which should provide constant-time insert, query, and
  16. * remove operations, although the insert may occasionally grow the table, which is linear in the
  17. * number of entries in the map. The table will grow as needed to hold new entries, but will not
  18. * shrink as entries are removed.
  19. */
  20. struct int_map;
  21. int __must_check vdo_int_map_create(size_t initial_capacity, struct int_map **map_ptr);
  22. void vdo_int_map_free(struct int_map *map);
  23. size_t vdo_int_map_size(const struct int_map *map);
  24. void *vdo_int_map_get(struct int_map *map, u64 key);
  25. int __must_check vdo_int_map_put(struct int_map *map, u64 key, void *new_value,
  26. bool update, void **old_value_ptr);
  27. void *vdo_int_map_remove(struct int_map *map, u64 key);
  28. #endif /* VDO_INT_MAP_H */