Alien-Judy

 view release on metacpan or  search on metacpan

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

    0,
    cJU_JPBRANCH_U2,
    cJU_JPBRANCH_U3,
#ifdef JU_64BIT
    cJU_JPBRANCH_U4,
    cJU_JPBRANCH_U5,
    cJU_JPBRANCH_U6,
    cJU_JPBRANCH_U7,
#endif
    cJU_JPBRANCH_U,
};

// Subexpanse masks are similer to JU_DCDMASK() but without the need to clear
// the first digits bits.  Avoid doing variable shifts by precomputing a
// lookup array.

static Word_t subexp_mask[] = {
    0,
    ~cJU_POP0MASK(1),
    ~cJU_POP0MASK(2),
    ~cJU_POP0MASK(3),
#ifdef JU_64BIT
    ~cJU_POP0MASK(4),
    ~cJU_POP0MASK(5),
    ~cJU_POP0MASK(6),
    ~cJU_POP0MASK(7),
#endif
};


// FUNCTION PROTOTYPES:

static bool_t j__udyInsArray(Pjp_t PjpParent, int Level, PWord_t PPop1,
                             PWord_t PIndex,
#ifdef JUDYL
                             Pjv_t   PValue,
#endif
                             Pjpm_t  Pjpm);


// ****************************************************************************
// J U D Y   1   S E T   A R R A Y
// J U D Y   L   I N S   A R R A Y
//
// Main entry point.  See the manual entry for external overview.
//
// TBD:  Until thats written, note that the function returns 1 for success or
// JERRI for serious error, including insufficient memory to build whole array;
// use Judy*Count() to see how many were stored, the first N of the total
// Count.  Also, since it takes Count == Pop1, it cannot handle a full array.
// Also, "sorted" means ascending without duplicates, otherwise you get the
// "unsorted" error.
//
// The purpose of these functions is to allow rapid construction of a large
// Judy array given a sorted list of indexes (and for JudyL, corresponding
// values).  At least one customer saw this as useful, and probably it would
// also be useful as a sufficient workaround for fast(er) unload/reload to/from
// disk.
//
// This code is written recursively for simplicity, until/unless someone
// decides to make it faster and more complex.  Hopefully recursion is fast
// enough simply because the function is so much faster than a series of
// Set/Ins calls.

#ifdef JUDY1
FUNCTION int Judy1SetArray
#else
FUNCTION int JudyLInsArray
#endif
        (
        PPvoid_t  PPArray,      // in which to insert, initially empty.
        Word_t    Count,        // number of indexes (and values) to insert.
const   Word_t *  const PIndex, // list of indexes to insert.
#ifdef JUDYL
const   Word_t *  const PValue, // list of corresponding values.
#endif
        PJError_t PJError       // optional, for returning error info.
        )
{
        Pjlw_t    Pjlw;         // new root-level leaf.
        Pjlw_t    Pjlwindex;    // first index in root-level leaf.
        int       offset;       // in PIndex.


// CHECK FOR NULL OR NON-NULL POINTER (error by caller):

        if (PPArray == (PPvoid_t) NULL)
        { JU_SET_ERRNO(PJError, JU_ERRNO_NULLPPARRAY);   return(JERRI); }

        if (*PPArray != (Pvoid_t) NULL)
        { JU_SET_ERRNO(PJError, JU_ERRNO_NONNULLPARRAY); return(JERRI); }

        if (PIndex == (PWord_t) NULL)
        { JU_SET_ERRNO(PJError, JU_ERRNO_NULLPINDEX);    return(JERRI); }

#ifdef JUDYL
        if (PValue == (PWord_t) NULL)
        { JU_SET_ERRNO(PJError, JU_ERRNO_NULLPVALUE);    return(JERRI); }
#endif


// HANDLE LARGE COUNT (= POP1) (typical case):
//
// Allocate and initialize a JPM, set the root pointer to point to it, and then
// build the tree underneath it.

// Common code for unusual error handling when no JPM available:

        if (Count > cJU_LEAFW_MAXPOP1)  // too big for root-level leaf.
        {
            Pjpm_t Pjpm;                        // new, to allocate.

// Allocate JPM:

            Pjpm = j__udyAllocJPM();
            JU_CHECKALLOC(Pjpm_t, Pjpm, JERRI);
            *PPArray = (Pvoid_t) Pjpm;

// Set some JPM fields:

            (Pjpm->jpm_Pop0) = Count - 1;



( run in 0.647 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )