#ifndef _LSUP_CORE_H #define _LSUP_CORE_H #include #include #include #include #include #include #ifdef DEBUG #define DEBUG_TEST 1 #else #define DEBUG_TEST 0 #endif #define STR "%s\n" #define TRACE(fmt, ...) \ do {\ if (DEBUG_TEST) \ fprintf(stderr, "%s:%d:%s(): " fmt "\n", \ __FILE__, __LINE__, __func__, __VA_ARGS__); \ } while (0) #define LIKELY(x) __builtin_expect(!!(x), true) #define UNLIKELY(x) __builtin_expect(!!(x), false) // TODO Handle memory errors better. #define CRITICAL(exp) if (UNLIKELY(((exp) == NULL))) { abort(); } // NOTE This may change in the future, e.g. if a different key size is to // be forced. typedef size_t LSUP_Key; typedef LSUP_Key LSUP_DoubleKey[2]; typedef LSUP_Key LSUP_TripleKey[3]; typedef LSUP_Key LSUP_QuadKey[4]; // "NULL" key, a value that is never user-provided. Used to mark special // values (e.g. deleted records). #define NULL_KEY 0 // Value of first key inserted in an empty term database. #define FIRST_KEY 1 // "NULL" triple, a value that is never user-provided. Used to fill deleted // triples in a keyset. extern LSUP_TripleKey NULL_TRP; // Don't use MIN and MAX macros: see // https://dustri.org/b/min-and-max-macro-considered-harmful.html inline int min(int x, int y) { return x < y ? x : y; } inline int max(int x, int y) { return x > y ? x : y; } #endif