Alien-Judy

 view release on metacpan or  search on metacpan

src/judy-1.0.5/src/JudyCommon/JudyIns.c  view on Meta::CPAN

// more reside starting at Pjp->jp_1Index.

#define JU_IMMSET_01_COPY(cIS,LeafType,NewJPType,Copy,CopyWord) \
        {                                                       \
            LeafType Pjll;                                      \
            Word_t   oldIndex = JU_JPDCDPOP0(Pjp);              \
                                                                \
            Index = JU_TRIMTODCDSIZE(Index);                    \
            if (oldIndex == Index) return(0);                   \
                                                                \
            Pjll = (LeafType) (Pjp->jp_1Index);                 \
            Copy(cIS,CopyWord);                                 \
            DBGCODE(JudyCheckSorted(Pjll, 2, cIS);)             \
                                                                \
            Pjp->jp_Type = (NewJPType);                         \
            return(1);                                          \
        }

#else // JUDYL

// Variations to also handle value areas; see comments above:
//
// For JudyL, Pjv (start of value area) and oldValue are also in the context;
// leave Pjv set to the value area for Index.

#define JU_IMMSET_01_COPY_EVEN(cIS,CopyWord)    \
        if (oldIndex < Index)                   \
        {                                       \
            Pjll[0] = oldIndex;                 \
            Pjv [0] = oldValue;                 \
            Pjll[1] = Index;                    \
            ++Pjv;                              \
        }                                       \
        else                                    \
        {                                       \
            Pjll[0] = Index;                    \
            Pjll[1] = oldIndex;                 \
            Pjv [1] = oldValue;                 \
        }

#define JU_IMMSET_01_COPY_ODD(cIS,CopyWord)     \
        if (oldIndex < Index)                   \
        {                                       \
            CopyWord(Pjll + 0,     oldIndex);   \
            CopyWord(Pjll + (cIS), Index);      \
            Pjv[0] = oldValue;                  \
            ++Pjv;                              \
        }                                       \
        else                                    \
        {                                       \
            CopyWord(Pjll + 0,    Index);       \
            CopyWord(Pjll + (cIS), oldIndex);   \
            Pjv[1] = oldValue;                  \
        }

// The old value area is in the first word (*Pjp), and Pjv and Pjpm are also in
// the context.  Also, unlike Judy1, indexes remain in word 2 (jp_LIndex),
// meaning insert-in-place rather than copy.
//
// Return jpm_PValue pointing to Indexs value area.  If Index is new, allocate
// a 2-value-leaf and attach it to the JP.

#define JU_IMMSET_01_COPY(cIS,LeafType,NewJPType,Copy,CopyWord) \
        {                                                       \
            LeafType Pjll;                                      \
            Word_t   oldIndex = JU_JPDCDPOP0(Pjp);              \
            Word_t   oldValue;                                  \
            Pjv_t    PjvRaw;                                    \
            Pjv_t    Pjv;                                       \
                                                                \
            Index = JU_TRIMTODCDSIZE(Index);                    \
                                                                \
            if (oldIndex == Index)                              \
            {                                                   \
                Pjpm->jpm_PValue = (Pjv_t) Pjp;                 \
                return(0);                                      \
            }                                                   \
                                                                \
            if ((PjvRaw = j__udyLAllocJV(2, Pjpm)) == (Pjv_t) NULL) \
                return(-1);                                     \
            Pjv = P_JV(PjvRaw);                                 \
                                                                \
            oldValue       = Pjp->jp_Addr;                      \
            (Pjp->jp_Addr) = (Word_t) PjvRaw;                   \
            Pjll           = (LeafType) (Pjp->jp_LIndex);       \
                                                                \
            Copy(cIS,CopyWord);                                 \
            DBGCODE(JudyCheckSorted(Pjll, 2, cIS);)             \
                                                                \
            Pjp->jp_Type   = (NewJPType);                       \
            *Pjv             = 0;                               \
            Pjpm->jpm_PValue = Pjv;                             \
            return(1);                                          \
        }

// The following is a unique mix of JU_IMMSET_01() and JU_IMMSETCASCADE() for
// going from cJU_JPIMMED_*_01 directly to a cJU_JPLEAF* for JudyL:
//
// If Index is not already set, allocate a leaf, copy the old and new indexes
// into it, clear and return the new value area, and modify the current JP.
// Note that jp_DcdPop is set to a pop0 of 0 for now, and incremented later.


#define JU_IMMSET_01_CASCADE(cIS,LeafType,NewJPType,ValueArea,  \
                             Copy,CopyWord,Alloc)               \
        {                                                       \
            Word_t   D_P0;                                      \
            LeafType PjllRaw;                                   \
            LeafType Pjll;                                      \
            Word_t   oldIndex = JU_JPDCDPOP0(Pjp);              \
            Word_t   oldValue;                                  \
            Pjv_t    Pjv;                                       \
                                                                \
            Index = JU_TRIMTODCDSIZE(Index);                    \
                                                                \
            if (oldIndex == Index)                              \
            {                                                   \
                Pjpm->jpm_PValue = (Pjv_t) (&(Pjp->jp_Addr));   \
                return(0);                                      \
            }                                                   \
                                                                \



( run in 0.508 second using v1.01-cache-2.11-cpan-e1769b4cff6 )