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