예제 #1
0
/**
 * Shrink deque at end.
 */
void _deque_shrink_at_end(deque_t* pdeq_deque, size_t t_shrinksize)
{
    deque_iterator_t it_oldend;
    deque_iterator_t it_newend;
    deque_iterator_t it_iter;
    _mappointer_t    ppby_map = NULL;
    bool_t           b_result = false;

    assert(pdeq_deque != NULL);
    assert(_deque_is_inited(pdeq_deque));

    it_oldend = deque_end(pdeq_deque);
    t_shrinksize = t_shrinksize < deque_size(pdeq_deque) ? t_shrinksize : deque_size(pdeq_deque);
    it_newend = iterator_prev_n(deque_end(pdeq_deque), t_shrinksize);
    assert(_deque_iterator_belong_to_deque(pdeq_deque, it_newend));

    /* destroy all elements */
    for(it_iter = it_newend; !iterator_equal(it_iter, it_oldend); it_iter = iterator_next(it_iter))
    {
        b_result = _GET_DEQUE_TYPE_SIZE(pdeq_deque);
        _GET_DEQUE_TYPE_DESTROY_FUNCTION(pdeq_deque)(_deque_iterator_get_pointer_auxiliary(it_iter), &b_result);
        assert(b_result);
    }
    pdeq_deque->_t_finish = it_newend;

    for(ppby_map = _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish) + 1; ppby_map <= _GET_DEQUE_MAP_POINTER(it_oldend); ++ppby_map)
    {
        _alloc_deallocate(&pdeq_deque->_t_allocator, *ppby_map, _GET_DEQUE_TYPE_SIZE(pdeq_deque), _DEQUE_ELEM_COUNT);
        *ppby_map = NULL;
    }
}
예제 #2
0
파일: sort1.c 프로젝트: chenzhongtao/source
int main(int argc, char* argv[])
{
    deque_t* pdeq_coll = NULL;
    person_t t_person;

    type_register(person_t, NULL, NULL, NULL, NULL);
    pdeq_coll = create_deque(person_t);
    if(pdeq_coll == NULL)
    {
        return -1;
    }

    deque_init(pdeq_coll);

    memset(t_person.s_firstname, '\0', 21);
    memset(t_person.s_lastname, '\0', 21);
    strcpy(t_person.s_firstname, "Jonh");
    strcpy(t_person.s_lastname, "right");
    deque_push_back(pdeq_coll, &t_person);
    memset(t_person.s_firstname, '\0', 21);
    memset(t_person.s_lastname, '\0', 21);
    strcpy(t_person.s_firstname, "Bill");
    strcpy(t_person.s_lastname, "killer");
    deque_push_back(pdeq_coll, &t_person);
    memset(t_person.s_firstname, '\0', 21);
    memset(t_person.s_lastname, '\0', 21);
    strcpy(t_person.s_firstname, "Jonh");
    strcpy(t_person.s_lastname, "sound");
    deque_push_back(pdeq_coll, &t_person);
    memset(t_person.s_firstname, '\0', 21);
    memset(t_person.s_lastname, '\0', 21);
    strcpy(t_person.s_firstname, "Bin");
    strcpy(t_person.s_lastname, "lee");
    deque_push_back(pdeq_coll, &t_person);
    memset(t_person.s_firstname, '\0', 21);
    memset(t_person.s_lastname, '\0', 21);
    strcpy(t_person.s_firstname, "Lee");
    strcpy(t_person.s_lastname, "bird");
    deque_push_back(pdeq_coll, &t_person);

    algo_for_each(deque_begin(pdeq_coll), deque_end(pdeq_coll), _print);
    printf("\n");

    algo_sort_if(deque_begin(pdeq_coll), deque_end(pdeq_coll), _person_sort_criterion);

    algo_for_each(deque_begin(pdeq_coll), deque_end(pdeq_coll), _print);
    printf("\n");

    deque_destroy(pdeq_coll);

    return 0;
}
예제 #3
0
파일: qbuffer.c 프로젝트: hildeth/chapel
qioerr qbuffer_destroy(qbuffer_t* buf)
{
  qioerr err = 0;
  deque_iterator_t cur = deque_begin(& buf->deque);
  deque_iterator_t end = deque_end(& buf->deque);

  while( ! deque_it_equals(cur, end) ) {
    qbuffer_part_t* qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), cur);

    // release the qbuffer.
    qbytes_release(qbp->bytes);

    deque_it_forward_one(sizeof(qbuffer_part_t), &cur);
  }

  // remove any cached data
  qbuffer_clear_cached(buf);

  // destroy the deque
  deque_destroy(& buf->deque);

  DO_DESTROY_REFCNT(buf);

  return err;
}
예제 #4
0
void iterate_counting(size_t item_size, deque_t* d, int num)
{
  deque_iterator_t begin = deque_begin(d);
  deque_iterator_t end = deque_end(d);
  deque_iterator_t cur = begin;
  deque_iterator_t test;
  int i = 0;
  int j;
  assert(item_size == 4);
  while( i < num && ! deque_it_equals(cur, end) ) {
    // check that the value is right.
    deque_it_get_cur(item_size, cur, &j);
    assert( j == i );
    
    // check that advancing from beginning i elements takes us here.
    test = begin;
    deque_it_forward_n(item_size, &test, i);
    assert( deque_it_equals( test, cur ) );

    // advance to the next element, checking that
    // forward_one is the same as forward_n(1) 
    test = cur;
    deque_it_forward_one(item_size, &cur);
    deque_it_forward_n(item_size, &test, 1);
    assert( deque_it_equals( test, cur ) );
    i++;
  }
}
예제 #5
0
파일: qbuffer.c 프로젝트: hildeth/chapel
qbuffer_iter_t qbuffer_end(qbuffer_t* buf)
{
  qbuffer_iter_t ret;
  ret.offset = buf->offset_end;
  ret.iter = deque_end( & buf->deque );
  return ret;
}
예제 #6
0
void deque_resize_with_value(cstl_deque *cd, size_t new_size, const void *value)
{
    if (new_size > cd->_size)
    {
        deque_insert_n(cd, deque_end(cd), new_size - cd->_size, value);
    }
    else
    {
        cd->_size = new_size;
        cd->_end = cd->_begin + cd->_size*cd->_single_data_size;
    }
}
예제 #7
0
파일: qbuffer.c 프로젝트: hildeth/chapel
void qbuffer_iter_ceil_part(qbuffer_t* buf, qbuffer_iter_t* iter)
{
  deque_iterator_t d_end = deque_end( & buf->deque );

  if( deque_it_equals(iter->iter, d_end) ) {
    // We're at the end. Do nothing.
  } else {
    qbuffer_part_t* qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter->iter);
    iter->offset = qbp->end_offset;
    deque_it_forward_one(sizeof(qbuffer_part_t), & iter->iter);
  }
}
예제 #8
0
파일: qbuffer.c 프로젝트: hildeth/chapel
void qbuffer_iter_next_part(qbuffer_t* buf, qbuffer_iter_t* iter)
{
  deque_iterator_t d_end = deque_end( & buf->deque );

  deque_it_forward_one(sizeof(qbuffer_part_t), & iter->iter);

  if( deque_it_equals(iter->iter, d_end) ) {
    // if we're not at the end now... offset is from buf
    iter->offset = buf->offset_end;
  } else {
    qbuffer_part_t* qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter->iter);
    iter->offset = qbp->end_offset - qbp->len_bytes;
  }
}
예제 #9
0
/**
 * Get the pointer that point to the iterator reference data.
 */
