MCPcopy Create free account
hub / github.com/documentdb/documentdb / CompareBsonIter

Function CompareBsonIter

pg_documentdb_core/src/query/bson_compare.c:339–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337
338
339int
340CompareBsonIter(bson_iter_t *leftIter, bson_iter_t *rightIter, bool compareFields, const
341 char *collationString)
342{
343 check_stack_depth();
344 while (true)
345 {
346 bool leftNext = bson_iter_next(leftIter);
347 bool rightNext = bson_iter_next(rightIter);
348 int32_t cmp;
349
350 if (!leftNext && !rightNext)
351 {
352 /* both reached the end, they must be equal. */
353 return 0;
354 }
355 else if (!leftNext || !rightNext)
356 {
357 /* one of them ended, not equal. */
358 /* if left has more, then left > right -> 1 */
359 /* if left ended, then right > left -> -1. */
360 return leftNext ? 1 : -1;
361 }
362
363 StringView leftKey = bson_iter_key_string_view(leftIter);
364 StringView rightKey = bson_iter_key_string_view(rightIter);
365
366 const bson_value_t *leftValue = bson_iter_value(leftIter);
367 const bson_value_t *rightValue = bson_iter_value(rightIter);
368
369 if (!compareFields)
370 {
371 leftKey.length = 0;
372 rightKey.length = 0;
373 }
374
375 /* they both have values compare typeCode. */
376 cmp = CompareBsonSortOrderType(leftValue, rightValue);
377 if (cmp != 0)
378 {
379 return cmp;
380 }
381
382 /* next compare field name. */
383 const char *collationStringIgnore = NULL;
384 cmp = CompareStrings(leftKey.string, leftKey.length,
385 rightKey.string, rightKey.length,
386 collationStringIgnore);
387 if (cmp != 0)
388 {
389 return cmp;
390 }
391
392 bool ignoreIsComparisonValid;
393 cmp = CompareBsonValue(leftValue, rightValue,
394 &ignoreIsComparisonValid, collationString);
395 if (cmp != 0)
396 {

Callers 2

ComparePgbsonFunction · 0.85
CompareBsonValueFunction · 0.85

Calls 4

CompareBsonSortOrderTypeFunction · 0.85
CompareStringsFunction · 0.85
CompareBsonValueFunction · 0.85

Tested by

no test coverage detected