-
Notifications
You must be signed in to change notification settings - Fork 0
/
td_iterate_compare.c
39 lines (36 loc) · 1.14 KB
/
td_iterate_compare.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
** Copyright 2015 K.J. Hermans (kees.jan.hermans@gmail.com)
** This code is part of simpledbm, an API to a dbm on a finite resource.
** License: BSD
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "td_private.h"
/**
* \ingroup btree_private
*
* Compares a path (stack-) element to a given key.
* Leaves the result of the comparison in the element itself.
*
* \param td Non-NULL pointer to an initialized btree structure.
* \param elt Element containing a pointer to the current key in the path.
* \param key Non-NULL pointer to a potentially uninitialized tdt.
* \param partial Boolean. Whether or not matches are allowed to be partial.
*
* \returns Zero on success, or a TDERR_* value on error.
*/
int td_iterate_compare
(td_t* td, struct stackelt* elt, const tdt_t* key, int partial)
{
unsigned char keydata[ elt->keyhead.size - sizeof(struct keyhead) ];
tdt_t cmpkey = { keydata, sizeof(keydata) };
CHECK(td_read_keydata(td, elt->ptr, &(elt->keyhead), &cmpkey, 0));
elt->cmp = td->compare(td, key, &cmpkey, partial, td->cmparg);
if (elt->cmp < 0) {
elt->cmp = -1;
} else if (elt->cmp > 0) {
elt->cmp = 1;
}
return 0;
}