const void* _deque_iterator_get_pointer(deque_iterator_t it_iter)
{
    assert(_deque_iterator_belong_to_deque(_DEQUE_ITERATOR_CONTAINER(it_iter), it_iter));
    assert(!iterator_equal(it_iter, deque_end(_DEQUE_ITERATOR_CONTAINER(it_iter))));

    /* char* */
    if(strncmp(_GET_DEQUE_TYPE_BASENAME(_DEQUE_ITERATOR_CONTAINER(it_iter)), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0)
    {
        return string_c_str((string_t*)_deque_iterator_get_pointer_auxiliary(it_iter));
    }
    else
    {
        return _deque_iterator_get_pointer_auxiliary(it_iter);
    }
}
예제 #10
0
void print_deque(size_t item_size, deque_t* d)
{
  deque_iterator_t cur = deque_begin(d);
  deque_iterator_t end = deque_end(d);
  int j;
  assert(item_size == 4);
  printf("deque %p: ", d);
  while( ! deque_it_equals(cur, end) ) {
    j = 0;
    deque_it_get_cur(item_size, cur, &j);
    printf(" %i", j);
    deque_it_forward_one(item_size, &cur);
  }
  printf("\n");
}
예제 #11
0
파일: qbuffer.c 프로젝트: hildeth/chapel
/* Advances an iterator using linear search. 
 */
void qbuffer_iter_advance(qbuffer_t* buf, qbuffer_iter_t* iter, int64_t amt)
{
  deque_iterator_t d_begin = deque_begin( & buf->deque );
  deque_iterator_t d_end = deque_end( & buf->deque );

  if( amt >= 0 ) {
    // forward search.
    iter->offset += amt;
    while( ! deque_it_equals(iter->iter, d_end) ) {
      qbuffer_part_t* qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter->iter);
      if( iter->offset < qbp->end_offset ) {
        // it's in this one.
        return;
      }
      deque_it_forward_one(sizeof(qbuffer_part_t), & iter->iter);
    }
    // If we get here, we didn't find it. Return the buffer end.
    *iter = qbuffer_end(buf);
  } else {
    // backward search.
    iter->offset += amt; // amt is negative

    if( ! deque_it_equals( iter->iter, d_end ) ) {
      // is it within the current buffer?
      qbuffer_part_t* qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter->iter);
      if( iter->offset >= qbp->end_offset - qbp->len_bytes ) {
        // it's in this one.
        return;
      }
    }

    // now we have a valid deque element.
    do {
      qbuffer_part_t* qbp;

      deque_it_back_one(sizeof(qbuffer_part_t), & iter->iter);

      qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter->iter);
      if( iter->offset >= qbp->end_offset - qbp->len_bytes ) {
        // it's in this one.
        return;
      }
    } while( ! deque_it_equals(iter->iter, d_begin) );
    // If we get here, we didn't find it. Return the buffer start.
    *iter = qbuffer_begin(buf);
  }
}
예제 #12
0
파일: qbuffer.c 프로젝트: hildeth/chapel
void qbuffer_reposition(qbuffer_t* buf, int64_t new_offset_start)
{
  deque_iterator_t start = deque_begin(& buf->deque);
  deque_iterator_t end = deque_end(& buf->deque);
  deque_iterator_t iter;
  qbuffer_part_t* qbp;
  int64_t diff;

  diff = new_offset_start - buf->offset_start;
  buf->offset_start += diff;
  buf->offset_end += diff;

  iter = start;

  while( ! deque_it_equals(iter, end) ) {
    qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter);
    qbp->end_offset += diff;
  }
}
예제 #13
0
파일: qbuffer.c 프로젝트: hildeth/chapel
void qbuffer_iter_floor_part(qbuffer_t* buf, qbuffer_iter_t* iter)
{
  deque_iterator_t d_start = deque_begin( & buf->deque );
  deque_iterator_t d_end = deque_end( & buf->deque );

  if( deque_it_equals(iter->iter, d_end) ) {
    if( deque_it_equals(iter->iter, d_start) ) {
      // We're at the beginning. Do nothing.
      return;
    }

    // If we're at the end, just go back one.
    deque_it_back_one(sizeof(qbuffer_part_t), & iter->iter);
  }

  {
    // Now, just set the offset appropriately.
    qbuffer_part_t* qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter->iter);
    iter->offset = qbp->end_offset - qbp->len_bytes;
  }
}
예제 #14
0
/**
 * Set iterator reference data.
 */
