| arbtree.h | | arbtree.h | |
| #ifndef _LIBHX_ARBTREE_H | | #ifndef _LIBHX_ARBTREE_H | |
| #define _LIBHX_ARBTREE_H 1 | | #define _LIBHX_ARBTREE_H 1 | |
| | | | |
|
| | | #include <sys/types.h> | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| extern "C" { | | extern "C" { | |
| #endif | | #endif | |
| | | | |
| enum { | | enum { | |
| /* activates key=>value pairs */ | | /* activates key=>value pairs */ | |
| HXBT_MAP = 1 << 0, | | HXBT_MAP = 1 << 0, | |
|
| /* copy key (only for string keys!) */ | | /* copy key */ | |
| HXBT_CKEY = 1 << 1, | | HXBT_CKEY = 1 << 1, | |
|
| /* copy data (only for string data!) */ | | /* copy data */ | |
| HXBT_CDATA = 1 << 2, | | HXBT_CDATA = 1 << 2, | |
|
| /* pointer to comparison routine passed */ | | /* HXbtree_init only: pointer to comparison routine passed */ | |
| HXBT_CMPFN = 1 << 3, | | HXBT_CMPFN = 1 << 3, | |
|
| /* use direct integer comparison */ | | /* HXbtree_init only: use direct integer comparison */ | |
| HXBT_ICMP = 1 << 4, | | HXBT_ICMP = 1 << 4, | |
|
| /* use strcmp() -- abbreviation for HXBT_CMPFN,strcmp */ | | /* HXbtree_init only: | |
| | | * use strcmp() -- abbreviation for HXBT_CMPFN,strcmp */ | |
| HXBT_SCMP = 1 << 5, | | HXBT_SCMP = 1 << 5, | |
|
| HXBT_SKEY = 1 << 5, /* init2 */ | | /* HXbtree_init2 only: keys are strings */ | |
| /* use CIDs for traverser */ | | HXBT_SKEY = 1 << 5, | |
| | | /* Copy key during traversal to ease pickup */ | |
| HXBT_CID = 1 << 6, | | HXBT_CID = 1 << 6, | |
|
| HXBT_SDATA = 1 << 7, /* init2 */ | | /* HXbtree_init2 only: data are strings */ | |
| | | HXBT_SDATA = 1 << 7, | |
| }; | | }; | |
| | | | |
| struct HXbtree_node { | | struct HXbtree_node { | |
| struct HXbtree_node *sub[2]; | | struct HXbtree_node *sub[2]; | |
| union { | | union { | |
| void *key; | | void *key; | |
| const char *const skey; | | const char *const skey; | |
| }; | | }; | |
| union { | | union { | |
| void *data; | | void *data; | |
| | | | |
End of changes. 8 change blocks. |
| 8 lines changed or deleted | | 13 lines changed or added | |
|
| defs.h | | defs.h | |
| #ifndef _LIBHX_DEFS_H | | #ifndef _LIBHX_DEFS_H | |
| #define _LIBHX_DEFS_H 1 | | #define _LIBHX_DEFS_H 1 | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| # if defined(__GNUC__) && __GNUC__ >= 4 && !defined(offsetof) | | # if defined(__GNUC__) && __GNUC__ >= 4 && !defined(offsetof) | |
|
| | | /* | |
| | | * This is here so most programs can skip inclusion | |
| | | * of stddef.h just to get offsetof. | |
| | | */ | |
| # define offsetof(type, member) __builtin_offsetof(type, membe
r) | | # define offsetof(type, member) __builtin_offsetof(type, membe
r) | |
| # endif | | # endif | |
| # ifndef offsetof | | # ifndef offsetof | |
| # define offsetof(type, member) \ | | # define offsetof(type, member) \ | |
| reinterpret_cast<long>(&(static_cast<type *>(NULL)->
member)) | | reinterpret_cast<long>(&(static_cast<type *>(NULL)->
member)) | |
| # endif | | # endif | |
| # ifndef containerof | | # ifndef containerof | |
| # define containerof(var, type, member) reinterpret_cast<type
*>( \ | | # define containerof(var, type, member) reinterpret_cast<type
*>( \ | |
| reinterpret_cast<char *>(var) - offsetof(type, membe
r)) | | reinterpret_cast<char *>(var) - offsetof(type, membe
r)) | |
| # endif | | # endif | |
| | | | |
End of changes. 1 change blocks. |
| 0 lines changed or deleted | | 4 lines changed or added | |
|
| list.h | | list.h | |
| #ifndef _LIBHX_LIST_H | | #ifndef _LIBHX_LIST_H | |
| #define _LIBHX_LIST_H 1 | | #define _LIBHX_LIST_H 1 | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| # include <cstddef> | | # include <cstddef> | |
| #else | | #else | |
| # include <stddef.h> | | # include <stddef.h> | |
| #endif | | #endif | |
|
| | | #include <libHX/defs.h> | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| extern "C" { | | extern "C" { | |
| #endif | | #endif | |
| | | | |
|
| #ifndef container_of | | #define HXlist_entry(ptr, type, member) containerof((ptr), type, member) | |
| # define container_of(ptr, type, member) ({ \ | | | |
| const typeof(((type *)0)->member) *__mptr = (ptr); \ | | | |
| (type *)((char *)__mptr - offsetof(type, member)); \ | | | |
| }) | | | |
| #endif | | | |
| #define HXlist_entry(ptr, type, member) container_of((ptr), type, member) | | | |
| | | | |
| struct HXlist_head { | | struct HXlist_head { | |
| struct HXlist_head *next, *prev; | | struct HXlist_head *next, *prev; | |
| }; | | }; | |
| | | | |
| #define HXLIST_HEAD_INIT(name) {&(name), &(name)} | | #define HXLIST_HEAD_INIT(name) {&(name), &(name)} | |
| #define HXLIST_HEAD(name) \ | | #define HXLIST_HEAD(name) \ | |
| struct HXlist_head name = HXLIST_HEAD_INIT(name) | | struct HXlist_head name = HXLIST_HEAD_INIT(name) | |
| | | | |
| static inline void HXlist_init(struct HXlist_head *list) | | static inline void HXlist_init(struct HXlist_head *list) | |
| | | | |
End of changes. 2 change blocks. |
| 7 lines changed or deleted | | 2 lines changed or added | |
|