File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,18 @@ mongoc_set_for_each (mongoc_set_t *set,
84
84
mongoc_set_for_each_cb_t cb ,
85
85
void * ctx );
86
86
87
+ /* first item in set for which "cb" returns true */
88
+ void *
89
+ mongoc_set_find_item (mongoc_set_t * set ,
90
+ mongoc_set_for_each_cb_t cb ,
91
+ void * ctx );
92
+
93
+ /* id of first item in set for which "cb" returns true, or 0. */
94
+ uint32_t
95
+ mongoc_set_find_id (mongoc_set_t * set ,
96
+ mongoc_set_for_each_cb_t cb ,
97
+ void * ctx );
98
+
87
99
BSON_END_DECLS
88
100
89
101
#endif /* MONGOC_SET_PRIVATE_H */
Original file line number Diff line number Diff line change @@ -163,3 +163,55 @@ mongoc_set_for_each (mongoc_set_t *set,
163
163
164
164
bson_free (old_set );
165
165
}
166
+
167
+
168
+ static mongoc_set_item_t *
169
+ _mongoc_set_find (mongoc_set_t * set ,
170
+ mongoc_set_for_each_cb_t cb ,
171
+ void * ctx )
172
+ {
173
+ size_t i ;
174
+ size_t items_len ;
175
+ mongoc_set_item_t * item ;
176
+
177
+ items_len = set -> items_len ;
178
+
179
+ for (i = 0 ; i < items_len ; i ++ ) {
180
+ item = & set -> items [i ];
181
+ if (cb (item -> item , ctx )) {
182
+ return item ;
183
+ }
184
+ }
185
+
186
+ return NULL ;
187
+ }
188
+
189
+
190
+ void *
191
+ mongoc_set_find_item (mongoc_set_t * set ,
192
+ mongoc_set_for_each_cb_t cb ,
193
+ void * ctx )
194
+ {
195
+ mongoc_set_item_t * item ;
196
+
197
+ if ((item = _mongoc_set_find (set , cb , ctx ))) {
198
+ return item -> item ;
199
+ }
200
+
201
+ return NULL ;
202
+ }
203
+
204
+
205
+ uint32_t
206
+ mongoc_set_find_id (mongoc_set_t * set ,
207
+ mongoc_set_for_each_cb_t cb ,
208
+ void * ctx )
209
+ {
210
+ mongoc_set_item_t * item ;
211
+
212
+ if ((item = _mongoc_set_find (set , cb , ctx ))) {
213
+ return item -> id ;
214
+ }
215
+
216
+ return 0 ;
217
+ }
You can’t perform that action at this time.
0 commit comments