MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / SIArray_Compare

Function SIArray_Compare

src/value.c:533–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

531}
532
533int SIArray_Compare(SIValue arrayA, SIValue arrayB, int *disjointOrNull) {
534 uint arrayALen = SIArray_Length(arrayA);
535 uint arrayBLen = SIArray_Length(arrayB);
536 // Check empty list.
537 if(arrayALen == 0 && arrayBLen == 0) return 0;
538 int lenDiff = arrayALen - arrayBLen;
539 // Check for the common range of indices.
540 uint minLength = arrayALen <= arrayBLen ? arrayALen : arrayBLen;
541 // notEqual holds the first false (result != 0) comparison result between two values from the same type, which are not equal.
542 int notEqual = 0;
543 uint nullCounter = 0; // Counter for the amount of null comparison.
544 uint notEqualCounter = 0; // Counter for the amount of false (compare(a,b) !=0) comparisons.
545
546 // Go over the common range for both arrays.
547 for(uint i = 0; i < minLength; i++) {
548 SIValue aValue = SIArray_Get(arrayA, i);
549 SIValue bValue = SIArray_Get(arrayB, i);
550 // Current comparison special cases indication variable.
551 int currentDisjointOrNull = 0;
552 int compareResult = SIValue_Compare(aValue, bValue, &currentDisjointOrNull);
553 // In case of special case such null or disjoint comparison.
554 if(currentDisjointOrNull) {
555 if(currentDisjointOrNull == COMPARED_NULL) nullCounter++; // Update null comparison counter.
556 // Null or disjoint comparison is also a false comparison, so increase the number of false comparisons in one.
557 notEqualCounter++;
558 // Set the first difference value, if not set before.
559 if(notEqual == 0) notEqual = compareResult;
560 } else if(compareResult != 0) {
561 // In the normal false comparison case, update false comparison counter.
562 notEqualCounter++;
563 // Set the first difference value, if not set before.
564 if(notEqual == 0) notEqual = compareResult;
565 }
566 // Note: In the case of compareResult = 0, there is nothing to be done.
567 }
568 // If all the elements in the shared range yielded false comparisons.
569 if(notEqualCounter == minLength && notEqualCounter > nullCounter) return notEqual;
570 // If there was a null comperison on non disjoint arrays.
571 if(nullCounter && arrayALen == arrayBLen) {
572 if(disjointOrNull) *disjointOrNull = COMPARED_NULL;
573 return notEqual;
574 }
575 // If there was a difference in some member, without any null compare.
576 if(notEqual) return notEqual;
577 // In this state, the common range is equal. We return lenDiff, which is 0 in case the lists are equal, and not 0 otherwise.
578 return lenDiff;
579}
580
581int SIValue_Compare(const SIValue a, const SIValue b, int *disjointOrNull) {
582

Callers 1

SIValue_CompareFunction · 0.85

Calls 3

SIArray_LengthFunction · 0.85
SIArray_GetFunction · 0.85
SIValue_CompareFunction · 0.85

Tested by

no test coverage detected