Skip to content

Commit

Permalink
filter: use binary search for large contact list filters
Browse files Browse the repository at this point in the history
This is much more efficient than linear scans
  • Loading branch information
jb55 committed Jan 4, 2024
1 parent 73e2306 commit e749479
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/nostrdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,17 +845,18 @@ int ndb_filter_matches(struct ndb_filter *filter, struct ndb_note *note)
goto cont;
}
break;
// TODO: add filter hashtable for large id lists
case NDB_FILTER_IDS:
for (j = 0; j < els->count; j++) {
if (!memcmp(els->elements[j].id, note->id, 32))
goto cont;
unsigned char *id = note->id;
if (bsearch(&id, &els->elements[0], els->count,
sizeof(els->elements[0].id), compare_ids)) {
goto cont;
}
break;
case NDB_FILTER_AUTHORS:
for (j = 0; j < els->count; j++) {
if (!memcmp(els->elements[j].id, note->pubkey, 32))
goto cont;
unsigned char *pubkey = note->pubkey;
if (bsearch(&pubkey, &els->elements[0], els->count,
sizeof(els->elements[0].id), compare_ids)) {
goto cont;
}
break;
case NDB_FILTER_GENERIC:
Expand Down

0 comments on commit e749479

Please sign in to comment.