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

Function AttributeSet_Get

src/graph/entities/attribute_set.c:88–120  ·  view source on GitHub ↗

retrieves a value from set NOTE: if the key does not exist we return the special constant value ATTRIBUTE_NOTFOUND

Source from the content-addressed store, hash-verified

86// NOTE: if the key does not exist
87// we return the special constant value ATTRIBUTE_NOTFOUND
88SIValue *AttributeSet_Get
89(
90 const AttributeSet set, // set to retieve attribute from
91 Attribute_ID attr_id // attribute identifier
92) {
93 // in case attribute-set is marked as read-only, clear marker
94 AttributeSet _set = (AttributeSet)ATTRIBUTE_SET_CLEAR_MSB(set);
95
96 if(_set == NULL) {
97 return ATTRIBUTE_NOTFOUND;
98 }
99
100 if(attr_id == ATTRIBUTE_ID_NONE) {
101 return ATTRIBUTE_NOTFOUND;
102 }
103
104 // TODO: benchmark, consider alternatives:
105 // sorted set
106 // array divided in two:
107 // [attr_id_0, attr_id_1, attr_id_2, value_0, value_1, value_2]
108 for (uint16_t i = 0; i < _set->attr_count; ++i) {
109 Attribute *attr = _set->attributes + i;
110 if(attr_id == attr->id) {
111 // note, unsafe as attribute-set can get reallocated
112 // TODO: why do we return a pointer to value instead of a copy ?
113 // especially when AttributeSet_GetIdx returns SIValue
114 // note AttributeSet_Update operate on this pointer
115 return &attr->value;
116 }
117 }
118
119 return ATTRIBUTE_NOTFOUND;
120}
121
122// retrieves a value from set by index
123SIValue AttributeSet_GetIdx

Callers 7

EnforceUniqueEntityFunction · 0.85
AttributeSet_AddNoCloneFunction · 0.85
AttributeSet_AddFunction · 0.85
AttributeSet_UpdateFunction · 0.85
GraphEntity_GetPropertyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected