MCPcopy Create free account
hub / github.com/apache/madlib / sparsedata_eq_zero_is_equal

Function sparsedata_eq_zero_is_equal

methods/svec/src/pg_gp/SparseData.c:858–906  ·  view source on GitHub ↗

Checks the equality of two SparseData. We can't assume that two * SparseData are in canonical form. * * The algorithm is simple: we traverse the left SparseData element by * element, and for each such element x, we traverse all the elements of * the right SparseData that overlaps with x and check that they are equal. * * Unlike sparsedata_eq, this function assumes that any zero represents a

Source from the content-addressed store, hash-verified

856 * Note: This function only works on SparseData of float8s at present.
857 */
858bool sparsedata_eq_zero_is_equal(SparseData left, SparseData right)
859{
860 char * ix = left->index->data;
861 double* vals = (double *)left->vals->data;
862
863 char * rix = right->index->data;
864 double* rvals = (double *)right->vals->data;
865
866 int read = 0, rread = 0;
867 int i=-1, j=-1, minimum = 0;
868 minimum = (left->total_value_count > right->total_value_count) ?
869 right->total_value_count : left->total_value_count;
870
871 for (;(read < minimum)||(rread < minimum);) {
872 if (read < rread) {
873 read += (int)compword_to_int8(ix);
874 ix +=int8compstoragesize(ix);
875 i++;
876 if ((memcmp(&(vals[i]),&(rvals[j]),sizeof(float8))!=0) &&
877 (vals[i]!=0.0)&&(rvals[j]!=0.0)) {
878 return false;
879 }
880 } else if (read > rread){
881 rread += (int)compword_to_int8(rix);
882 rix+=int8compstoragesize(rix);
883 j++;
884 if ((memcmp(&(vals[i]),&(rvals[j]),sizeof(float8))!=0) &&
885 (vals[i]!=0.0)&&(rvals[j]!=0.0)) {
886 return false;
887 }
888 } else {
889 read += (int)compword_to_int8(ix);
890 rread += (int)compword_to_int8(rix);
891 ix +=int8compstoragesize(ix);
892 rix+=int8compstoragesize(rix);
893 i++;
894 j++;
895 if ((memcmp(&(vals[i]),&(rvals[j]),sizeof(float8))!=0) &&
896 (vals[i]!=0.0)&&(rvals[j]!=0.0)) {
897 return false;
898 }
899 }
900 }
901 /*sprintf(result, "result after %d %f", j, rvals[j]);
902 ereport(NOTICE,
903 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
904 errmsg(result)));*/
905 return true;
906}
907
908/* Checks if one SparseData object contained in another
909 *

Callers 1

svec_eq_non_zeroFunction · 0.85

Calls 1

compword_to_int8Function · 0.85

Tested by

no test coverage detected