Skip to content

Commit 7365c20

Browse files
committed
ndb_filter_{eq,is_subset_of}: make interfaces const
this makes rust happier Signed-off-by: William Casarin <[email protected]>
1 parent 78f9ef0 commit 7365c20

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/nostrdb.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ ndb_filter_find_elements(struct ndb_filter *filter, enum ndb_filter_fieldtype ty
26722672
return NULL;
26732673
}
26742674

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

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

27062707
if (a_field == NULL)
27072708
return 0;
27082709

2709-
if (!ndb_filter_field_eq(a, a_field, b, b_field))
2710+
if (!ndb_filter_field_eq((struct ndb_filter*)a, a_field,
2711+
(struct ndb_filter*)b, b_field))
27102712
return 0;
27112713
}
27122714

27132715
return 1;
27142716
}
27152717

2716-
int ndb_filter_eq(struct ndb_filter *a, struct ndb_filter *b)
2718+
int ndb_filter_eq(const struct ndb_filter *a, const struct ndb_filter *b)
27172719
{
27182720
int i;
27192721
struct ndb_filter_elements *a_els, *b_els;
@@ -2722,13 +2724,15 @@ int ndb_filter_eq(struct ndb_filter *a, struct ndb_filter *b)
27222724
return 0;
27232725

27242726
for (i = 0; i < a->num_elements; i++) {
2725-
a_els = ndb_filter_get_elements(a, i);
2726-
b_els = ndb_filter_find_elements(b, a_els->field.type);
2727+
a_els = ndb_filter_get_elements((struct ndb_filter*)a, i);
2728+
b_els = ndb_filter_find_elements((struct ndb_filter *)b,
2729+
a_els->field.type);
27272730

27282731
if (b_els == NULL)
27292732
return 0;
27302733

2731-
if (!ndb_filter_field_eq(a, a_els, b, b_els))
2734+
if (!ndb_filter_field_eq((struct ndb_filter*)a, a_els,
2735+
(struct ndb_filter*)b, b_els))
27322736
return 0;
27332737
}
27342738

src/nostrdb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,10 @@ int ndb_filter_init(struct ndb_filter *);
495495
int ndb_filter_add_id_element(struct ndb_filter *, const unsigned char *id);
496496
int ndb_filter_add_int_element(struct ndb_filter *, uint64_t integer);
497497
int ndb_filter_add_str_element(struct ndb_filter *, const char *str);
498-
int ndb_filter_eq(struct ndb_filter *, struct ndb_filter *);
498+
int ndb_filter_eq(const struct ndb_filter *, const struct ndb_filter *);
499499

500500
/// is `a` a subset of `b`
501-
int ndb_filter_is_subset_of(struct ndb_filter *a, struct ndb_filter *b);
501+
int ndb_filter_is_subset_of(const struct ndb_filter *a, const struct ndb_filter *b);
502502

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

0 commit comments

Comments
 (0)