void _deque_iterator_set_value(deque_iterator_t it_iter, const void* cpv_value)
{
    bool_t b_result = false;

    assert(cpv_value != NULL);
    assert(_deque_iterator_belong_to_deque(_DEQUE_ITERATOR_CONTAINER(it_iter), it_iter));
    assert(!iterator_equal(it_iter, deque_end(_DEQUE_ITERATOR_CONTAINER(it_iter))));

    /* char* */
    if(strncmp(_GET_DEQUE_TYPE_BASENAME(_DEQUE_ITERATOR_CONTAINER(it_iter)), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0)
    {
        string_assign_cstr((string_t*)_deque_iterator_get_pointer_auxiliary(it_iter), (char*)cpv_value);
    }
    else
    {
        b_result = _GET_DEQUE_TYPE_SIZE(_DEQUE_ITERATOR_CONTAINER(it_iter));
        _GET_DEQUE_TYPE_COPY_FUNCTION(_DEQUE_ITERATOR_CONTAINER(it_iter))(
            _deque_iterator_get_pointer_auxiliary(it_iter), cpv_value, &b_result);
        assert(b_result);
    }
}
예제 #15
0
파일: qbuffer.c 프로젝트: hildeth/chapel
// find buffer iterator part in logarithmic time
// finds an offset in the window [offset_start,offset_end]
// (in other words, offset might not start at 0)
qbuffer_iter_t qbuffer_iter_at(qbuffer_t* buf, int64_t offset)
{
  qbuffer_iter_t ret;
  deque_iterator_t first = deque_begin(& buf->deque);
  deque_iterator_t last = deque_end(& buf->deque);
  deque_iterator_t middle;
  qbuffer_part_t* qbp;
  ssize_t num_parts = deque_it_difference(sizeof(qbuffer_part_t), last, first);
  ssize_t half;

  while( num_parts > 0 ) {
    half = num_parts >> 1;
    middle = first;

    deque_it_forward_n(sizeof(qbuffer_part_t), &middle, half);

    qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), middle);
    if( offset < qbp->end_offset ) {
      num_parts = half;
    } else {
      first = middle;
      deque_it_forward_one(sizeof(qbuffer_part_t), &first);
      num_parts = num_parts - half - 1;
    }
  }

  if( deque_it_equals(first, last) ) {
    ret = qbuffer_end(buf);
  } else {
    qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), first);
    if( offset < qbp->end_offset - qbp->len_bytes ) {
      ret = qbuffer_begin(buf);
    } else {
      ret.offset = offset;
      ret.iter = first;
    }
  }
  return ret;
}
예제 #16
0
파일: qbuffer.c 프로젝트: hildeth/chapel
void debug_print_qbuffer(qbuffer_t* buf)
{
  deque_iterator_t cur = deque_begin(& buf->deque);
  deque_iterator_t end = deque_end(& buf->deque);

  fprintf(stderr, "buf %p: offset_start=%lli offset_end=%lli deque:\n",
          buf, (long long int) buf->offset_start, (long long int) buf->offset_end);

  // Print out the deque iterators
  debug_print_deque_iter(&cur);
  debug_print_deque_iter(&end);

  while( ! deque_it_equals(cur, end) ) {
    qbuffer_part_t* qbp = (qbuffer_part_t*) deque_it_get_cur_ptr( sizeof(qbuffer_part_t), cur);
    fprintf(stderr, "part %p: bytes=%p (data %p) skip=%lli len=%lli end=%lli\n", 
            qbp, qbp->bytes, qbp->bytes->data,
            (long long int) qbp->skip_bytes,
            (long long int) qbp->len_bytes,
            (long long int) qbp->end_offset);

    deque_it_forward_one( sizeof(qbuffer_part_t), &cur );
  }
}
예제 #17
0
/**
 * Get the iterator pointer auxiliary function.
 */
