Skip to content

Commit

Permalink
Show filter example
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Nov 4, 2024
1 parent 991e953 commit 37bc853
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,25 @@ while (users_iter_valid(&iter)) {
users_iter_release(&iter);
```
It's usually not safe to modify the btree while iterating.
If you need to filter data then it's best to reset the iterator after
each modification.
```c
struct users_iter iter;
users_iter_init(&users, &iter, 0);
users_iter_scan(&iter);
while (users_iter_valid(&iter)) {
users_iter_item(&iter, &user);
if (user.age >= 30 && user.age < 40) {
users_delete(&users, user, 0, 0);
users_iter_seek(&iter, user);
continue;
}
users_iter_next(&iter);
}
```
## Status codes
Most btree operations, such as `bt_get()` and `bt_insert()` return status
Expand Down

0 comments on commit 37bc853

Please sign in to comment.