Exemplo n.º 1
0
static gl_list_node_t
gl_carray_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
                          const void *elt)
{
  size_t index = gl_carray_indexof_from_to (list, start_index, end_index, elt);
  return INDEX_TO_NODE (index);
}
Exemplo n.º 2
0
static bool
gl_carray_iterator_next (gl_list_iterator_t *iterator,
                         const void **eltp, gl_list_node_t *nodep)
{
  gl_list_t list = iterator->list;
  if (iterator->count != list->count)
    {
      if (iterator->count != list->count + 1)
        /* Concurrent modifications were done on the list.  */
        abort ();
      /* The last returned element was removed.  */
      iterator->count--;
      iterator->i--;
      iterator->j--;
    }
  if (iterator->i < iterator->j)
    {
      size_t i = list->offset + iterator->i;
      if (i >= list->allocated)
        i -= list->allocated;
      *eltp = list->elements[i];
      if (nodep != NULL)
        *nodep = INDEX_TO_NODE (iterator->i);
      iterator->i++;
      return true;
    }
  else
    return false;
}
Exemplo n.º 3
0
static gl_list_node_t
gl_carray_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar,
                             const void *elt)
{
  size_t index =
    gl_carray_sortedlist_indexof_from_to (list, compar, 0, list->count, elt);
  return INDEX_TO_NODE (index);
}
Exemplo n.º 4
0
static gl_list_node_t
gl_carray_sortedlist_search_from_to (gl_list_t list,
                                     gl_listelement_compar_fn compar,
                                     size_t low, size_t high,
                                     const void *elt)
{
  size_t index =
    gl_carray_sortedlist_indexof_from_to (list, compar, low, high, elt);
  return INDEX_TO_NODE (index);
}
Exemplo n.º 5
0
static gl_list_node_t
gl_carray_previous_node (gl_list_t list, gl_list_node_t node)
{
  uintptr_t index = NODE_TO_INDEX (node);
  if (!(index < list->count))
    /* Invalid argument.  */
    abort ();
  if (index > 0)
    return INDEX_TO_NODE (index - 1);
  else
    return NULL;
}
Exemplo n.º 6
0
static gl_list_node_t
gl_carray_nx_add_first (gl_list_t list, const void *elt)
{
  size_t count = list->count;

  if (count == list->allocated)
    if (grow (list) < 0)
      return NULL;
  list->offset = (list->offset == 0 ? list->allocated : list->offset) - 1;
  list->elements[list->offset] = elt;
  list->count = count + 1;
  return INDEX_TO_NODE (0);
}
Exemplo n.º 7
0
static gl_list_node_t
gl_carray_nx_set_at (gl_list_t list, size_t position, const void *elt)
{
  size_t count = list->count;
  size_t i;

  if (!(position < count))
    /* Invalid argument.  */
    abort ();
  i = list->offset + position;
  if (i >= list->allocated)
    i -= list->allocated;
  list->elements[i] = elt;
  return INDEX_TO_NODE (position);
}
Exemplo n.º 8
0
static gl_list_node_t
gl_carray_nx_add_last (gl_list_t list, const void *elt)
{
  size_t count = list->count;
  size_t i;

  if (count == list->allocated)
    if (grow (list) < 0)
      return NULL;
  i = list->offset + count;
  if (i >= list->allocated)
    i -= list->allocated;
  list->elements[i] = elt;
  list->count = count + 1;
  return INDEX_TO_NODE (count);
}
Exemplo n.º 9
0
void
uu_list_insert(uu_list_t *lp, void *elem, uu_list_index_t idx)
{
    uu_list_node_impl_t *np;

    np = INDEX_TO_NODE(idx);
    if (np == NULL)
        np = &lp->ul_null_node;

    if (lp->ul_debug) {
        if (!INDEX_VALID(lp, idx))
            uu_panic("uu_list_insert(%p, %p, %p): %s\n",
                     (void *)lp, elem, (void *)idx,
                     INDEX_CHECK(idx)? "outdated index" :
                     "invalid index");
        if (np->uln_prev == NULL)
            uu_panic("uu_list_insert(%p, %p, %p): out-of-date "
                     "index\n", (void *)lp, elem, (void *)idx);
    }

    list_insert(lp, ELEM_TO_NODE(lp, elem), np->uln_prev, np);
}
Exemplo n.º 10
0
static gl_list_node_t
gl_carray_nx_add_at (gl_list_t list, size_t position, const void *elt)
{
  size_t count = list->count;
  const void **elements;

  if (!(position <= count))
    /* Invalid argument.  */
    abort ();
  if (count == list->allocated)
    if (grow (list) < 0)
      return NULL;
  elements = list->elements;
  if (position <= (count / 2))
    {
      /* Shift at most count/2 elements to the left.  */
      size_t i2, i;

      list->offset = (list->offset == 0 ? list->allocated : list->offset) - 1;

      i2 = list->offset + position;
      if (i2 >= list->allocated)
        {
          /* Here we must have list->offset > 0, hence list->allocated > 0.  */
          size_t i1 = list->allocated - 1;
          i2 -= list->allocated;
          for (i = list->offset; i < i1; i++)
            elements[i] = elements[i + 1];
          elements[i1] = elements[0];
          for (i = 0; i < i2; i++)
            elements[i] = elements[i + 1];
        }
      else
        {
          for (i = list->offset; i < i2; i++)
            elements[i] = elements[i + 1];
        }
      elements[i2] = elt;
    }
  else
    {
      /* Shift at most (count+1)/2 elements to the right.  */
      size_t i1, i3, i;

      i1 = list->offset + position;
      i3 = list->offset + count;
      if (i1 >= list->allocated)
        {
          i1 -= list->allocated;
          i3 -= list->allocated;
          for (i = i3; i > i1; i--)
            elements[i] = elements[i - 1];
        }
      else if (i3 >= list->allocated)
        {
          /* Here we must have list->offset > 0, hence list->allocated > 0.  */
          size_t i2 = list->allocated - 1;
          i3 -= list->allocated;
          for (i = i3; i > 0; i--)
            elements[i] = elements[i - 1];
          elements[0] = elements[i2];
          for (i = i2; i > i1; i--)
            elements[i] = elements[i - 1];
        }
      else
        {
          for (i = i3; i > i1; i--)
            elements[i] = elements[i - 1];
        }
      elements[i1] = elt;
    }
  list->count = count + 1;
  return INDEX_TO_NODE (position);
}