void* _deque_iterator_get_pointer_auxiliary(iterator_t it_iter)
{
    _byte_t* pby_pos = NULL;

    assert(_deque_iterator_belong_to_deque(_GET_DEQUE_CONTAINER(it_iter), it_iter));
    assert(!iterator_equal(it_iter, deque_end(_GET_DEQUE_CONTAINER(it_iter))));

    if(_GET_DEQUE_COREPOS(it_iter) != _GET_DEQUE_AFTERLAST_POS(it_iter))
    {
        pby_pos = _GET_DEQUE_COREPOS(it_iter);
    }
    else
    {
        /* 
         * when the iterator is begin and the corepos equal to afterlast 
         * then get the first element in next chunk.
         */
        _mappointer_t ppby_next = _GET_DEQUE_MAP_POINTER(it_iter) + 1;
        pby_pos = *ppby_next;
    }
    assert(pby_pos != NULL);

    return pby_pos;
}
예제 #18
0
파일: qbuffer.c 프로젝트: hildeth/chapel
qioerr qbuffer_to_iov(qbuffer_t* buf, qbuffer_iter_t start, qbuffer_iter_t end, 
                     size_t max_iov, struct iovec *iov_out, 
                     qbytes_t** bytes_out /* can be NULL */,
                     size_t *iovcnt_out)
{
  deque_iterator_t d_end = deque_end(& buf->deque);
  deque_iterator_t iter;
  qbuffer_part_t* qbp;
  size_t i = 0;

  iter = start.iter;

  // invalid range!
  if( start.offset > end.offset ) {
    *iovcnt_out = 0;
    QIO_RETURN_CONSTANT_ERROR(EINVAL, "invalid range");
  }

  if( deque_it_equals(iter, d_end) ) {
    // start is actually pointing to the end of the deque. no data.
    *iovcnt_out = 0;
    return 0;
  }

  if( deque_it_equals(iter, end.iter) ) {
    // we're only pointing to a single block.
    qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter);
    if( i >= max_iov ) goto error_nospace;
    iov_out[i].iov_base = PTR_ADDBYTES(qbp->bytes->data, qbp->skip_bytes + (start.offset - (qbp->end_offset - qbp->len_bytes)));
    iov_out[i].iov_len = end.offset - start.offset;
    if( bytes_out ) bytes_out[i] = qbp->bytes;
    if( iov_out[i].iov_len > 0 ) i++;
  } else {
    // otherwise, there's a possibly partial block in start.
    qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter);
    if( i >= max_iov ) goto error_nospace;
    iov_out[i].iov_base = PTR_ADDBYTES(qbp->bytes->data, qbp->skip_bytes + (start.offset - (qbp->end_offset - qbp->len_bytes)));
    iov_out[i].iov_len = qbp->end_offset - start.offset;
    if( bytes_out ) bytes_out[i] = qbp->bytes;
    // store it if we had any data there.
    if( iov_out[i].iov_len > 0 ) i++;


    // Now, on to the next.
    deque_it_forward_one(sizeof(qbuffer_part_t), &iter);

    // until we get to the same block as end, we need to store full blocks.
    while( ! deque_it_equals( iter, end.iter ) ) {
      if( deque_it_equals( iter, d_end ) ) {
        // error: end is not in deque.
        *iovcnt_out = 0;
        QIO_RETURN_CONSTANT_ERROR(EINVAL, "end is not in deque");
      }

      qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter);
      if( i >= max_iov ) goto error_nospace;
      iov_out[i].iov_base = PTR_ADDBYTES(qbp->bytes->data, qbp->skip_bytes);
      iov_out[i].iov_len = qbp->len_bytes;
      if( bytes_out ) bytes_out[i] = qbp->bytes;
      // store it if we had any data there.
      if( iov_out[i].iov_len > 0 ) i++;

      // Now, on to the next.
      deque_it_forward_one(sizeof(qbuffer_part_t), &iter);
    }

    // at the end of the loop
    // is there any data in end?
    if( deque_it_equals(iter, d_end) ) {
      // we're currently pointing to the end; no need to add more.
    } else {
      qbp = (qbuffer_part_t*) deque_it_get_cur_ptr(sizeof(qbuffer_part_t), iter);
      // add a partial end block. We know it's different from
      // start since we handled that above.
      if( i >= max_iov ) goto error_nospace;
      iov_out[i].iov_base = PTR_ADDBYTES(qbp->bytes->data, qbp->skip_bytes);
      iov_out[i].iov_len = end.offset - (qbp->end_offset - qbp->len_bytes);
      if( bytes_out ) bytes_out[i] = qbp->bytes;
      if( iov_out[i].iov_len > 0 ) i++;
    }
  }

  *iovcnt_out = i;
  return 0;

