Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

push -> rpush

  • Loading branch information...
commit ff0b832954b728a85dfff1722c94293a562ff994 1 parent 3f0ef1d
@tj tj authored
Showing with 42 additions and 42 deletions.
  1. +5 −5 Readme.md
  2. +4 −4 benchmark.c
  3. +1 −1  src/list.c
  4. +1 −1  src/list.h
  5. +31 −31 test.c
View
10 Readme.md
@@ -20,11 +20,11 @@
list_node_t *node = list_node_new("my value");
node->val; // "my value"
-## list_node_ \* list_push(list_t_ \*self, list_node_t *node)
+## list_node_ \* list_rpush(list_t_ \*self, list_node_t *node)
Append _node_ to _self_, returning _node_.
- list_push(list, list_node_new("value"));
+ list_rpush(list, list_node_new("value"));
list->tail->val; // "value"
## list_node_t \* list_pop(list \*self)
@@ -96,9 +96,9 @@ list iteration:
list *langs = list_new();
- list_node_t *c = list_push(langs, list_node_new("c"));
- list_node_t *js = list_push(langs, list_node_new("js"));
- list_node_t *ruby = list_push(langs, list_node_new("ruby"));
+ list_node_t *c = list_rpush(langs, list_node_new("c"));
+ list_node_t *js = list_rpush(langs, list_node_new("js"));
+ list_node_t *ruby = list_rpush(langs, list_node_new("ruby"));
list_node_t *node;
list_iterator_t *it = list_iterator_new(langs, LIST_HEAD);
View
8 benchmark.c
@@ -25,12 +25,12 @@ stop() {
}
static void
-bm_push() {
+bm_rpush() {
start();
int n = nnodes;
list_t *list = list_new();
while (n--) {
- list_push(list, list_node_new("foo"));
+ list_rpush(list, list_node_new("foo"));
}
stop();
}
@@ -53,7 +53,7 @@ bm_find() {
while (n--) {
list_lpush(list, list_node_new("foo"));
}
- list_push(list, list_node_new("bar"));
+ list_rpush(list, list_node_new("bar"));
start();
list_find(list, "bar");
stop();
@@ -131,7 +131,7 @@ main(int argc, const char **argv){
list = list_new();
while (n--) list_lpush(list, list_node_new("foo"));
puts("\n 10,000,000 nodes\n");
- bm("pushed", bm_push);
+ bm("rpushed", bm_rpush);
bm("lpushed", bm_lpush);
bm("pop", bm_pop);
bm("shift", bm_shift);
View
2  src/list.c
@@ -48,7 +48,7 @@ list_destroy(list_t *self) {
*/
list_node_t *
-list_push(list_t *self, list_node_t *node) {
+list_rpush(list_t *self, list_node_t *node) {
if (!node) return NULL;
if (self->len) {
node->prev = self->tail;
View
2  src/list.h
@@ -79,7 +79,7 @@ list_t *
list_new();
list_node_t *
-list_push(list_t *self, list_node_t *node);
+list_rpush(list_t *self, list_node_t *node);
list_node_t *
list_lpush(list_t *self, list_node_t *node);
View
62 test.c
@@ -38,7 +38,7 @@ test_list_node_new() {
}
static void
-test_list_push() {
+test_list_rpush() {
// Setup
list_t *list = list_new();
list_node_t *a = list_node_new("a");
@@ -46,9 +46,9 @@ test_list_push() {
list_node_t *c = list_node_new("c");
// a b c
- list_push(list, a);
- list_push(list, b);
- list_push(list, c);
+ list_rpush(list, a);
+ list_rpush(list, b);
+ list_rpush(list, c);
// Assertions
assert(list->head == a);
@@ -71,7 +71,7 @@ test_list_lpush() {
list_node_t *c = list_node_new("c");
// c b a
- list_push(list, a);
+ list_rpush(list, a);
list_lpush(list, b);
list_lpush(list, c);
@@ -96,9 +96,9 @@ test_list_at() {
list_node_t *c = list_node_new("c");
// a b c
- list_push(list, a);
- list_push(list, b);
- list_push(list, c);
+ list_rpush(list, a);
+ list_rpush(list, b);
+ list_rpush(list, c);
// Assertions
assert(a == list_at(list, 0));
@@ -120,17 +120,17 @@ test_list_destroy() {
// a b c
list_t *b = list_new();
- list_push(b, list_node_new("a"));
- list_push(b, list_node_new("b"));
- list_push(b, list_node_new("c"));
+ list_rpush(b, list_node_new("a"));
+ list_rpush(b, list_node_new("b"));
+ list_rpush(b, list_node_new("c"));
list_destroy(b);
// Assertions
list_t *c = list_new();
c->free = freeProxy;
- list_push(c, list_node_new(list_node_new("a")));
- list_push(c, list_node_new(list_node_new("b")));
- list_push(c, list_node_new(list_node_new("c")));
+ list_rpush(c, list_node_new(list_node_new("a")));
+ list_rpush(c, list_node_new(list_node_new("b")));
+ list_rpush(c, list_node_new(list_node_new("c")));
list_destroy(c);
assert(freeProxyCalls == 3);
}
@@ -139,16 +139,16 @@ static void
test_list_find() {
// Setup
list_t *langs = list_new();
- list_node_t *js = list_push(langs, list_node_new("js"));
- list_node_t *ruby = list_push(langs, list_node_new("ruby"));
+ list_node_t *js = list_rpush(langs, list_node_new("js"));
+ list_node_t *ruby = list_rpush(langs, list_node_new("ruby"));
list_t *users = list_new();
users->match = User_equal;
User userTJ = { "tj" };
User userSimon = { "simon" };
User userTaylor = { "taylor" };
- list_node_t *tj = list_push(users, list_node_new(&userTJ));
- list_node_t *simon = list_push(users, list_node_new(&userSimon));
+ list_node_t *tj = list_rpush(users, list_node_new(&userTJ));
+ list_node_t *simon = list_rpush(users, list_node_new(&userSimon));
// Assertions
list_node_t *a = list_find(langs, "js");
@@ -170,9 +170,9 @@ static void
test_list_remove() {
// Setup
list_t *list = list_new();
- list_node_t *a = list_push(list, list_node_new("a"));
- list_node_t *b = list_push(list, list_node_new("b"));
- list_node_t *c = list_push(list, list_node_new("c"));
+ list_node_t *a = list_rpush(list, list_node_new("a"));
+ list_node_t *b = list_rpush(list, list_node_new("b"));
+ list_node_t *c = list_rpush(list, list_node_new("c"));
// Assertions
assert(list->len == 3);
@@ -203,9 +203,9 @@ static void
test_list_pop() {
// Setup
list_t *list = list_new();
- list_node_t *a = list_push(list, list_node_new("a"));
- list_node_t *b = list_push(list, list_node_new("b"));
- list_node_t *c = list_push(list, list_node_new("c"));
+ list_node_t *a = list_rpush(list, list_node_new("a"));
+ list_node_t *b = list_rpush(list, list_node_new("b"));
+ list_node_t *c = list_rpush(list, list_node_new("c"));
// Assertions
assert(3 == list->len);
@@ -237,9 +237,9 @@ static void
test_list_shift() {
// Setup
list_t *list = list_new();
- list_node_t *a = list_push(list, list_node_new("a"));
- list_node_t *b = list_push(list, list_node_new("b"));
- list_node_t *c = list_push(list, list_node_new("c"));
+ list_node_t *a = list_rpush(list, list_node_new("a"));
+ list_node_t *b = list_rpush(list, list_node_new("b"));
+ list_node_t *c = list_rpush(list, list_node_new("c"));
// Assertions
assert(3 == list->len);
@@ -272,9 +272,9 @@ test_list_iterator_t() {
list_node_t *simon = list_node_new("simon");
// tj taylor simon
- list_push(list, tj);
- list_push(list, taylor);
- list_push(list, simon);
+ list_rpush(list, tj);
+ list_rpush(list, taylor);
+ list_rpush(list, simon);
// Assertions
@@ -310,7 +310,7 @@ main(int argc, const char **argv){
printf("list_node_t: %db\n", sizeof(list_node_t));
printf("list_iterator_t: %db\n\n", sizeof(list_iterator_t));
test(list_node_new);
- test(list_push);
+ test(list_rpush);
test(list_lpush);
test(list_find);
test(list_at);
Please sign in to comment.
Something went wrong with that request. Please try again.