Skip to content

Commit

Permalink
add list splicing
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Widlund committed Sep 2, 2019
1 parent 89e46a2 commit 3a2673c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ Released 2019-04-19

- Add maps (string map) and mapi (uint64_t) abstractions
- Refactor map interface

Version 1.3
===========

Released 2019-09-02

* New features:

- Add list splicing
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([libdynamic], [1.2.0], [fredrik.widlund@gmail.com])
AC_INIT([libdynamic], [1.3.0], [fredrik.widlund@gmail.com])
AC_CONFIG_AUX_DIR(autotools)
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign no-define])
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef DYNAMIC_H_INCLUDED
#define DYNAMIC_H_INCLUDED

#define DYNAMIC_VERSION "1.2.0"
#define DYNAMIC_VERSION "1.3.0"
#define DYNAMIC_VERSION_MAJOR 1
#define DYNAMIC_VERSION_MINOR 2
#define DYNAMIC_VERSION_MINOR 3
#define DYNAMIC_VERSION_PATCH 0

#ifdef __cplusplus
Expand Down
16 changes: 16 additions & 0 deletions src/dynamic/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ void list_insert(void *list_object, void *object, size_t size)
item->list.next->list.previous = item;
}

void list_splice(void *object1, void *object2)
{
list_item *to, *from;

to = list_object_item(object1);
from = list_object_item(object2);

from->list.previous->list.next = from->list.next;
from->list.next->list.previous = from->list.previous;

from->list.previous = to->list.previous;
from->list.next = to;
from->list.previous->list.next = from;
from->list.next->list.previous = from;
}

void list_erase(void *object, list_release *release)
{
list_item *item = list_object_item(object);
Expand Down
1 change: 1 addition & 0 deletions src/dynamic/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void *list_end(list *);
void list_push_front(list *, void *, size_t);
void list_push_back(list *, void *, size_t);
void list_insert(void *, void *, size_t);
void list_splice(void *, void *);
void list_erase(void *, list_release *);
void list_clear(list *, list_release *);

Expand Down
13 changes: 12 additions & 1 deletion test/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void alloc()

void unit()
{
list l;
list l, l2;
int *p;

list_construct(&l);
Expand Down Expand Up @@ -121,6 +121,17 @@ void unit()
p = list_next(list_front(&l));
assert_int_equal(*p, 3);

list_clear(&l, NULL);
list_construct(&l2);
list_push_back(&l, (int[]){1}, sizeof (int));
list_push_back(&l, (int[]){2}, sizeof (int));
list_push_back(&l, (int[]){3}, sizeof (int));
assert_true(list_empty(&l2));
list_splice(list_front(&l2), list_next(list_front(&l)));
assert_int_equal(*(int *) list_front(&l2), 2);
assert_int_equal(*(int *) list_next(list_front(&l)), 3);
list_destruct(&l2, NULL);

list_destruct(&l, NULL);
}

Expand Down

0 comments on commit 3a2673c

Please sign in to comment.