Skip to content

Commit

Permalink
simap: Add utility function to help compare two simaps.
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Pfaff <[email protected]>
Signed-off-by: Justin Pettit <[email protected]>
  • Loading branch information
blp authored and justinpettit committed Sep 26, 2019
1 parent 1f16131 commit 6a16962
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/simap.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2017 Nicira, Inc.
* Copyright (c) 2009, 2010, 2011, 2012, 2017, 2019 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -242,6 +242,19 @@ simap_equal(const struct simap *a, const struct simap *b)
return true;
}

uint32_t
simap_hash(const struct simap *simap)
{
uint32_t hash = 0;

const struct simap_node *node;
SIMAP_FOR_EACH (node, simap) {
hash ^= hash_int(node->data,
hash_name(node->name, strlen(node->name)));
}
return hash;
}

static size_t
hash_name(const char *name, size_t length)
{
Expand Down
1 change: 1 addition & 0 deletions lib/simap.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ bool simap_find_and_delete(struct simap *, const char *);

const struct simap_node **simap_sort(const struct simap *);
bool simap_equal(const struct simap *, const struct simap *);
uint32_t simap_hash(const struct simap *);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 6a16962

Please sign in to comment.