summaryrefslogtreecommitdiff
path: root/lib/smap.h
Commit message (Collapse)AuthorAgeFilesLines
* smap: New macro SMAP_CONST2 for an immutable map of 2 key-value pairs.Ben Pfaff2016-10-071-9/+17
| | | | | | | Future commits will add a user. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
* smap: New function smap_get_ullong().Ben Pfaff2016-08-081-0/+2
| | | | | Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* smap: New function smap_get_def().Ben Pfaff2016-08-081-1/+3
| | | | | Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* json: Move from lib to include/openvswitch.Terry Wilson2016-07-221-1/+1
| | | | | | | | | | | | | | | To easily allow both in- and out-of-tree building of the Python wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to include/openvswitch. This also requires moving lib/{hmap,shash}.h. Both hmap.h and shash.h were #include-ing "util.h" even though the headers themselves did not use anything from there, but rather from include/openvswitch/util.h. Fixing that required including util.h in several C files mostly due to OVS_NOT_REACHED and things like xmalloc. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* smap: Include hash.h.Russell Bryant2016-03-281-0/+1
| | | | | | | SMAP_CONST1 uses the hash_string() function from hash.h. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* smap: bsd: Fix compilation error.Pravin B Shelar2016-03-101-0/+1
| | | | | | | | | | | | | | | | | I saw following error while testing this series. ---8<--- In file included from lib/smap.c:16: ./lib/smap.h:75:56: warning: declaration of 'struct in6_addr' will not be visible outside of this function [-Wvisibility] void smap_add_ipv6(struct smap *, const char *, struct in6_addr *); ^ lib/smap.c:102:1: error: conflicting types for 'smap_add_ipv6' smap_add_ipv6(struct smap *smap, const char *key, struct in6_addr *addr) ^ ./lib/smap.h:75:6: note: previous declaration is here void smap_add_ipv6(struct smap *, const char *, struct in6_addr *); Signed-off-by: Pravin B Shelar <pshelar@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* hmap: Add extra build-time iteration checks for types derived from hmap.Ben Pfaff2016-02-191-6/+12
| | | | | | | | | | | | | | | | | | | | | | | | | Some of our data structures derived from hmap use the same member names. This means it's possible to confuse them in iteration, e.g. to iterate a shash with SIMAP_FOR_EACH. Of course this will crash at runtime, but it seems even better to catch it at compile time. An alternative would be to use unique member names, e.g. shash_map and simap_map instead of just map. I like short names, though. It's kind of nasty that we need support from the hmap code to do this. An alternative would be to insert the build assertions as statements before the for loop. But that would cause nasty surprises if someone forgets the {} around a block of statements; even though the OVS coding style requires them in all cases, I suspect that programmers doing debugging, etc. tend to omit them sometimes. It's not actually necessary to have multiple variants of these macros, e.g. one can write a C99-compliant HMAP_FOR_EACH that accepts 3 or 4 or more arguments. But such a macro is harder to read, so I don't know whether this is a good tradeoff. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
* lib: add ipv6 helper functions for tnl_configJiri Benc2015-11-101-0/+1
| | | | | | | | These functions will be used by the next patches. Signed-off-by: Jiri Benc <jbenc@redhat.com> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* smap: New macro SMAP_CONST1 for initializing immutable 1-member smaps.Ben Pfaff2015-09-081-0/+19
| | | | | | | | | | | | | | | | | | | | | | | Reviewing the ovn-controller code I started to notice a common pattern: struct smap ext_ids = SMAP_INITIALIZER(&ext_ids); smap_add(&ext_ids, "ovn-patch-port", network); ovsrec_port_set_external_ids(port, &ext_ids); smap_destroy(&ext_ids); This seemed like a bit too much code for something as simple as initializing an smap with a single key-value pair. This commit allows the code to be reduced to just: const struct smap ids = SMAP_CONST1(&ids, "ovn-patch-port", network); ovsrec_port_set_external_ids(port, &ids); This new form also eliminates multiple memory allocation and free operations, but I doubt that has any real effect on performance; the primary goal here is code readability. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com>
* smap: New function smap_get_uuid().Ben Pfaff2015-08-031-1/+3
| | | | | | | | To be used in an upcoming commit. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* smap: Add smap_equal().Russell Bryant2015-07-311-0/+2
| | | | | | | | | Add a method to determine of two smaps are equal (have the exact same set of key-value pairs). Suggested-by: Ben Pfaff <blp@nicira.com> Signed-off-by: Russell Bryant <rbryant@redhat.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* lib: Move compiler.h to <openvswitch/compiler.h>Thomas Graf2014-12-151-1/+1
| | | | | | | | | | The following macros are renamed to avoid conflicts with other headers: * WARN_UNUSED_RESULT to OVS_WARN_UNUSED_RESULT * PRINTF_FORMAT to OVS_PRINTF_FORMAT * NO_RETURN to OVS_NO_RETURN Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
* smap: New function smap_add_nocopy().Ben Pfaff2014-07-171-1/+2
| | | | | | | | An upcoming commit will add a caller that needs to format both the key and the value. That isn't cleanly possible with the current interface. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Gurucharan Shetty <gshetty@nicira.com>
* system-stats: Use "smap" instead of "shash".Ben Pfaff2012-07-181-1/+1
| | | | | | | | | "smap" is now the appropriate data structure for a string-to-string map. Also changes ovsdb_datum_from_shash() into ovsdb_datum_from_smap() since system-stats related code was the only client. Signed-off-by: Ben Pfaff <blp@nicira.com>
* smap: New function smap_steal().Ben Pfaff2012-07-181-1/+2
| | | | | | An upcoming commit will add a caller. Signed-off-by: Ben Pfaff <blp@nicira.com>
* smap: New functions smap_from_json(), smap_to_json().Ben Pfaff2012-07-181-0/+5
| | | | | | These will acquire a caller in an upcoming commit. Signed-off-by: Ben Pfaff <blp@nicira.com>
* lib: Minor const tweak in smap library.Ethan Jackson2012-06-191-1/+1
| | | | | | | The source argument of smap_clone() isn't modified, and thus can be declared const. Signed-off-by: Ethan Jackson <ethan@nicira.com>
* lib: New data structure - smap.Ethan Jackson2012-06-141-0/+63
A smap is a string to string hash map. It has a cleaner interface than shash's which were traditionally used for the same purpose. This patch implements the data structure, and changes netdev and its providers to use it. Signed-off-by: Ethan Jackson <ethan@nicira.com>