2012-05-22 10:32:02 -07:00
|
|
|
/*
|
2017-05-05 12:54:42 +00:00
|
|
|
* Copyright (c) 2009, 2010, 2011, 2012, 2016, 2017 Nicira, Inc.
|
2012-05-22 10:32:02 -07:00
|
|
|
*
|
|
|
|
* 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 SIMAP_H
|
|
|
|
#define SIMAP_H 1
|
|
|
|
|
2016-07-12 16:37:34 -05:00
|
|
|
#include "openvswitch/hmap.h"
|
2012-05-22 10:32:02 -07:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* A map from strings to unsigned integers. */
|
|
|
|
struct simap {
|
|
|
|
struct hmap map; /* Contains "struct simap_node"s. */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct simap_node {
|
|
|
|
struct hmap_node node; /* In struct simap's 'map' hmap. */
|
|
|
|
char *name;
|
|
|
|
unsigned int data;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SIMAP_INITIALIZER(SIMAP) { HMAP_INITIALIZER(&(SIMAP)->map) }
|
|
|
|
|
2016-02-08 16:52:45 -08:00
|
|
|
#define SIMAP_FOR_EACH(SIMAP_NODE, SIMAP) \
|
|
|
|
HMAP_FOR_EACH_INIT (SIMAP_NODE, node, &(SIMAP)->map, \
|
|
|
|
BUILD_ASSERT_TYPE(SIMAP_NODE, struct simap_node *), \
|
|
|
|
BUILD_ASSERT_TYPE(SIMAP, struct simap *))
|
2012-05-22 10:32:02 -07:00
|
|
|
|
2022-03-23 12:56:17 +01:00
|
|
|
#define SIMAP_FOR_EACH_SAFE_SHORT(SIMAP_NODE, SIMAP) \
|
|
|
|
HMAP_FOR_EACH_SAFE_SHORT_INIT (SIMAP_NODE, node, &(SIMAP)->map, \
|
2016-02-08 16:52:45 -08:00
|
|
|
BUILD_ASSERT_TYPE(SIMAP_NODE, struct simap_node *), \
|
|
|
|
BUILD_ASSERT_TYPE(SIMAP, struct simap *))
|
2012-05-22 10:32:02 -07:00
|
|
|
|
2022-03-23 12:56:17 +01:00
|
|
|
#define SIMAP_FOR_EACH_SAFE_LONG(SIMAP_NODE, NEXT, SIMAP) \
|
|
|
|
HMAP_FOR_EACH_SAFE_LONG_INIT (SIMAP_NODE, NEXT, node, &(SIMAP)->map, \
|
|
|
|
BUILD_ASSERT_TYPE(SIMAP_NODE, struct simap_node *), \
|
|
|
|
BUILD_ASSERT_TYPE(NEXT, struct simap_node *), \
|
|
|
|
BUILD_ASSERT_TYPE(SIMAP, struct simap *))
|
|
|
|
|
|
|
|
#define SIMAP_FOR_EACH_SAFE(...) \
|
|
|
|
OVERLOAD_SAFE_MACRO(SIMAP_FOR_EACH_SAFE_LONG, \
|
|
|
|
SIMAP_FOR_EACH_SAFE_SHORT, \
|
|
|
|
3, __VA_ARGS__)
|
|
|
|
|
2012-05-22 10:32:02 -07:00
|
|
|
void simap_init(struct simap *);
|
|
|
|
void simap_destroy(struct simap *);
|
|
|
|
void simap_swap(struct simap *, struct simap *);
|
|
|
|
void simap_moved(struct simap *);
|
|
|
|
void simap_clear(struct simap *);
|
|
|
|
|
|
|
|
bool simap_is_empty(const struct simap *);
|
|
|
|
size_t simap_count(const struct simap *);
|
|
|
|
|
|
|
|
bool simap_put(struct simap *, const char *, unsigned int);
|
|
|
|
unsigned int simap_increase(struct simap *, const char *, unsigned int);
|
|
|
|
|
|
|
|
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);
|
2013-02-14 09:37:27 -05:00
|
|
|
bool simap_contains(const struct simap *, const char *);
|
2012-05-22 10:32:02 -07:00
|
|
|
|
|
|
|
void simap_delete(struct simap *, struct simap_node *);
|
2013-02-14 09:37:27 -05:00
|
|
|
bool simap_find_and_delete(struct simap *, const char *);
|
2012-05-22 10:32:02 -07:00
|
|
|
|
|
|
|
const struct simap_node **simap_sort(const struct simap *);
|
2017-05-05 12:54:42 +00:00
|
|
|
bool simap_equal(const struct simap *, const struct simap *);
|
2019-08-28 15:14:25 -07:00
|
|
|
uint32_t simap_hash(const struct simap *);
|
2012-05-22 10:32:02 -07:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* simap.h */
|