avl: add blob comparator function

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau 2016-07-29 10:58:55 +02:00
parent d3fa561e5a
commit 72613ca2c8
2 changed files with 14 additions and 0 deletions

View file

@ -15,6 +15,12 @@
*/ */
#include <string.h> #include <string.h>
#include "avl-cmp.h" #include "avl-cmp.h"
#include "blob.h"
static inline int _min(int v1, int v2)
{
return v1 < v2 ? v1 : v2;
}
int int
avl_strcmp(const void *k1, const void *k2, void *ptr) avl_strcmp(const void *k1, const void *k2, void *ptr)
@ -22,3 +28,10 @@ avl_strcmp(const void *k1, const void *k2, void *ptr)
return strcmp(k1, k2); return strcmp(k1, k2);
} }
int
avl_blobcmp(const void *k1, const void *k2, void *ptr)
{
int len = _min(blob_raw_len(k1), blob_raw_len(k2));
return memcmp(k1, k2, len);
}

View file

@ -17,5 +17,6 @@
#define __AVL_CMP_H #define __AVL_CMP_H
int avl_strcmp(const void *k1, const void *k2, void *ptr); int avl_strcmp(const void *k1, const void *k2, void *ptr);
int avl_blobcmp(const void *k1, const void *k2, void *ptr);
#endif #endif