예제 #1
0
파일: list.c 프로젝트: hbfhaapy/study
void 
list_push_front(list_t l, element_t e)
{
  ASSERT_LIST(l);

  list_insert(l, &l->head, e);
}
예제 #2
0
파일: list.c 프로젝트: hbfhaapy/study
void 
list_push_back(list_t l, element_t e)
{
  ASSERT_LIST(l);
  
  list_insert(l, l->head.next, e);
}
예제 #3
0
파일: list.c 프로젝트: hbfhaapy/study
int 
list_empty(list_t l) 
{
  ASSERT_LIST(l);

  return (NULL == l->front);
}
예제 #4
0
파일: list.c 프로젝트: hbfhaapy/study
int 
list_size(list_t l) 
{
  ASSERT_LIST(l);

  return (l->size);
}
예제 #5
0
파일: list.c 프로젝트: hbfhaapy/study
int 
list_empty(list_t l) 
{
  ASSERT_LIST(l);

  return (l->head.next == &l->head);
}
예제 #6
0
int
list_empty(list_t l)
{
    ASSERT_LIST(l);

    return (0 == l->size);
}
예제 #7
0
파일: list.c 프로젝트: hbfhaapy/study
element_t 
list_pop_back(list_t l) 
{
  ASSERT_LIST(l);
  ASSERT_LIST_UNDERFLOW(l);

  return list_erase(l, l->head.next);
}
예제 #8
0
파일: list.c 프로젝트: hbfhaapy/study
element_t 
list_pop_front(list_t l)
{
  ASSERT_LIST(l);
  ASSERT_LIST_UNDERFLOW(l);

  return list_erase(l, (&l->head)->prev);
}
예제 #9
0
void
linked_list_free (linked_list list)
{
  ASSERT_LIST (list);
  linked_list_header *header = (linked_list_header *) list;
  if (header->next)
  {
    linked_list_free ((linked_list) header->next);
  }
  jsp_mm_free (list);
}
예제 #10
0
파일: list.c 프로젝트: hbfhaapy/study
list_t 
list_create(void) 
{
  list_t l = (list_t)malloc(sizeof(*l));
  ASSERT_LIST(l);

  l->front = l->rear = NULL;
  l->size = 0;
  
  return l;
}
예제 #11
0
파일: list.c 프로젝트: hbfhaapy/study
list_t 
list_create(void) 
{
  list_t l = (list_t)malloc(sizeof(*l));
  ASSERT_LIST(l);

  l->size = 0;
  l->head.prev = l->head.next = &l->head;

  return l;
}
예제 #12
0
void
linked_list_free (linked_list list)
{
  ASSERT_LIST (list);
  linked_list_header *header = (linked_list_header *) list;
  if (header->next)
  {
    linked_list_free ((linked_list) header->next);
  }
  mem_heap_free_block (list);
}
예제 #13
0
파일: list.c 프로젝트: hbfhaapy/study
void 
list_traverse(list_t l, void (*visit)(element_t)) 
{
  list_node_t iter;
  ASSERT_LIST(l);
  ASSERT_LIST_UNDERFLOW(l);

  iter = l->front;
  while (NULL != iter) {
    visit(iter->e);
    iter = iter->next;
  }
}
예제 #14
0
void
list_push_back(list_t l, element_t e)
{
    int i;
    ASSERT_LIST(l);
    ASSERT_LIST_OVERFLOW(l);

    i = l->free;
    l->free = l->elements[i].next;
    l->elements[i].e = e;
    l->rear = i;
    ++l->size;
}
예제 #15
0
파일: list.c 프로젝트: hbfhaapy/study
void 
list_clear(list_t l) 
{
  list_node_t iter, node;
  ASSERT_LIST(l);

  iter = l->head.next;
  while (iter != &l->head) {
    node = iter;
    iter = iter->next;
    list_erase(l, iter);
  }
  l->size = 0;
}
예제 #16
0
파일: list.c 프로젝트: hbfhaapy/study
void 
list_insert(list_t l, element_t e)
{
  list_node_t new_node;
  ASSERT_LIST(l);

  new_node = list_node_create(e);
  if (NULL == l->front)
    l->front = l->rear = new_node;
  else {
    l->rear->next = new_node;
    l->rear = new_node;
  }
  ++l->size;
}
예제 #17
0
파일: list.c 프로젝트: hbfhaapy/study
element_t 
list_remove(list_t l)
{
  element_t e;
  list_node_t old_node;
  ASSERT_LIST(l);
  ASSERT_LIST_UNDERFLOW(l);

  old_node = l->front;
  l->front = l->front->next;
  e = old_node->e;
  free(old_node);
  --l->size;

  return e;
}
예제 #18
0
파일: list.c 프로젝트: hbfhaapy/study
void 
list_circular(list_t l, int circular)
{
  int i;
  list_node_t iter;
  ASSERT_LIST(l);

  iter = l->head.next;
  for (i = 0; i < circular; ++i) {
    fprintf(stdout, "The [%d] circular circular-list show:\n", i + 1);
    while (iter != &l->head) {
      fprintf(stdout, "\tthe element is {value=>%lf}\n", *(double*)iter->e);
      iter = iter->next;
    }
    iter = iter->next;
  }
}
예제 #19
0
void
list_push_front(list_t l, element_t e)
{
    int i;
    ASSERT_LIST(l);
    ASSERT_LIST_OVERFLOW(l);

    i = l->free;
    l->free = l->elements[i].next;
    l->elements[i].e = e;
    if (0 != l->size)
        l->elements[i].next = l->front;
    else
        l->rear = i;
    l->front = i;
    ++l->size;
}
예제 #20
0
파일: list.c 프로젝트: hbfhaapy/study
int 
list_find(list_t l, element_t e, 
  int (*cmp)(element_t, element_t, int), int elem_sz)
{
  int i = 0;
  list_node_t iter;
  ASSERT_LIST(l);
  ASSERT_LIST_UNDERFLOW(l);

  iter = l->front;
  while (NULL != iter) {
    if (cmp(e, iter->e, elem_sz))
      return i;
    ++i;
  }

  return (-1);
}
예제 #21
0
element_t
list_pop_front(list_t l)
{
    int i;
    element_t e;
    ASSERT_LIST(l);
    ASSERT_LIST_UNDERFLOW(l);

    i = l->front;
    e = l->elements[i].e;
    l->front = l->elements[i].next;
    l->elements[i].next = l->free;
    l->free = i;
    if (0 == --l->size)
        l->front = l->rear = l->free = 0;

    return e;
}
예제 #22
0
list_t
list_create(int capacity)
{
    list_t l = (list_t)malloc(sizeof(*l));
    ASSERT_LIST(l);

    l->capacity = (capacity < LIST_CAPACITY_DEF ?
                   LIST_CAPACITY_DEF : capacity);
    l->size     = 0;
    l->front = l->rear = 0;
    l->free     = 0;
    l->elements = (element_t)malloc(l->capacity * sizeof(list_node_t));
    if (NULL == l->elements) {
        fprintf(stderr, "create static list failed ...");
        exit(0);
    }
    list_initialize(l);

    return l;
}
예제 #23
0
void *
linked_list_element (linked_list list, size_t element_num)
{
  ASSERT_LIST (list);
  linked_list_header *header = (linked_list_header *) list;
  size_t block_size = linked_list_block_size (header->element_size);
  linked_list raw = list + sizeof (linked_list_header);
  if (block_size < header->element_size * (element_num + 1))
  {
    if (header->next)
    {
      return linked_list_element ((linked_list) header->next,
                                  element_num - (block_size / header->element_size));
    }
    else
    {
      return NULL;
    }
  }
  raw += header->element_size * element_num;
  return raw;
}
예제 #24
0
void
linked_list_set_element (linked_list list, size_t element_num, void *element)
{
  ASSERT_LIST (list);
  linked_list_header *header = (linked_list_header *) list;
  size_t block_size = linked_list_block_size (header->element_size);
  uint8_t *raw = (uint8_t *) (header + 1);
  if (block_size < header->element_size * (element_num + 1))
  {
    if (header->next == null_list)
    {
      header->next = (linked_list_header *) linked_list_init (header->element_size);
    }
    linked_list_set_element ((linked_list) header->next,
                             element_num - (block_size / header->element_size),
                             element);
    return;
  }
  if (element == NULL)
  {
    return;
  }
  memcpy (raw + element_num * header->element_size, element, header->element_size);
}