Browse Source

avl: add blob comparator function

Signed-off-by: Felix Fietkau <nbd@nbd.name>
lede-17.01
Felix Fietkau 4 years ago
parent
commit
72613ca2c8
2 changed files with 14 additions and 0 deletions
  1. +13
    -0
      avl-cmp.c
  2. +1
    -0
      avl-cmp.h

+ 13
- 0
avl-cmp.c View File

@ -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);
}

+ 1
- 0
avl-cmp.h View File

@ -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…
Cancel
Save