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

Function AR_TOMAP

src/arithmetic/map_funcs/map_funcs.c:16–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include "../../graph/entities/graph_entity.h"
15
16SIValue AR_TOMAP(SIValue *argv, int argc, void *private_data) {
17 /* create a new SIMap object
18 * expecting an even number of arguments
19 * argv[even] = key
20 * argv[odd] = value */
21
22 // validate number of arguments
23 if(argc % 2 != 0) {
24 ErrorCtx_RaiseRuntimeException("map expects even number of elements");
25 }
26
27 SIValue map = SI_Map(argc / 2);
28
29 for(int i = 0; i < argc; i += 2) {
30 SIValue key = argv[i];
31 SIValue val = argv[i + 1];
32
33 // make sure key is a string
34 if(!(SI_TYPE(key) & T_STRING)) {
35 Error_SITypeMismatch(key, T_STRING);
36 break;
37 }
38
39 Map_Add(&map, key, val);
40 }
41
42 return map;
43}
44
45SIValue AR_KEYS(SIValue *argv, int argc, void *private_data) {
46 ASSERT(argc == 1);

Callers

nothing calls this directly

Calls 4

SI_MapFunction · 0.85
Error_SITypeMismatchFunction · 0.85
Map_AddFunction · 0.85

Tested by

no test coverage detected