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

Function _AR_NodeDegree

src/arithmetic/entity_funcs/entity_funcs.c:144–211  ·  view source on GitHub ↗

returns node incoming/outgoing degree

Source from the content-addressed store, hash-verified

142
143// returns node incoming/outgoing degree
144static SIValue _AR_NodeDegree
145(
146 SIValue *argv,
147 int argc,
148 GRAPH_EDGE_DIR dir // edge direction
149) {
150 ASSERT(SI_TYPE(argv[0]) != T_NULL);
151
152 Node *n = (Node*)argv[0].ptrval;
153 uint64_t count = 0;
154 GraphContext *gc = QueryCtx_GetGraphCtx();
155
156 if(argc > 1) {
157 // we're interested in specific relationship type(s)
158
159 // get labels array from input arguments, but removing duplicates
160 SIValue labels = SI_EmptyArray();
161 if(SI_TYPE(argv[1]) == T_STRING) {
162 // validate signature function(NODE, STR_0, STR_1, ... STR_N)
163 for(int i = 1; i < argc; i++) {
164 if(SI_TYPE(argv[i]) == T_STRING) {
165 if(SIArray_ContainsValue(labels, argv[i], NULL) == false) {
166 SIArray_Append(&labels, argv[i]);
167 }
168 } else {
169 Error_SITypeMismatch(argv[i], T_STRING);
170 }
171 }
172 } else if (SI_TYPE(argv[1]) == T_ARRAY) {
173 if(argc > 2) {
174 ErrorCtx_SetError("Received %d arguments, expected at most 2 because second argument is List", argc);
175 }
176 // validate signature function(NODE, ARRAY_OF_STRINGS)
177 uint len = SIArray_Length(argv[1]);
178 for(int j = 0; j < len; j++) {
179 SIValue elem = SIArray_Get(argv[1], j);
180 if(SI_TYPE(elem) != T_STRING) {
181 SIArray_Free(labels);
182 Error_SITypeMismatch(elem, T_STRING);
183 return SI_NullVal();
184 }
185 if(SIArray_ContainsValue(labels, elem, NULL) == false) {
186 SIArray_Append(&labels, elem);
187 }
188 }
189 }
190 uint len = SIArray_Length(labels);
191 for(int i = 0; i < len; i++) {
192 SIValue elem = SIArray_Get(labels, i);
193 const char *label = elem.stringval;
194 // make sure relationship exists.
195 Schema *s = GraphContext_GetSchema(gc, label, SCHEMA_EDGE);
196 if(s == NULL) {
197 continue;
198 }
199
200 // count edges
201 count += Graph_GetNodeDegree(gc->g, n, dir, s->id);

Callers 2

AR_INCOMEDEGREEFunction · 0.85
AR_OUTGOINGDEGREEFunction · 0.85

Calls 13

QueryCtx_GetGraphCtxFunction · 0.85
SI_EmptyArrayFunction · 0.85
SIArray_ContainsValueFunction · 0.85
SIArray_AppendFunction · 0.85
Error_SITypeMismatchFunction · 0.85
ErrorCtx_SetErrorFunction · 0.85
SIArray_LengthFunction · 0.85
SIArray_GetFunction · 0.85
SIArray_FreeFunction · 0.85
SI_NullValFunction · 0.85
GraphContext_GetSchemaFunction · 0.85
Graph_GetNodeDegreeFunction · 0.85

Tested by

no test coverage detected