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

Function SIValue_Compare

src/value.c:581–648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

579}
580
581int SIValue_Compare(const SIValue a, const SIValue b, int *disjointOrNull) {
582
583 /* No special case (null or disjoint comparison) happened yet.
584 * If indication for such cases is required, first set the indication value to zero (not happen). */
585 if(disjointOrNull) *disjointOrNull = 0;
586
587 /* In order to be comparable, both SIValues must be from the same type. */
588 if(a.type == b.type) {
589 switch(a.type) {
590 case T_INT64:
591 case T_BOOL:
592 return SAFE_COMPARISON_RESULT(a.longval - b.longval);
593 case T_DOUBLE:
594 if(isnan(a.doubleval) || isnan(b.doubleval)) {
595 if(disjointOrNull) *disjointOrNull = COMPARED_NAN;
596 }
597
598 return SAFE_COMPARISON_RESULT(a.doubleval - b.doubleval);
599 case T_STRING:
600 return strcmp(a.stringval, b.stringval);
601 case T_NODE:
602 case T_EDGE:
603 return ENTITY_GET_ID((GraphEntity *)a.ptrval) - ENTITY_GET_ID((GraphEntity *)b.ptrval);
604 case T_ARRAY:
605 return SIArray_Compare(a, b, disjointOrNull);
606 case T_PATH:
607 return SIPath_Compare(a, b);
608 case T_MAP:
609 return Map_Compare(a, b, disjointOrNull);
610 case T_NULL:
611 break;
612 case T_POINT:
613 {
614 int lon_diff = SAFE_COMPARISON_RESULT(Point_lon(a) - Point_lon(b));
615 if(lon_diff == 0)
616 return SAFE_COMPARISON_RESULT(Point_lat(a) - Point_lat(b));
617 return lon_diff;
618 }
619 default:
620 // Both inputs were of an incomparable type, like a pointer, or not implemented comparison yet.
621 ASSERT(false);
622 break;
623 }
624 }
625
626 /* The inputs have different SITypes - compare them if they
627 * are both numerics of differing types. */
628 if(SI_TYPE(a) & SI_NUMERIC && SI_TYPE(b) & SI_NUMERIC) {
629 if(isnan(SI_GET_NUMERIC(a)) || isnan(SI_GET_NUMERIC(b))) {
630 if(disjointOrNull) *disjointOrNull = COMPARED_NAN;
631 }
632
633 double diff = SI_GET_NUMERIC(a) - SI_GET_NUMERIC(b);
634 return SAFE_COMPARISON_RESULT(diff);
635 }
636
637 // Check if either type is null.
638 if(a.type == T_NULL || b.type == T_NULL) {

Callers 15

SIArray_CompareFunction · 0.85
_applyFilterFunction · 0.85
AGG_MINFunction · 0.85
AGG_MAXFunction · 0.85
AR_CASEWHENFunction · 0.85
AR_GTFunction · 0.85
AR_GEFunction · 0.85
AR_LTFunction · 0.85
AR_LEFunction · 0.85
AR_EQFunction · 0.85
AR_NEFunction · 0.85

Calls 5

SIArray_CompareFunction · 0.85
SIPath_CompareFunction · 0.85
Map_CompareFunction · 0.85
Point_lonFunction · 0.85
Point_latFunction · 0.85

Tested by

no test coverage detected