forked from gatsby/datalink_repo
add feature for sorting list.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
// Copyright (c) 2010 TJ Holowaychuk <[email protected]>
|
||||
//
|
||||
|
||||
#include <stdint.h>
|
||||
#include "list.h"
|
||||
|
||||
/*
|
||||
@@ -41,7 +42,7 @@ list_new(void) {
|
||||
self->head = NULL;
|
||||
self->tail = NULL;
|
||||
self->free = NULL;
|
||||
self->match = NULL;
|
||||
self->compare = NULL;
|
||||
self->len = 0;
|
||||
return self;
|
||||
}
|
||||
@@ -181,8 +182,8 @@ list_find(list_t *self, void *val) {
|
||||
list_node_t *node;
|
||||
|
||||
while ((node = list_iterator_next(it))) {
|
||||
if (self->match) {
|
||||
if (self->match(val, node->val)) {
|
||||
if (self->compare) {
|
||||
if (self->compare(val, node->val) == 0) {
|
||||
list_iterator_destroy(it);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
@@ -44,7 +43,7 @@ typedef struct {
|
||||
list_node_t *tail;
|
||||
uint32_t len;
|
||||
void (*free)(void *val);
|
||||
bool (*match)(void *a, void *b);
|
||||
int8_t (*compare)(void *a, void *b);
|
||||
} list_t;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user