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

Function _AttributeSet_Remove

src/graph/entities/attribute_set.c:28–72  ·  view source on GitHub ↗

removes an attribute from set

Source from the content-addressed store, hash-verified

26
27// removes an attribute from set
28static bool _AttributeSet_Remove
29(
30 AttributeSet *set,
31 Attribute_ID attr_id
32) {
33 AttributeSet _set = *set;
34 const uint16_t attr_count = _set->attr_count;
35
36 // attribute-set can't be read-only
37 ASSERT(ATTRIBUTE_SET_IS_READONLY(_set) == false);
38
39 // locate attribute position
40 for (uint16_t i = 0; i < attr_count; ++i) {
41 if(attr_id != _set->attributes[i].id) {
42 continue;
43 }
44
45 // if this is the last attribute free the attribute-set
46 if(_set->attr_count == 1) {
47 AttributeSet_Free(set);
48 return true;
49 }
50
51 // attribute located
52 // free attribute value
53 SIValue_Free(_set->attributes[i].value);
54
55 // overwrite deleted attribute with the last
56 // attribute and shrink set
57 _set->attributes[i] = _set->attributes[attr_count - 1];
58
59 // update attribute count
60 --_set->attr_count;
61
62 // compute new set size
63 size_t n = ATTRIBUTESET_BYTE_SIZE(_set);
64 *set = rm_realloc(_set, n);
65
66 // attribute removed
67 return true;
68 }
69
70 // unable to locate attribute
71 return false;
72}
73
74// returns number of attributes within the set
75uint16_t AttributeSet_Count

Callers 2

AttributeSet_UpdateFunction · 0.85

Calls 3

AttributeSet_FreeFunction · 0.85
SIValue_FreeFunction · 0.85
rm_reallocFunction · 0.85

Tested by

no test coverage detected