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

Function AttributeSet_Update

src/graph/entities/attribute_set.c:334–370  ·  view source on GitHub ↗

updates existing attribute, return true if attribute been updated

Source from the content-addressed store, hash-verified

332
333// updates existing attribute, return true if attribute been updated
334bool AttributeSet_Update
335(
336 AttributeSet *set, // set to update
337 Attribute_ID attr_id, // attribute identifier
338 SIValue value // new value
339) {
340 ASSERT(set != NULL);
341 ASSERT(attr_id != ATTRIBUTE_ID_NONE);
342
343 AttributeSet _set = *set;
344
345 // return if set is read-only
346 if(unlikely(ATTRIBUTE_SET_IS_READONLY(_set))) {
347 return false;
348 }
349
350 ASSERT(_set != NULL);
351
352 // setting an attribute value to NULL removes that attribute
353 if(unlikely(SIValue_IsNull(value))) {
354 return _AttributeSet_Remove(set, attr_id);
355 }
356
357 SIValue *current = AttributeSet_Get(_set, attr_id);
358 ASSERT(current != ATTRIBUTE_NOTFOUND);
359
360 // compare current value to new value, only update if current != new
361 if(unlikely(SIValue_Compare(*current, value, NULL) == 0)) {
362 return false;
363 }
364
365 // value != current, update entity
366 SIValue_Free(*current); // free previous value
367 *current = SI_CloneValue(value);
368
369 return true;
370}
371
372// clones attribute-set without SI values
373AttributeSet AttributeSet_ShallowClone

Callers 1

Calls 6

SIValue_IsNullFunction · 0.85
_AttributeSet_RemoveFunction · 0.85
AttributeSet_GetFunction · 0.85
SIValue_CompareFunction · 0.85
SIValue_FreeFunction · 0.85
SI_CloneValueFunction · 0.85

Tested by

no test coverage detected