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

Function GraphEntity_ToString

src/graph/entities/graph_entity.c:130–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void GraphEntity_ToString
131(
132 const GraphEntity *e,
133 char **buffer,
134 size_t *bufferLen,
135 size_t *bytesWritten,
136 GraphEntityStringFormat format,
137 GraphEntityType entityType
138) {
139 // space allocation
140 if(*bufferLen - *bytesWritten < 64) {
141 *bufferLen += 64;
142 *buffer = rm_realloc(*buffer, sizeof(char) * *bufferLen);
143 }
144
145 // get open an close symbols
146 char *openSymbole;
147 char *closeSymbole;
148 if(entityType == GETYPE_NODE) {
149 openSymbole = "(";
150 closeSymbole = ")";
151 } else {
152 openSymbole = "[";
153 closeSymbole = "]";
154 }
155 *bytesWritten += snprintf(*buffer + *bytesWritten, *bufferLen, "%s", openSymbole);
156
157 // write id
158 if(format & ENTITY_ID) {
159 *bytesWritten += snprintf(*buffer + *bytesWritten, *bufferLen, "%" PRIu64, ENTITY_GET_ID(e));
160 }
161
162 // write label
163 if(format & ENTITY_LABELS_OR_RELATIONS) {
164 switch(entityType) {
165 case GETYPE_NODE: {
166 Node *n = (Node *)e;
167 GraphContext *gc = QueryCtx_GetGraphCtx();
168
169 // retrieve node labels
170 uint label_count;
171 NODE_GET_LABELS(gc->g, n, label_count);
172 for(uint i = 0; i < label_count; i ++) {
173 Schema *s = GraphContext_GetSchemaByID(gc, i, SCHEMA_NODE);
174 const char *name = Schema_GetName(s);
175
176 // allocate space if needed
177 size_t labelLen = strlen(name);
178 if(*bufferLen - *bytesWritten < labelLen) {
179 *bufferLen += labelLen;
180 *buffer = rm_realloc(*buffer, sizeof(char) * *bufferLen);
181 }
182 *bytesWritten += snprintf(*buffer + *bytesWritten, *bufferLen, ":%s", name);
183 }
184 break;
185 }
186
187 case GETYPE_EDGE: {

Callers 2

Node_ToStringFunction · 0.85
Edge_ToStringFunction · 0.85

Calls 5

rm_reallocFunction · 0.85
QueryCtx_GetGraphCtxFunction · 0.85
Schema_GetNameFunction · 0.85

Tested by

no test coverage detected