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

Function AR_RANGE

src/arithmetic/list_funcs/list_funcs.c:329–354  ·  view source on GitHub ↗

Create a new list of integers in the range of [start, end]. If a step was given the step between two consecutive list members will be this step. If step was not suppllied, it will be default as 1 "RETURN range(3,8,2)" will yield [3, 5, 7] */

Source from the content-addressed store, hash-verified

327 If step was not suppllied, it will be default as 1
328 "RETURN range(3,8,2)" will yield [3, 5, 7] */
329SIValue AR_RANGE(SIValue *argv, int argc, void *private_data) {
330 int64_t start = argv[0].longval;
331 int64_t end = argv[1].longval;
332 int64_t interval = 1;
333 if(argc == 3) {
334 ASSERT(SI_TYPE(argv[2]) == T_INT64);
335 interval = argv[2].longval;
336 if(interval == 0) {
337 ErrorCtx_RaiseRuntimeException("ArgumentError: step argument to range() can't be 0");
338 // Incase expection handler wasn't set, return NULL.
339 return SI_NullVal();
340 }
341 }
342
343 uint64_t size = 0;
344 if((end >= start && interval > 0) || (end <= start && interval < 0)) {
345 size = 1 + (end - start) / interval;
346 }
347
348 SIValue array = SI_Array(size);
349 for(uint64_t i = 0; i < size; i++) {
350 SIArray_Append(&array, SI_LongVal(start));
351 start += interval;
352 }
353 return array;
354}
355
356/* Checks if a value is in a given list.
357 "RETURN 3 IN [1, 2, 3]" will return true */

Callers

nothing calls this directly

Calls 5

SI_NullValFunction · 0.85
SI_ArrayFunction · 0.85
SIArray_AppendFunction · 0.85
SI_LongValFunction · 0.85

Tested by

no test coverage detected