error_nospace:
  *iovcnt_out = 0;
  // EOVERFLOW or ENOBUFS would make sense too
  QIO_RETURN_CONSTANT_ERROR(EMSGSIZE, "no space in buffer");
}
예제 #19
0
/**
 * Expand deque at end.
 */
deque_iterator_t _deque_expand_at_end(deque_t* pdeq_deque, size_t t_expandsize, deque_iterator_t* pit_pos)
{
    deque_iterator_t it_oldend;
    size_t           t_remainsize = 0; /* the remain size in last container */

    assert(pdeq_deque != NULL);
    assert(_deque_is_inited(pdeq_deque));
#ifndef NDEBUG
    if(pit_pos != NULL)
    {
        assert(_deque_iterator_belong_to_deque(_GET_DEQUE_CONTAINER(*pit_pos), *pit_pos));
    }
#endif /* NDEBUG */

    it_oldend = deque_end(pdeq_deque);

    /* if the capacity of last container is enough for expand size */
    t_remainsize = (_GET_DEQUE_AFTERLAST_POS(it_oldend) - _GET_DEQUE_COREPOS(it_oldend)) / _GET_DEQUE_TYPE_SIZE(pdeq_deque);
    if(t_expandsize < t_remainsize)
    {
        /* set the new end iterator */
        _GET_DEQUE_COREPOS(pdeq_deque->_t_finish) += t_expandsize * _GET_DEQUE_TYPE_SIZE(pdeq_deque);
    }
    else
    {
        size_t    t_nomemsize = 0;        /* the size that they have no memory */
        size_t    t_chunksize = 0;        /* the chunk for new element */
        size_t    t_suffixsize = 0;       /* the valid size in end container */
        size_t    t_remainendmapsize = 0; /* the remain space at the map end */
        size_t    t_remainmapsize = 0;    /* the remain space in the map */
        _byte_t** ppby_newchunk = NULL;    /* the pointer to new chunk */
        size_t    i = 0;

        /* caculate the expand container number */
        t_nomemsize = t_expandsize - t_remainsize;
        t_chunksize = (t_nomemsize + _DEQUE_ELEM_COUNT - 1) / _DEQUE_ELEM_COUNT;
        t_suffixsize = t_nomemsize % _DEQUE_ELEM_COUNT;
        if(t_suffixsize == 0)
        {
            t_chunksize++;
        }

        t_remainendmapsize = (pdeq_deque->_ppby_map + pdeq_deque->_t_mapsize) - _GET_DEQUE_MAP_POINTER(it_oldend) - 1;
        t_remainmapsize = pdeq_deque->_t_mapsize -
            (_GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish) - _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start) + 1);

        /* if container remain space is not enough for expand size then grow the map for expand container */
        if(t_chunksize > t_remainmapsize)
        {
            size_t t_validmapsize = _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish) -
                _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start) + 1;
            size_t t_newmapstartpos = 0;
            size_t t_oldmapstartpos = (pdeq_deque->_t_mapsize - t_validmapsize) / 2;
            size_t t_posdistance = 0;                          /* the distance of pit_pos and map */
            size_t t_growsize = (t_chunksize - t_remainmapsize + _DEQUE_MAP_GROW_STEP - 1) /
                _DEQUE_MAP_GROW_STEP * _DEQUE_MAP_GROW_STEP;   /* grow size multiple of eight */
            _mappointer_t ppby_oldmap = pdeq_deque->_ppby_map;  /* save the old map */
            size_t t_oldmapsize = pdeq_deque->_t_mapsize;

            /* new map */
            pdeq_deque->_t_mapsize += t_growsize;
            pdeq_deque->_ppby_map = _alloc_allocate(&pdeq_deque->_t_allocator, sizeof(_byte_t*), pdeq_deque->_t_mapsize);
            assert(pdeq_deque->_ppby_map != NULL);
            memset(pdeq_deque->_ppby_map, 0x00, sizeof(_byte_t*) * pdeq_deque->_t_mapsize);

            /* copy the chunk pointer from old map to new map */
            t_newmapstartpos = (pdeq_deque->_t_mapsize - (t_validmapsize + t_chunksize)) / 2;
            memcpy(pdeq_deque->_ppby_map + t_newmapstartpos, ppby_oldmap + t_oldmapstartpos, sizeof(_byte_t*) * t_validmapsize);
            /* get the pit_pos distance */
            if(pit_pos != NULL)
            {
                t_posdistance = _GET_DEQUE_MAP_POINTER(*pit_pos) - _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start);
            }
            /* reset the start, finish and old front iterator */
            _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start) = pdeq_deque->_ppby_map + t_newmapstartpos;
            _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish) = pdeq_deque->_ppby_map + t_newmapstartpos + t_validmapsize - 1;
            _GET_DEQUE_MAP_POINTER(it_oldend) = _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish);
            /* modify pit_pos */
            if(pit_pos != NULL)
            {
                _GET_DEQUE_MAP_POINTER(*pit_pos) = _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start) + t_posdistance;
            }
            _alloc_deallocate(&pdeq_deque->_t_allocator, ppby_oldmap, sizeof(_byte_t*), t_oldmapsize);
        }
        /* else if the chunk remain space is enough for expand size */
        else if(t_chunksize > t_remainendmapsize && t_chunksize <= t_remainmapsize)
        {
            size_t t_oldvalidmapsize = _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish) -
                _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start) + 1;                        /* old valid chunk count in old map */
            size_t t_newvalidmapsize = t_oldvalidmapsize + t_chunksize;                  /* the valid chunk count in new map */
            size_t t_oldstartpossize = (pdeq_deque->_t_mapsize - t_oldvalidmapsize) / 2; /* the chunk start pos in old map */
            size_t t_newstartpossize = (pdeq_deque->_t_mapsize - t_newvalidmapsize) / 2; /* the chunk start pos in new map */
            size_t t_movesize = t_oldstartpossize - t_newstartpossize;                   /* the distance of move */

            /* move the valid container pointer in map */
            memmove(_GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start) - t_movesize,
                _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start), sizeof(_byte_t*) * t_oldvalidmapsize);
            /* reset the start, finish and oldend iterator */
            _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_start) -= t_movesize;
            _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish) -= t_movesize;
            _GET_DEQUE_MAP_POINTER(it_oldend) -= t_movesize;
            if(pit_pos != NULL)
            {
                _GET_DEQUE_MAP_POINTER(*pit_pos) -= t_movesize;
            }
        }

        /* allocate the container */
        for(i = 0, ppby_newchunk = _GET_DEQUE_MAP_POINTER(it_oldend) + 1; i < t_chunksize; ++i, ++ppby_newchunk)
        {
            *ppby_newchunk = _alloc_allocate(&pdeq_deque->_t_allocator, _GET_DEQUE_TYPE_SIZE(pdeq_deque), _DEQUE_ELEM_COUNT);
            assert(*ppby_newchunk != NULL);
        }

        /* set new end iterator */
        _GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish) = _GET_DEQUE_MAP_POINTER(it_oldend) + t_chunksize;
        _GET_DEQUE_FIRST_POS(pdeq_deque->_t_finish) = *_GET_DEQUE_MAP_POINTER(pdeq_deque->_t_finish);
        _GET_DEQUE_AFTERLAST_POS(pdeq_deque->_t_finish) = _GET_DEQUE_FIRST_POS(pdeq_deque->_t_finish) + 
            _DEQUE_ELEM_COUNT * _GET_DEQUE_TYPE_SIZE(pdeq_deque);
        _GET_DEQUE_COREPOS(pdeq_deque->_t_finish) = _GET_DEQUE_FIRST_POS(pdeq_deque->_t_finish) + 
            t_suffixsize * _GET_DEQUE_TYPE_SIZE(pdeq_deque);
    }

    /* initialize all new elements */
    _deque_init_elem_range_auxiliary(pdeq_deque, it_oldend, deque_end(pdeq_deque));

    return it_oldend;
}