Permalink
Browse files

Renamed more functions

  • Loading branch information...
1 parent 0adbf97 commit 724aeafecac3b762621e2b250faa905fabc4599a @tj tj committed Nov 28, 2010
Showing with 85 additions and 85 deletions.
  1. +15 −15 src/iterator.c
  2. +34 −34 src/list.c
  3. +31 −31 src/list.h
  4. +5 −5 src/node.c
View
@@ -8,41 +8,41 @@
#include "list.h"
/*
- * Allocate a new ListIterator. NULL on failure.
+ * Allocate a new list_iterator_t. NULL on failure.
* Accepts a direction, which may be LIST_HEAD or LIST_TAIL.
*/
-ListIterator *
-ListIterator_new(List *list, ListDirection direction) {
- ListNode *node = direction == LIST_HEAD
+list_iterator_t *
+list_iterator_new(list_t *list, list_direction_t direction) {
+ list_node_t *node = direction == LIST_HEAD
? list->head
: list->tail;
- return ListIterator_newFromNode(node, direction);
+ return list_iterator_new_from_node(node, direction);
}
/*
- * Allocate a new ListIterator with the given start
+ * Allocate a new list_iterator_t with the given start
* node. NULL on failure.
*/
-ListIterator *
-ListIterator_newFromNode(ListNode *node, ListDirection direction) {
- ListIterator *self;
- if (!(self = LIST_MALLOC(sizeof(ListIterator))))
+list_iterator_t *
+list_iterator_new_from_node(list_node_t *node, list_direction_t direction) {
+ list_iterator_t *self;
+ if (!(self = LIST_MALLOC(sizeof(list_iterator_t))))
return NULL;
self->next = node;
self->direction = direction;
return self;
}
/*
- * Return the next ListNode or NULL when no more
+ * Return the next list_node_t or NULL when no more
* nodes remain in the list.
*/
-ListNode *
-ListIterator_next(ListIterator *self) {
- ListNode *curr = self->next;
+list_node_t *
+list_iterator_next(list_iterator_t *self) {
+ list_node_t *curr = self->next;
if (curr) {
self->next = self->direction == LIST_HEAD
? curr->next
@@ -56,6 +56,6 @@ ListIterator_next(ListIterator *self) {
*/
void
-ListIterator_destroy(ListIterator *self) {
+list_iterator_destroy(list_iterator_t *self) {
LIST_FREE(self);
}
View
@@ -8,13 +8,13 @@
#include "list.h"
/*
- * Allocate a new List. NULL on failure.
+ * Allocate a new list_t. NULL on failure.
*/
-List *
-List_new() {
- List *self;
- if (!(self = LIST_MALLOC(sizeof(List))))
+list_t *
+list_new() {
+ list_t *self;
+ if (!(self = LIST_MALLOC(sizeof(list_t))))
return NULL;
self->head = NULL;
self->tail = NULL;
@@ -29,10 +29,10 @@ List_new() {
*/
void
-List_destroy(List *self) {
+list_destroy(list_t *self) {
unsigned int len = self->len;
- ListNode *next;
- ListNode *curr = self->head;
+ list_node_t *next;
+ list_node_t *curr = self->head;
while (len--) {
next = curr->next;
if (self->free) self->free(curr->val);
@@ -47,8 +47,8 @@ List_destroy(List *self) {
* and return the node, NULL on failure.
*/
-ListNode *
-List_push(List *self, ListNode *node) {
+list_node_t *
+list_push(list_t *self, list_node_t *node) {
if (!node) return NULL;
if (self->len) {
node->prev = self->tail;
@@ -67,10 +67,10 @@ List_push(List *self, ListNode *node) {
* Return / detach the last node in the list, or NULL.
*/
-ListNode *
-List_pop(List *self) {
+list_node_t *
+list_pop(list_t *self) {
if (!self->len) return NULL;
- ListNode *node = self->tail;
+ list_node_t *node = self->tail;
if (--self->len) {
(self->tail = node->prev)->next = NULL;
} else {
@@ -84,10 +84,10 @@ List_pop(List *self) {
* Return / detach the first node in the list, or NULL.
*/
-ListNode *
-List_shift(List *self) {
+list_node_t *
+list_shift(list_t *self) {
if (!self->len) return NULL;
- ListNode *node = self->head;
+ list_node_t *node = self->head;
if (--self->len) {
(self->head = node->next)->prev = NULL;
} else {
@@ -102,8 +102,8 @@ List_shift(List *self) {
* and return the node, NULL on failure.
*/
-ListNode *
-List_unshift(List *self, ListNode *node) {
+list_node_t *
+list_unshift(list_t *self, list_node_t *node) {
if (!node) return NULL;
if (self->len) {
node->next = self->head;
@@ -122,47 +122,47 @@ List_unshift(List *self, ListNode *node) {
* Return the node associated to val or NULL.
*/
-ListNode *
-List_find(List *self, void *val) {
- ListIterator *it = ListIterator_new(self, LIST_HEAD);
- ListNode *node;
- while ((node = ListIterator_next(it))) {
+list_node_t *
+list_find(list_t *self, void *val) {
+ list_iterator_t *it = list_iterator_new(self, LIST_HEAD);
+ list_node_t *node;
+ while ((node = list_iterator_next(it))) {
if (self->match) {
if (self->match(val, node->val)) {
- ListIterator_destroy(it);
+ list_iterator_destroy(it);
return node;
}
} else {
if (val == node->val) {
- ListIterator_destroy(it);
+ list_iterator_destroy(it);
return node;
}
}
}
- ListIterator_destroy(it);
+ list_iterator_destroy(it);
return NULL;
}
/*
* Return the node at the given index or NULL.
*/
-ListNode *
-List_at(List *self, int index) {
- ListDirection direction = LIST_HEAD;
+list_node_t *
+list_at(list_t *self, int index) {
+ list_direction_t direction = LIST_HEAD;
if (index < 0) {
direction = LIST_TAIL;
index = ~index;
}
if (index < self->len) {
- ListIterator *it = ListIterator_new(self, direction);
- ListNode *node = ListIterator_next(it);
+ list_iterator_t *it = list_iterator_new(self, direction);
+ list_node_t *node = list_iterator_next(it);
while (index--) {
- node = ListIterator_next(it);
+ node = list_iterator_next(it);
};
- ListIterator_destroy(it);
+ list_iterator_destroy(it);
return node;
}
@@ -174,7 +174,7 @@ List_at(List *self, int index) {
*/
void
-List_remove(List *self, ListNode *node) {
+list_remove(list_t *self, list_node_t *node) {
node->prev
? (node->prev->next = node->next)
: (self->head = node->next);
View
@@ -29,67 +29,67 @@ extern "C" {
#endif
/*
- * List iterator direction.
+ * list_t iterator direction.
*/
typedef enum {
LIST_HEAD
, LIST_TAIL
-} ListDirection;
+} list_direction_t;
/*
- * List node struct.
+ * list_t node struct.
*/
-typedef struct ListNode {
- struct ListNode *prev;
- struct ListNode *next;
+typedef struct list_node {
+ struct list_node *prev;
+ struct list_node *next;
void *val;
-} ListNode;
+} list_node_t;
/*
- * List struct.
+ * list_t struct.
*/
typedef struct {
- ListNode *head;
- ListNode *tail;
+ list_node_t *head;
+ list_node_t *tail;
unsigned int len;
void (*free)(void *val);
int (*match)(void *a, void *b);
-} List;
+} list_t;
/*
- * List iterator struct.
+ * list_t iterator struct.
*/
typedef struct {
- ListNode *next;
- ListDirection direction;
-} ListIterator;
+ list_node_t *next;
+ list_direction_t direction;
+} list_iterator_t;
// Node prototypes.
-ListNode *ListNode_new(void *val);
+list_node_t *list_node_new(void *val);
-// List prototypes.
+// list_t prototypes.
-List *List_new();
-ListNode *List_push(List *self, ListNode *node);
-ListNode *List_unshift(List *self, ListNode *node);
-ListNode *List_find(List *self, void *val);
-ListNode *List_at(List *self, int index);
-ListNode *List_pop(List *self);
-ListNode *List_shift(List *self);
-void List_remove(List *self, ListNode *node);
-void List_destroy(List *self);
+list_t *list_new();
+list_node_t *list_push(list_t *self, list_node_t *node);
+list_node_t *list_unshift(list_t *self, list_node_t *node);
+list_node_t *list_find(list_t *self, void *val);
+list_node_t *list_at(list_t *self, int index);
+list_node_t *list_pop(list_t *self);
+list_node_t *list_shift(list_t *self);
+void list_remove(list_t *self, list_node_t *node);
+void list_destroy(list_t *self);
-// List iterator prototypes.
+// list_t iterator prototypes.
-ListIterator *ListIterator_new(List *list, ListDirection direction);
-ListIterator *ListIterator_newFromNode(ListNode *node, ListDirection direction);
-ListNode *ListIterator_next(ListIterator *self);
-void ListIterator_destroy(ListIterator *self);
+list_iterator_t *list_iterator_new(list_t *list, list_direction_t direction);
+list_iterator_t *list_iterator_new_from_node(list_node_t *node, list_direction_t direction);
+list_node_t *list_iterator_next(list_iterator_t *self);
+void list_iterator_destroy(list_iterator_t *self);
#ifdef __cplusplus
}
View
@@ -8,13 +8,13 @@
#include "list.h"
/*
- * Allocates a new ListNode. NULL on failure.
+ * Allocates a new list_node_t. NULL on failure.
*/
-ListNode *
-ListNode_new(void *val) {
- ListNode *self;
- if (!(self = LIST_MALLOC(sizeof(ListNode))))
+list_node_t *
+list_node_new(void *val) {
+ list_node_t *self;
+ if (!(self = LIST_MALLOC(sizeof(list_node_t))))
return NULL;
self->prev = NULL;
self->next = NULL;

0 comments on commit 724aeaf

Please sign in to comment.