Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/src/JudySL/JudySL.c view on Meta::CPAN
}
#else // JU_32BIT
// copy from 1..4 bytes from string to Word_t and test if \0 bytes
#define COPYSTRINGtoWORD(WORD,STR) \
{ \
do \
{ \
uint8_t chr; \
WORD = (STR)[0] << 24; \
if (WORD == 0) break; \
if (!(chr = (STR)[1])) break; \
WORD += (Word_t)(chr << 16); \
if (!(chr = (STR)[2])) break; \
WORD += (Word_t)(chr << 8) + (STR)[3]; \
} while(0); \
}
// copy Word_t from 1..4 bytes to string and test of \0 bytes
#define COPYWORDtoSTRING(STR,WORD) \
{ \
do \
{ \
if (!((STR)[0] = (uint8_t)((WORD) >> 24))) break; \
if (!((STR)[1] = (uint8_t)((WORD) >> 16))) break; \
if (!((STR)[2] = (uint8_t)((WORD) >> 8))) break; \
(STR)[3] = (uint8_t)(WORD); \
} while(0); \
}
#endif // JU_32BIT
// SUPPORT FOR SINGLE-INDEX SHORTCUT LEAVES:
typedef struct SHORCUTLEAF
{
Pvoid_t scl_Pvalue; // callers value area.
uint8_t scl_Index[WORDSIZE]; // base Index string.
} scl_t , *Pscl_t;
// overhead of the scl_Pvalue only, the scl_Index is calculate elsewhere
#define STRUCTOVD (sizeof(scl_t) - WORDSIZE)
// How big to malloc a shortcut leaf; stringlen should already include the
// trailing null char:
#define SCLSIZE(LEN) (((LEN) + STRUCTOVD + WORDSIZE - 1) / WORDSIZE)
// string routines, may replace with your own
//
#define STRCMP(S1,S2) strcmp((void *)(S1), (void *)(S2))
#define STRCPY(S1,S2) strcpy((void *)(S1), (void *)(S2))
#define STRLEN(S1) (strlen((void *)(S1)) + 1)
// Index and value area for a shortcut leaf, depending on how it matches the
// undecoded remainder of the Index, given a Pscl_t that includes type bits
// that must be cleared:
//
// PSCLINDEX() and PSCLVALUE() are also useful when Pscl contains uncleared
// TYPE bits.
//
// Note: SCLCMP() cannot take advantage of knowing the Index length because
// the scl_Index length is not pre-known when these macros are used.
#define PSCLINDEX(PSCL) ((CLEAR_PSCL(PSCL))->scl_Index)
#define PSCLVALUE(PSCL) ((CLEAR_PSCL(PSCL))->scl_Pvalue)
#define SCLCMP(INDEX,PSCL) STRCMP(INDEX, PSCLINDEX(PSCL))
#define PPSCLVALUE_EQ(INDEX,PSCL) \
((SCLCMP(INDEX, PSCL) == 0) ? &PSCLVALUE(PSCL) : (PPvoid_t)NULL)
#define PPSCLVALUE_LT(INDEX,PSCL) \
((SCLCMP(INDEX, PSCL) < 0) ? &PSCLVALUE(PSCL) : (PPvoid_t)NULL)
#define PPSCLVALUE_GT(INDEX,PSCL) \
((SCLCMP(INDEX, PSCL) > 0) ? &PSCLVALUE(PSCL) : (PPvoid_t)NULL)
// Common in-lined code to append or free a shortcut leaf:
//
// See header comments about premature return(). Note that malloc() does not
// pre-zero the memory, so ensure scl_Pvalue is zeroed, just like a value area
// in a JudyL array. Hope strcpy() is fast enough in this context.
#define APPEND_SCL(PSCL,PPARRAY,INDEX,LEN,PJERROR) \
{ \
if (((PSCL) = (Pscl_t) JudyMalloc(SCLSIZE(LEN))) == (Pscl_t)NULL) \
{ \
JU_SET_ERRNO(PJERROR, JU_ERRNO_NOMEM); \
return (PPJERR); \
} \
*(PPARRAY) = (Pvoid_t)SET_PSCL(PSCL); \
((PSCL)->scl_Pvalue) = (Pvoid_t)NULL; \
(void)STRCPY((PSCL)->scl_Index, INDEX); \
}
// "FORWARD" DECLARATIONS:
static void JudySLModifyErrno(PJError_t PJError,
Pcvoid_t PArray, Pcvoid_t PArrayOrig);
static int JudySLDelSub(PPvoid_t PPArray, PPvoid_t PPArrayOrig,
const uint8_t * Index, Word_t len, PJError_t PJError);
static PPvoid_t JudySLPrevSub(Pcvoid_t PArray, uint8_t * Index, int orig,
Word_t len, PJError_t PJError);
static PPvoid_t JudySLNextSub(Pcvoid_t PArray, uint8_t * Index, int orig,
Word_t len, PJError_t PJError);
// ****************************************************************************
// J U D Y S L M O D I F Y E R R N O
//
// Common code for error translation: When a caller passes an invalid JAP
// ("not a JudyL pointer"), OR if the JudySL array is corrupted at a lower
// level, various JudyL*() calls return JU_ERRNO_NOTJUDYL. If the caller wants
// detailed error info, convert this particular error to JU_ERRNO_NOTJUDYSL if
// at the top of the tree, otherwise convert it to JU_ERRNO_CORRUPT, meaning
// there was a corruption (the only one even detectable outside JudyL) in the
( run in 0.785 second using v1.01-cache-2.11-cpan-39bf76dae61 )