| 320 | } |
| 321 | |
| 322 | void UpdateNodeLabels |
| 323 | ( |
| 324 | GraphContext *gc, // graph context to update the entity |
| 325 | Node *node, // the node to be updated |
| 326 | const char **add_labels, // labels to add to the node |
| 327 | const char **remove_labels, // labels to add to the node |
| 328 | uint n_add_labels, // number of labels to add |
| 329 | uint n_remove_labels, // number of labels to remove |
| 330 | bool log // log this operation in undo-log |
| 331 | ) { |
| 332 | ASSERT(gc != NULL); |
| 333 | ASSERT(node != NULL); |
| 334 | |
| 335 | // quick return if there are no labels |
| 336 | if(add_labels == NULL && remove_labels == NULL) { |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | // if add_labels is specified its count must be > 0 |
| 341 | ASSERT((add_labels != NULL && n_add_labels > 0) || |
| 342 | (add_labels == NULL && n_add_labels == 0)); |
| 343 | |
| 344 | // if remove_labels is specified its count must be > 0 |
| 345 | ASSERT((remove_labels != NULL && n_remove_labels > 0) || |
| 346 | (remove_labels == NULL && n_remove_labels == 0)); |
| 347 | |
| 348 | EffectsBuffer *eb = NULL; |
| 349 | UndoLog undo_log = NULL; |
| 350 | |
| 351 | if(log == true) { |
| 352 | eb = QueryCtx_GetEffectsBuffer(); |
| 353 | undo_log = QueryCtx_GetUndoLog(); |
| 354 | } |
| 355 | |
| 356 | if(add_labels != NULL) { |
| 357 | int add_labels_ids[n_add_labels]; |
| 358 | uint add_labels_index = 0; |
| 359 | |
| 360 | for (uint i = 0; i < n_add_labels; i++) { |
| 361 | const char *label = add_labels[i]; |
| 362 | // get or create label matrix |
| 363 | const Schema *s = GraphContext_GetSchema(gc, label, SCHEMA_NODE); |
| 364 | bool schema_created = false; |
| 365 | if(s == NULL) { |
| 366 | s = AddSchema(gc, label, SCHEMA_NODE, log); |
| 367 | schema_created = true; |
| 368 | } |
| 369 | |
| 370 | int schema_id = Schema_GetID(s); |
| 371 | bool node_labeled = Graph_IsNodeLabeled(gc->g, ENTITY_GET_ID(node), |
| 372 | schema_id); |
| 373 | |
| 374 | if(!node_labeled) { |
| 375 | // sync matrix |
| 376 | // make sure label matrix is of the right dimensions |
| 377 | if(schema_created) { |
| 378 | RG_Matrix m = Graph_GetLabelMatrix(gc->g, schema_id); |
| 379 | } |
no test coverage detected