/
usr
/
src
/
file_protector-1.1-1506
/
transport
/
File Upload :
llllll
Current File: //usr/src/file_protector-1.1-1506/transport/set.h
/** @file @brief 'set' @details Copyright (c) 2021 Acronis International GmbH @author Mikhail Krivtsov (mikhail.krivtsov@acronis.com) @since $Id: $ */ #pragma once #include <linux/types.h> // bool, [u]int(8|16|32|64)_t, pid_t, size_t typedef struct { void *buffer; size_t item_size; unsigned capacity; unsigned count; unsigned count_max; } set_t; static inline void set_init(set_t *set, void *buffer, size_t buffer_size, size_t item_size) { set->buffer = buffer; set->item_size = item_size; set->capacity = buffer_size / item_size; set->count = 0; set->count_max = 0; } static inline void *set_buffer(set_t *set) { return set->buffer; } static inline unsigned set_capacity(set_t *set) { return set->capacity; } static inline void *set_ptr_next(set_t *set, void *item_ptr) { return (void *) ((char *)item_ptr + set->item_size); } static inline void *set_item_ptr(set_t *set, unsigned item_index) { return (void *) (item_index * set->item_size + (char *)set->buffer); } static inline void *set_begin_ptr(set_t *set) { return set_item_ptr(set, 0); } static inline void *set_end_ptr(set_t *set) { return set_item_ptr(set, set->count); } static inline unsigned set_items_count(set_t *set) { return set->count; } static inline void set_items_count_set(set_t *set, unsigned count) { set->count = count; if (set->count_max < count) { set->count_max = count; } } static inline unsigned set_items_count_dec(set_t *set) { return --set->count; } static inline unsigned set_items_count_inc(set_t *set) { unsigned count = ++set->count; if (set->count_max < count) { set->count_max = count; } return count; } static inline unsigned set_items_count_max(set_t *set) { return set->count_max; } static inline bool set_is_empty(set_t *set) { return !set_items_count(set); } static inline bool set_is_full(set_t *set) { return set_items_count(set) >= set->capacity; }
Copyright ©2k19 -
Hexid
|
Tex7ure