MINOR: pattern: add pat_ref_gen_set() function

pat_ref_gen_set(ref, gen_id, value, err) modifies to <value> the sample
of all patterns matching <key> and belonging to <gen_id> (generation id)
under <ref>

The goal is to be able to target a single subset from <ref>
This commit is contained in:
Aurelien DARRAGON 2024-11-20 17:30:39 +01:00
parent 3d250b3be8
commit c9d6af3c6d
2 changed files with 21 additions and 0 deletions

View File

@ -190,6 +190,7 @@ int pat_ref_push(struct pat_ref_elt *elt, struct pattern_expr *expr, int patflag
int pat_ref_add(struct pat_ref *ref, const char *pattern, const char *sample, char **err);
int pat_ref_set(struct pat_ref *ref, const char *pattern, const char *sample, char **err);
int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value, char **err);
int pat_ref_gen_set(struct pat_ref *ref, unsigned int gen_id, const char *key, const char *value, char **err);
int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const char *value, char **err);
int pat_ref_delete(struct pat_ref *ref, const char *key);
void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt);

View File

@ -1788,6 +1788,26 @@ int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, cons
return pat_ref_set_from_node(ref, &elt->node, value, err);
}
/* This function modifies to <value> the sample of all patterns matching <key>
* and belonging to <gen_id> under <ref>.
*/
int pat_ref_gen_set(struct pat_ref *ref, unsigned int gen_id,
const char *key, const char *value, char **err)
{
struct ebmb_node *node;
struct pat_ref_elt *elt;
/* Look for pattern in the reference. */
node = ebst_lookup(&ref->ebmb_root, key);
while (node) {
elt = ebmb_entry(node, struct pat_ref_elt, node);
if (elt->gen_id == gen_id)
break;
node = ebmb_next_dup(node);
}
return pat_ref_set_from_node(ref, node, value, err);
}
/* This function modifies to <value> the sample of all patterns matching <key>
* under <ref>.
*/