Skip to content

Commit

Permalink
shift -> lpop
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Apr 15, 2011
1 parent ff0b832 commit 3240b6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ bm_pop() {
}

static void
bm_shift() {
bm_lpop() {
int n = nnodes;
list_t *list = list_new();
while (n--) {
list_lpush(list, list_node_new("foo"));
}
list_node_t *node;
start();
while ((node = list_shift(list)))
while ((node = list_lpop(list)))
;
stop();
}
Expand Down Expand Up @@ -134,7 +134,7 @@ main(int argc, const char **argv){
bm("rpushed", bm_rpush);
bm("lpushed", bm_lpush);
bm("pop", bm_pop);
bm("shift", bm_shift);
bm("lpop", bm_lpop);
bm("find (last node)", bm_find);
bm("iterate", bm_iterate);
bm("at(100,000)", bm_at);
Expand Down
2 changes: 1 addition & 1 deletion src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ list_pop(list_t *self) {
*/

list_node_t *
list_shift(list_t *self) {
list_lpop(list_t *self) {
if (!self->len) return NULL;
list_node_t *node = self->head;
if (--self->len) {
Expand Down
2 changes: 1 addition & 1 deletion src/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ list_node_t *
list_pop(list_t *self);

list_node_t *
list_shift(list_t *self);
list_lpop(list_t *self);

void
list_remove(list_t *self, list_node_t *node);
Expand Down
12 changes: 6 additions & 6 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ test_list_pop() {
}

static void
test_list_shift() {
test_list_lpop() {
// Setup
list_t *list = list_new();
list_node_t *a = list_rpush(list, list_node_new("a"));
Expand All @@ -244,22 +244,22 @@ test_list_shift() {
// Assertions
assert(3 == list->len);

assert(a == list_shift(list));
assert(a == list_lpop(list));
assert(2 == list->len);
assert(b == list->head);
assert(NULL == list->head->prev && "new head node prev is not NULL");
assert(NULL == a->prev && "detached node prev is not NULL");
assert(NULL == a->next && "detached node next is not NULL");

assert(b == list_shift(list));
assert(b == list_lpop(list));
assert(1 == list->len);

assert(c == list_shift(list));
assert(c == list_lpop(list));
assert(0 == list->len);
assert(NULL == list->head);
assert(NULL == list->tail);

assert(NULL == list_shift(list));
assert(NULL == list_lpop(list));
assert(0 == list->len);
}

Expand Down Expand Up @@ -316,7 +316,7 @@ main(int argc, const char **argv){
test(list_at);
test(list_remove);
test(list_pop);
test(list_shift);
test(list_lpop);
test(list_destroy);
test(list_iterator_t);
puts("... \x1b[32m100%\x1b[0m\n");
Expand Down

0 comments on commit 3240b6d

Please sign in to comment.