mirror of
https://github.com/openvswitch/ovs
synced 2025-08-22 09:58:01 +00:00
Using SHORT version of the *_SAFE loops makes the code cleaner and less error prone. So, use the SHORT version and remove the extra variable when possible for hmap and all its derived types. In order to be able to use both long and short versions without changing the name of the macro for all the clients, overload the existing name and select the appropriate version depending on the number of arguments. Acked-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
87 lines
3.2 KiB
C
87 lines
3.2 KiB
C
/*
|
|
* Copyright (c) 2011, 2016 Nicira, Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at:
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef HMAPX_H
|
|
#define HMAPX_H
|
|
|
|
#include "openvswitch/hmap.h"
|
|
|
|
struct hmapx_node {
|
|
struct hmap_node hmap_node;
|
|
void *data;
|
|
};
|
|
|
|
/* A set of "void *" pointers. */
|
|
struct hmapx {
|
|
struct hmap map;
|
|
};
|
|
|
|
#define HMAPX_INITIALIZER(HMAPX) { HMAP_INITIALIZER(&(HMAPX)->map) }
|
|
|
|
/* Basics. */
|
|
void hmapx_init(struct hmapx *);
|
|
void hmapx_destroy(struct hmapx *);
|
|
void hmapx_clone(struct hmapx *, const struct hmapx *);
|
|
void hmapx_swap(struct hmapx *, struct hmapx *);
|
|
void hmapx_moved(struct hmapx *);
|
|
|
|
/* Count. */
|
|
bool hmapx_is_empty(const struct hmapx *);
|
|
size_t hmapx_count(const struct hmapx *);
|
|
|
|
/* Insertion. */
|
|
struct hmapx_node *hmapx_add(struct hmapx *, void *);
|
|
void hmapx_add_assert(struct hmapx *, void *);
|
|
|
|
/* Deletion. */
|
|
void hmapx_clear(struct hmapx *);
|
|
void hmapx_delete(struct hmapx *, struct hmapx_node *);
|
|
bool hmapx_find_and_delete(struct hmapx *, const void *);
|
|
void hmapx_find_and_delete_assert(struct hmapx *, const void *);
|
|
|
|
/* Search. */
|
|
struct hmapx_node *hmapx_find(const struct hmapx *, const void *);
|
|
bool hmapx_contains(const struct hmapx *, const void *);
|
|
bool hmapx_equals(const struct hmapx *, const struct hmapx *);
|
|
|
|
/* Iteration. */
|
|
|
|
/* Iterates through every hmapx_node in HMAPX. */
|
|
#define HMAPX_FOR_EACH(NODE, HMAPX) \
|
|
HMAP_FOR_EACH_INIT(NODE, hmap_node, &(HMAPX)->map, \
|
|
BUILD_ASSERT_TYPE(NODE, struct hmapx_node *), \
|
|
BUILD_ASSERT_TYPE(HMAPX, struct hmapx *))
|
|
|
|
/* Safe when NODE may be freed (not needed when NODE may be removed from the
|
|
* hash map but its members remain accessible and intact). */
|
|
#define HMAPX_FOR_EACH_SAFE_SHORT(NODE, HMAPX) \
|
|
HMAP_FOR_EACH_SAFE_SHORT_INIT (NODE, hmap_node, &(HMAPX)->map, \
|
|
BUILD_ASSERT_TYPE(NODE, struct hmapx_node *), \
|
|
BUILD_ASSERT_TYPE(HMAPX, struct hmapx *))
|
|
|
|
#define HMAPX_FOR_EACH_SAFE_LONG(NODE, NEXT, HMAPX) \
|
|
HMAP_FOR_EACH_SAFE_LONG_INIT (NODE, NEXT, hmap_node, &(HMAPX)->map, \
|
|
BUILD_ASSERT_TYPE(NODE, struct hmapx_node *), \
|
|
BUILD_ASSERT_TYPE(NEXT, struct hmapx_node *), \
|
|
BUILD_ASSERT_TYPE(HMAPX, struct hmapx *))
|
|
|
|
#define HMAPX_FOR_EACH_SAFE(...) \
|
|
OVERLOAD_SAFE_MACRO(HMAPX_FOR_EACH_SAFE_LONG, \
|
|
HMAPX_FOR_EACH_SAFE_SHORT, \
|
|
3, __VA_ARGS__)
|
|
|
|
#endif /* hmapx.h */
|