Skip to content

Commit

Permalink
vxlan: Add utility functions to the simap data structure.
Browse files Browse the repository at this point in the history
Add utility functions to the simap structure. These are
used by future patches in this seris. The functions added are.

Signed-off-by: Kyle Mestery <[email protected]>
Acked-by: Ethan Jackson <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
mestery authored and blp committed Feb 14, 2013
1 parent b2c9b58 commit bcac5b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/simap.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ simap_delete(struct simap *simap, struct simap_node *node)
free(node);
}

/* Searches for 'name' in 'simap'. If found, deletes it and returns true. If
* not found, returns false without modifying 'simap'. */
bool
simap_find_and_delete(struct simap *simap, const char *name)
{
struct simap_node *node = simap_find(simap, name);
if (node) {
simap_delete(simap, node);
return true;
}
return false;
}

/* Searches 'simap' for a mapping with the given 'name'. Returns it, if found,
* or a null pointer if not. */
struct simap_node *
Expand All @@ -172,6 +185,13 @@ simap_get(const struct simap *simap, const char *name)
return node ? node->data : 0;
}

/* Returns true if 'simap' contains a copy of 'name', false otherwise. */
bool
simap_contains(const struct simap *simap, const char *name)
{
return simap_find(simap, name) != NULL;
}

/* Returns an array that contains a pointer to each mapping in 'simap',
* ordered alphabetically by name. The returned array has simap_count(simap)
* elements.
Expand Down
2 changes: 2 additions & 0 deletions lib/simap.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ unsigned int simap_get(const struct simap *, const char *);
struct simap_node *simap_find(const struct simap *, const char *);
struct simap_node *simap_find_len(const struct simap *,
const char *, size_t len);
bool simap_contains(const struct simap *, const char *);

void simap_delete(struct simap *, struct simap_node *);
bool simap_find_and_delete(struct simap *, const char *);

const struct simap_node **simap_sort(const struct simap *);

Expand Down

0 comments on commit bcac5b7

Please sign in to comment.