| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_UUIDMAP_H |
| 4 | #define NETDATA_UUIDMAP_H |
| 5 | |
| 6 | #include "libnetdata/libnetdata.h" |
| 7 | |
| 8 | typedef uint32_t UUIDMAP_ID; |
| 9 | |
| 10 | #define UUIDMAP_PARTITIONS 8 |
| 11 | |
| 12 | static inline uint8_t uuid_to_uuidmap_partition(const nd_uuid_t uuid) { |
| 13 | return uuid[15] & 0x07; // Mask for 8 partitions (0b111) |
| 14 | } |
| 15 | |
| 16 | static inline uint8_t uuidmap_id_to_partition(UUIDMAP_ID id) { |
| 17 | return (uint8_t)(id >> 29); // Use top 3 bits for partition |
| 18 | } |
| 19 | |
| 20 | static inline UUIDMAP_ID uuidmap_make_id(uint8_t partition, uint32_t id) { |
| 21 | return ((UUIDMAP_ID)partition << 29) | (id & 0x1FFFFFFF); // Use bottom 29 bits for sequence |
| 22 | } |
| 23 | |
| 24 | // returns ID, or zero on error |
| 25 | UUIDMAP_ID uuidmap_create(const nd_uuid_t uuid); |
| 26 | |
| 27 | // returns the number of entries still referenced (although freed) |
| 28 | size_t uuidmap_destroy(void); |
| 29 | |
| 30 | // delete a uuid from the map |
| 31 | void uuidmap_free(UUIDMAP_ID id); |
| 32 | |
| 33 | // returns true if found, false if not found |
| 34 | // UUID is copied to out_uuid if found |
| 35 | bool uuidmap_uuid(UUIDMAP_ID id, nd_uuid_t out_uuid); |
| 36 | |
| 37 | nd_uuid_t *uuidmap_uuid_ptr(UUIDMAP_ID id); |
| 38 | nd_uuid_t *uuidmap_uuid_ptr_and_dup(UUIDMAP_ID id); |
| 39 | |
| 40 | ND_UUID uuidmap_get(UUIDMAP_ID id); |
| 41 | |
| 42 | size_t uuidmap_memory(void); |
| 43 | size_t uuidmap_free_bytes(void); |
| 44 | struct aral_statistics *uuidmap_aral_statistics(void); |
| 45 | |
| 46 | UUIDMAP_ID uuidmap_dup(UUIDMAP_ID id); |
| 47 | |
| 48 | int uuidmap_unittest(void); |
| 49 | |
| 50 | #endif //NETDATA_UUIDMAP_H |