Skip to content

Commit

Permalink
ndb_filter_{eq,is_subset_of}: make interfaces const
Browse files Browse the repository at this point in the history
this makes rust happier

Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed Nov 3, 2024
1 parent 78f9ef0 commit 7365c20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/nostrdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2672,7 +2672,7 @@ ndb_filter_find_elements(struct ndb_filter *filter, enum ndb_filter_fieldtype ty
return NULL;
}

int ndb_filter_is_subset_of(struct ndb_filter *a, struct ndb_filter *b)
int ndb_filter_is_subset_of(const struct ndb_filter *a, const struct ndb_filter *b)
{
int i;
struct ndb_filter_elements *b_field, *a_field;
Expand Down Expand Up @@ -2700,20 +2700,22 @@ int ndb_filter_is_subset_of(struct ndb_filter *a, struct ndb_filter *b)
// A is a subset of B because `k:1` and `a:b` both exist in A

for (i = 0; i < b->num_elements; i++) {
b_field = ndb_filter_get_elements(b, i);
a_field = ndb_filter_find_elements(a, b_field->field.type);
b_field = ndb_filter_get_elements((struct ndb_filter*)b, i);
a_field = ndb_filter_find_elements((struct ndb_filter*)a,
b_field->field.type);

if (a_field == NULL)
return 0;

if (!ndb_filter_field_eq(a, a_field, b, b_field))
if (!ndb_filter_field_eq((struct ndb_filter*)a, a_field,
(struct ndb_filter*)b, b_field))
return 0;
}

return 1;
}

int ndb_filter_eq(struct ndb_filter *a, struct ndb_filter *b)
int ndb_filter_eq(const struct ndb_filter *a, const struct ndb_filter *b)
{
int i;
struct ndb_filter_elements *a_els, *b_els;
Expand All @@ -2722,13 +2724,15 @@ int ndb_filter_eq(struct ndb_filter *a, struct ndb_filter *b)
return 0;

for (i = 0; i < a->num_elements; i++) {
a_els = ndb_filter_get_elements(a, i);
b_els = ndb_filter_find_elements(b, a_els->field.type);
a_els = ndb_filter_get_elements((struct ndb_filter*)a, i);
b_els = ndb_filter_find_elements((struct ndb_filter *)b,
a_els->field.type);

if (b_els == NULL)
return 0;

if (!ndb_filter_field_eq(a, a_els, b, b_els))
if (!ndb_filter_field_eq((struct ndb_filter*)a, a_els,
(struct ndb_filter*)b, b_els))
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/nostrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,10 @@ int ndb_filter_init(struct ndb_filter *);
int ndb_filter_add_id_element(struct ndb_filter *, const unsigned char *id);
int ndb_filter_add_int_element(struct ndb_filter *, uint64_t integer);
int ndb_filter_add_str_element(struct ndb_filter *, const char *str);
int ndb_filter_eq(struct ndb_filter *, struct ndb_filter *);
int ndb_filter_eq(const struct ndb_filter *, const struct ndb_filter *);

/// is `a` a subset of `b`
int ndb_filter_is_subset_of(struct ndb_filter *a, struct ndb_filter *b);
int ndb_filter_is_subset_of(const struct ndb_filter *a, const struct ndb_filter *b);

// filters from json
int ndb_filter_from_json(const char *, int len, struct ndb_filter *filter, unsigned char *buf, int bufsize);
Expand Down

0 comments on commit 7365c20

Please sign in to comment.