2019-07-28 10:31:56 +08:00
|
|
|
|
#ifndef ACL_BITS_MAP_INCLUDE_H
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#define ACL_BITS_MAP_INCLUDE_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "acl_define.h"
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* λӳ<EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
typedef struct ACL_BITS_MASK {
|
|
|
|
|
char *data; /**< bit mask */
|
|
|
|
|
size_t data_len; /**< data byte count */
|
|
|
|
|
} ACL_BITS_MASK;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bits per byte, byte in vector, bit offset in byte, bytes perset
|
|
|
|
|
*/
|
|
|
|
|
#define ACL_BITS_MASK_NBBY (8)
|
|
|
|
|
#define ACL_BITS_MASK_FD_BYTE(number, mask) \
|
|
|
|
|
(((unsigned char *) (mask)->data)[(number) / ACL_BITS_MASK_NBBY])
|
|
|
|
|
#define ACL_BITS_MASK_FD_BIT(number) (1 << ((number) % ACL_BITS_MASK_NBBY))
|
|
|
|
|
#define ACL_BITS_MASK_BYTES_NEEDED(len) \
|
|
|
|
|
(size_t) (((acl_int64) (len) + (ACL_BITS_MASK_NBBY - 1)) / ACL_BITS_MASK_NBBY)
|
|
|
|
|
#define ACL_BITS_MASK_BYTE_COUNT(mask) ((mask)->data_len)
|
|
|
|
|
|
|
|
|
|
/* Memory management. */
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>
|
|
|
|
|
* @param mask {ACL_BITS_MASK*) ACL_BITS_MASK ָ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param nmax {size_t/unsigned int/unsigned short/unsigned char} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ֵ<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> (mask)->data ռ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD>磺<EFBFBD><EFBFBD> nmax=4294967295, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* (mask)->data_len=536870912, <EFBFBD><EFBFBD> (mask)->data ռ<EFBFBD><EFBFBD> 536870912 Bytes; <EFBFBD><EFBFBD> nmax=65535,
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> unsigned short ֵʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (mask)->data_len=8192, <EFBFBD><EFBFBD> (mask)->data ռ<EFBFBD><EFBFBD> 8192 <EFBFBD>ֽ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
#define ACL_BITS_MASK_ALLOC(mask, nmax) do { \
|
|
|
|
|
size_t _byte_len = ACL_BITS_MASK_BYTES_NEEDED(nmax); \
|
|
|
|
|
(mask)->data = (char*) acl_mymalloc(_byte_len); \
|
|
|
|
|
memset((mask)->data, 0, _byte_len); \
|
|
|
|
|
(mask)->data_len = _byte_len; \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>
|
|
|
|
|
* @param mask {ACL_BITS_MASK*) ACL_BITS_MASK ָ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param nmax {size_t/unsigned int/unsigned short/unsigned char} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ֵ<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> (mask)->data ռ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD>磺<EFBFBD><EFBFBD> nmax=4294967295, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* (mask)->data_len=536870912, <EFBFBD><EFBFBD> (mask)->data ռ<EFBFBD><EFBFBD> 536870912 Bytes; <EFBFBD><EFBFBD> nmax=65535,
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> unsigned short ֵʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (mask)->data_len=8192, <EFBFBD><EFBFBD> (mask)->data ռ<EFBFBD><EFBFBD> 8192 <EFBFBD>ֽ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
#define ACL_BITS_MASK_REALLOC(mask, nmax) do { \
|
|
|
|
|
size_t _byte_len = ACL_BITS_MASK_BYTES_NEEDED(nmax); \
|
|
|
|
|
size_t _old_len = (mask)->data_len; \
|
|
|
|
|
(mask)->data = (char*) acl_myrealloc((mask)->data, _byte_len); \
|
|
|
|
|
memset((mask)->data + _old_len, 0, _byte_len - _old_len); \
|
|
|
|
|
(mask)->data_len = _byte_len; \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>ͷ<EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD>ռ<EFBFBD>
|
|
|
|
|
* @param mask {ACL_BITS_MASK*) ACL_BITS_MASK ָ<EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
#define ACL_BITS_MASK_FREE(mask) acl_myfree((mask)->data)
|
|
|
|
|
|
|
|
|
|
/* Set operations, modeled after FD_ZERO/SET/ISSET/CLR. */
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param mask {ACL_BITS_MASK*) ACL_BITS_MASK ָ<EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
#define ACL_BITS_MASK_ZERO(mask) \
|
|
|
|
|
memset((mask)->data, 0, (mask)->data_len);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD>Ϊλ<EFBFBD>洢<EFBFBD><EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>̬<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param number {unsigned int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @param mask {ACL_BITS_MASK*) ACL_BITS_MASK ָ<EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
#define ACL_BITS_MASK_SET(number, mask) \
|
|
|
|
|
(ACL_BITS_MASK_FD_BYTE((number), (mask)) |= ACL_BITS_MASK_FD_BIT(number))
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>ж<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>洢<EFBFBD><EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>̬<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param number {unsigned int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @param mask {ACL_BITS_MASK*) ACL_BITS_MASK ָ<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {int} 0: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>!= 0: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
#define ACL_BITS_MASK_ISSET(number, mask) \
|
|
|
|
|
(ACL_BITS_MASK_FD_BYTE((number), (mask)) & ACL_BITS_MASK_FD_BIT(number))
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>̬<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param number {unsigned int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @param mask {ACL_BITS_MASK*) ACL_BITS_MASK ָ<EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
#define ACL_BITS_MASK_CLR(number, mask) \
|
|
|
|
|
(ACL_BITS_MASK_FD_BYTE((number), (mask)) &= ~ACL_BITS_MASK_FD_BIT(number))
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|