Add sexp_cmp
This commit is contained in:
parent
76cf11c69a
commit
ce48a0fbea
|
@ -155,6 +155,25 @@ cmsg_bytes_t sexp_data(sexp_t *x) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sexp_cmp(sexp_t *a, sexp_t *b) {
|
||||||
|
tail:
|
||||||
|
if (a == b) return 0;
|
||||||
|
if (sexp_stringp(a) && sexp_stringp(b)) {
|
||||||
|
return cmsg_bytes_cmp(sexp_data(a), sexp_data(b));
|
||||||
|
}
|
||||||
|
if (sexp_pairp(a) && sexp_pairp(b)) {
|
||||||
|
int result = sexp_cmp(sexp_head(a), sexp_head(b));
|
||||||
|
if (result) return result;
|
||||||
|
a = sexp_tail(a);
|
||||||
|
b = sexp_tail(b);
|
||||||
|
goto tail;
|
||||||
|
}
|
||||||
|
if (a == NULL) return -1;
|
||||||
|
if (b == NULL) return 1;
|
||||||
|
if (a->kind < b->kind) return -1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
sexp_t *sexp_assoc(sexp_t *list, cmsg_bytes_t key) {
|
sexp_t *sexp_assoc(sexp_t *list, cmsg_bytes_t key) {
|
||||||
while (list != NULL) {
|
while (list != NULL) {
|
||||||
sexp_t *candidate = sexp_head(list);
|
sexp_t *candidate = sexp_head(list);
|
||||||
|
|
|
@ -65,6 +65,7 @@ static inline int sexp_pairp(sexp_t *x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern cmsg_bytes_t sexp_data(sexp_t *x);
|
extern cmsg_bytes_t sexp_data(sexp_t *x);
|
||||||
|
extern int sexp_cmp(sexp_t *a, sexp_t *b);
|
||||||
|
|
||||||
static inline sexp_t *sexp_head(sexp_t *x) {
|
static inline sexp_t *sexp_head(sexp_t *x) {
|
||||||
assert(x->kind == SEXP_PAIR);
|
assert(x->kind == SEXP_PAIR);
|
||||||
|
|
Loading…
Reference in New Issue