avl: add blob comparator function
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
d3fa561e5a
commit
72613ca2c8
2 changed files with 14 additions and 0 deletions
13
avl-cmp.c
13
avl-cmp.c
|
@ -15,6 +15,12 @@
|
|||
*/
|
||||
#include <string.h>
|
||||
#include "avl-cmp.h"
|
||||
#include "blob.h"
|
||||
|
||||
static inline int _min(int v1, int v2)
|
||||
{
|
||||
return v1 < v2 ? v1 : v2;
|
||||
}
|
||||
|
||||
int
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -17,5 +17,6 @@
|
|||
#define __AVL_CMP_H
|
||||
|
||||
int avl_strcmp(const void *k1, const void *k2, void *ptr);
|
||||
int avl_blobcmp(const void *k1, const void *k2, void *ptr);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue