Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/src/JudyCommon/JudyPrivate.h view on Meta::CPAN
#endif // A_PICTURE_IS_WORTH_1000_WORDS
// ****************************************************************************
// MISCELLANEOUS GLOBALS:
//
// PLATFORM-SPECIFIC CONVENIENCE MACROS:
//
// These are derived from context (set by cc or in system header files) or
// based on JU_<PLATFORM> macros from make_includes/platform.*.mk. We decided
// on 011018 that any macro reliably derivable from context (cc or headers) for
// ALL platforms supported by Judy is based on that derivation, but ANY
// exception means to stop using the external macro completely and derive from
// JU_<PLATFORM> instead.
// Other miscellaneous stuff:
#ifndef _BOOL_T
#define _BOOL_T
typedef int bool_t;
#endif
#define FUNCTION // null; easy to find functions.
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifdef TRACE // turn on all other tracing in the code:
#define TRACEJP 1 // JP traversals in JudyIns.c and JudyDel.c.
#define TRACEJPR 1 // JP traversals in retrieval code, JudyGet.c.
#define TRACECF 1 // cache fills in JudyGet.c.
#define TRACEMI 1 // malloc calls in JudyMallocIF.c.
#define TRACEMF 1 // malloc calls at a lower level in JudyMalloc.c.
#endif
// SUPPORT FOR DEBUG-ONLY CODE:
//
// By convention, use -DDEBUG to enable both debug-only code AND assertions in
// the Judy sources.
//
// Invert the sense of assertions, so they are off unless explicitly requested,
// in a uniform way.
//
// Note: It is NOT appropriate to put this in Judy.h; it would mess up
// application code.
#ifndef DEBUG
#define NDEBUG 1 // must be 1 for "#if".
#endif
// Shorthand notations to avoid #ifdefs for single-line conditional statements:
//
// Warning: These cannot be used around compiler directives, such as
// "#include", nor in the case where Code contains a comma other than nested
// within parentheses or quotes.
#ifndef DEBUG
#define DBGCODE(Code) // null.
#else
#define DBGCODE(Code) Code
#endif
#ifdef JUDY1
#define JUDY1CODE(Code) Code
#define JUDYLCODE(Code) // null.
#endif
#ifdef JUDYL
#define JUDYLCODE(Code) Code
#define JUDY1CODE(Code) // null.
#endif
#include <assert.h>
// ****************************************************************************
// FUNDAMENTAL CONSTANTS FOR MACHINE
// ****************************************************************************
// Machine (CPU) cache line size:
//
// NOTE: A leaf size of 2 cache lines maximum is the target (optimal) for
// Judy. Its hard to obtain a machines cache line size at compile time, but
// if the machine has an unexpected cache line size, its not devastating if
// the following constants end up causing leaves that are 1 cache line in size,
// or even 4 cache lines in size. The assumed 32-bit system has 16-word =
// 64-byte cache lines, and the assumed 64-bit system has 16-word = 128-byte
// cache lines.
#ifdef JU_64BIT
#define cJU_BYTESPERCL 128 // cache line size in bytes.
#else
#define cJU_BYTESPERCL 64 // cache line size in bytes.
#endif
// Bits Per Byte:
#define cJU_BITSPERBYTE 0x8
// Bytes Per Word and Bits Per Word, latter assuming sizeof(byte) is 8 bits:
//
// Expect 32 [64] bits per word.
#define cJU_BYTESPERWORD (sizeof(Word_t))
#define cJU_BITSPERWORD (sizeof(Word_t) * cJU_BITSPERBYTE)
#define JU_BYTESTOWORDS(BYTES) \
(((BYTES) + cJU_BYTESPERWORD - 1) / cJU_BYTESPERWORD)
// A word that is all-ones, normally equal to -1UL, but safer with ~0:
#define cJU_ALLONES (~0UL)
// Note, these are forward references, but thats OK:
#define cJU_FULLBITMAPB ((BITMAPB_t) cJU_ALLONES)
src/judy-1.0.5/src/JudyCommon/JudyPrivate.h view on Meta::CPAN
// SET (REPLACE) ONE DIGIT IN AN INDEX:
//
// To avoid endian issues, use masking and ORing, which operates in a
// big-endian register, rather than treating the Index as an array of bytes,
// though that would be simpler, but would operate in endian-specific memory.
//
// TBD: This contains two variable shifts, is that bad?
#define JU_SETDIGIT(INDEX,DIGIT,STATE) \
(INDEX) = ((INDEX) & (~cJU_MASKATSTATE(STATE))) \
| (((Word_t) (DIGIT)) \
<< (((STATE) - 1) * cJU_BITSPERBYTE))
// Fast version for single LSB:
#define JU_SETDIGIT1(INDEX,DIGIT) (INDEX) = ((INDEX) & ~0xff) | (DIGIT)
// SET (REPLACE) "N" LEAST DIGITS IN AN INDEX:
#define JU_SETDIGITS(INDEX,INDEX2,cSTATE) \
(INDEX) = ((INDEX ) & (~JU_LEASTBYTESMASK(cSTATE))) \
| ((INDEX2) & ( JU_LEASTBYTESMASK(cSTATE)))
// COPY DECODE BYTES FROM JP TO INDEX:
//
// Modify Index digit(s) to match the bytes in jp_DcdPopO in case one or more
// branches are skipped and the digits are significant. Its probably faster
// to just do this unconditionally than to check if its necessary.
//
// To avoid endian issues, use masking and ORing, which operates in a
// big-endian register, rather than treating the Index as an array of bytes,
// though that would be simpler, but would operate in endian-specific memory.
//
// WARNING: Must not call JU_LEASTBYTESMASK (via cJU_DCDMASK) with Bytes =
// cJU_ROOTSTATE or a bad mask is generated, but there are no Dcd bytes to copy
// in this case anyway. In fact there are no Dcd bytes unless State <
// cJU_ROOTSTATE - 1, so dont call this macro except in those cases.
//
// TBD: It would be nice to validate jp_DcdPopO against known digits to ensure
// no corruption, but this is non-trivial.
#define JU_SETDCD(INDEX,PJP,cSTATE) \
(INDEX) = ((INDEX) & ~cJU_DCDMASK(cSTATE)) \
| (JU_JPDCDPOP0(PJP) & cJU_DCDMASK(cSTATE))
// INSERT/DELETE AN INDEX IN-PLACE IN MEMORY:
//
// Given a pointer to an array of "even" (native), same-sized objects
// (indexes), the current population of the array, an offset in the array, and
// a new Index to insert, "shift up" the array elements (Indexes) above the
// insertion point and insert the new Index. Assume there is sufficient memory
// to do this.
//
// In these macros, "i_offset" is an index offset, and "b_off" is a byte
// offset for odd Index sizes.
//
// Note: Endian issues only arise fro insertion, not deletion, and even for
// insertion, they are transparent when native (even) objects are used, and
// handled explicitly for odd (non-native) Index sizes.
//
// Note: The following macros are tricky enough that there is some test code
// for them appended to this file.
#define JU_INSERTINPLACE(PARRAY,POP1,OFFSET,INDEX) \
assert((long) (POP1) > 0); \
assert((Word_t) (OFFSET) <= (Word_t) (POP1)); \
{ \
Word_t i_offset = (POP1); \
\
while (i_offset-- > (OFFSET)) \
(PARRAY)[i_offset + 1] = (PARRAY)[i_offset]; \
\
(PARRAY)[OFFSET] = (INDEX); \
}
// Variation for non-native Indexes, where cIS = Index Size
// and PByte must point to a uint8_t (byte); shift byte-by-byte:
//
#define JU_INSERTINPLACE3(PBYTE,POP1,OFFSET,INDEX) \
{ \
Word_t i_off = POP1; \
\
while (i_off-- > (OFFSET)) \
{ \
Word_t i_dx = i_off * 3; \
(PBYTE)[i_dx + 0 + 3] = (PBYTE)[i_dx + 0]; \
(PBYTE)[i_dx + 1 + 3] = (PBYTE)[i_dx + 1]; \
(PBYTE)[i_dx + 2 + 3] = (PBYTE)[i_dx + 2]; \
} \
JU_COPY3_LONG_TO_PINDEX(&((PBYTE)[(OFFSET) * 3]), INDEX); \
}
#ifdef JU_64BIT
#define JU_INSERTINPLACE5(PBYTE,POP1,OFFSET,INDEX) \
{ \
Word_t i_off = POP1; \
\
while (i_off-- > (OFFSET)) \
{ \
Word_t i_dx = i_off * 5; \
(PBYTE)[i_dx + 0 + 5] = (PBYTE)[i_dx + 0]; \
(PBYTE)[i_dx + 1 + 5] = (PBYTE)[i_dx + 1]; \
(PBYTE)[i_dx + 2 + 5] = (PBYTE)[i_dx + 2]; \
(PBYTE)[i_dx + 3 + 5] = (PBYTE)[i_dx + 3]; \
(PBYTE)[i_dx + 4 + 5] = (PBYTE)[i_dx + 4]; \
} \
JU_COPY5_LONG_TO_PINDEX(&((PBYTE)[(OFFSET) * 5]), INDEX); \
}
#define JU_INSERTINPLACE6(PBYTE,POP1,OFFSET,INDEX) \
{ \
Word_t i_off = POP1; \
\
while (i_off-- > (OFFSET)) \
{ \
( run in 0.769 second using v1.01-cache-2.11-cpan-2398b32b56e )