示例#1
0
static 
AvlNode* avl_dopy ( AvlNode* nd, 
                    UWord(*dopyK)(UWord), 
                    UWord(*dopyV)(UWord),
                    void*(alloc_nofail)(const HChar*,SizeT),
                    const HChar* cc )
{
   AvlNode* nyu;
   if (! nd)
      return NULL;
   nyu = alloc_nofail(cc, sizeof(AvlNode));
   tl_assert(nyu);
   
   nyu->child[0] = nd->child[0];
   nyu->child[1] = nd->child[1];
   nyu->balance = nd->balance;

   /* Copy key */
   if (dopyK) {
      nyu->key = dopyK( nd->key );
      if (nd->key != 0 && nyu->key == 0)
         return NULL; /* oom in key dcopy */
   } else {
      /* copying assumedly unboxed keys */
      nyu->key = nd->key;
   }

   /* Copy val */
   if (dopyV) {
      nyu->val = dopyV( nd->val );
      if (nd->val != 0 && nyu->val == 0)
         return NULL; /* oom in val dcopy */
   } else {
      /* copying assumedly unboxed vals */
      nyu->val = nd->val;
   }

   /* Copy subtrees */
   if (nyu->child[0]) {
      nyu->child[0] = avl_dopy( nyu->child[0], dopyK, dopyV, 
                                alloc_nofail, cc );
      if (! nyu->child[0])
         return NULL;
   }
   if (nyu->child[1]) {
      nyu->child[1] = avl_dopy( nyu->child[1], dopyK, dopyV,
                                alloc_nofail, cc );
      if (! nyu->child[1])
         return NULL;
   }

   return nyu;
}
示例#2
0
static
AvlNode* avl_dopy ( AvlNode* nd,
                    Word(*dopyK)(Word),
                    Word(*dopyV)(Word),
                    void*(alloc_nofail)(SizeT) )
{
    AvlNode* nyu;
    if (! nd)
        return NULL;
    nyu = alloc_nofail(sizeof(AvlNode));
    assert(nyu);

    nyu->left = nd->left;
    nyu->right = nd->right;
    nyu->balance = nd->balance;

    /* Copy key */
    if (dopyK) {
        nyu->key = dopyK( nd->key );
        if (nd->key != 0 && nyu->key == 0)
            return NULL; /* oom in key dcopy */
    } else {
        /* copying assumedly unboxed keys */
        nyu->key = nd->key;
    }

    /* Copy val */
    if (dopyV) {
        nyu->val = dopyV( nd->val );
        if (nd->val != 0 && nyu->val == 0)
            return NULL; /* oom in val dcopy */
    } else {
        /* copying assumedly unboxed vals */
        nyu->val = nd->val;
    }

    /* Copy subtrees */
    if (nyu->left) {
        nyu->left = avl_dopy( nyu->left, dopyK, dopyV, alloc_nofail );
        if (! nyu->left)
            return NULL;
    }
    if (nyu->right) {
        nyu->right = avl_dopy( nyu->right, dopyK, dopyV, alloc_nofail );
        if (! nyu->right)
            return NULL;
    }

    return nyu;
}
示例#3
0
WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
{
   WordFM* nyu; 

   /* can't clone the fm whilst iterating on it */
   tl_assert(fm->stackTop == 0);

   nyu = fm->alloc_nofail( fm->cc, sizeof(WordFM) );
   tl_assert(nyu);

   *nyu = *fm;

   fm->stackTop = 0;
   VG_(memset)(fm->nodeStack, 0, sizeof(fm->nodeStack));
   VG_(memset)(fm->numStack, 0,  sizeof(fm->numStack));

   if (nyu->root) {
      nyu->root = avl_dopy( nyu->root, dopyK, dopyV,
                            fm->alloc_nofail, fm->cc );
      if (! nyu->root)
         return NULL;
   }

   return nyu;
}
示例#4
0
WordFM* dopyFM ( WordFM* fm, Word(*dopyK)(Word), Word(*dopyV)(Word) )
{
    WordFM* nyu;

    /* can't clone the fm whilst iterating on it */
    assert(fm->stackTop == 0);

    nyu = fm->alloc_nofail( sizeof(WordFM) );
    assert(nyu);

    *nyu = *fm;

    fm->stackTop = 0;
    memset(fm->nodeStack, 0, sizeof(fm->nodeStack));
    memset(fm->numStack, 0,  sizeof(fm->numStack));

    if (nyu->root) {
        nyu->root = avl_dopy( nyu->root, dopyK, dopyV, fm->alloc_nofail );
        if (! nyu->root)
            return NULL;
    }

    return nyu;
}