MCPcopy Create free account
hub / github.com/ElementsProject/lightning / closest

Function closest

ccan/ccan/strset/strset.c:36–58  ·  view source on GitHub ↗

Closest member to this in a non-empty set. */

Source from the content-addressed store, hash-verified

34
35/* Closest member to this in a non-empty set. */
36static const char *closest(struct strset n, const char *member)
37{
38 size_t len = strlen(member);
39 const u8 *bytes = (const u8 *)member;
40
41 /* Anything with first byte 0 is a node. */
42 while (!n.u.s[0]) {
43 u8 direction = 0;
44
45 /* Special node which represents the empty string. */
46 if (unlikely(n.u.n->byte_num == (size_t)-1)) {
47 n = n.u.n->child[0];
48 break;
49 }
50
51 if (n.u.n->byte_num < len) {
52 u8 c = bytes[n.u.n->byte_num];
53 direction = (c >> n.u.n->bit_num) & 1;
54 }
55 n = n.u.n->child[direction];
56 }
57 return n.u.s;
58}
59
60char *strset_get(const struct strset *set, const char *member)
61{

Callers 2

strset_getFunction · 0.70
strset_addFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected