mirror of
https://github.com/openvswitch/ovs
synced 2025-09-02 15:25:22 +00:00
ovsdb-types: Add functions to compare types for equality.
Will be used in the next commit to optimize database conversion. Acked-by: Han Zhou <hzhou@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
@@ -275,6 +275,58 @@ ovsdb_base_type_is_valid(const struct ovsdb_base_type *base)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ovsdb_base_type_equals(const struct ovsdb_base_type *a,
|
||||
const struct ovsdb_base_type *b)
|
||||
{
|
||||
if (a == b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (a->type != b->type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((a->enum_ && !b->enum_) || (!a->enum_ && b->enum_)) {
|
||||
return false;
|
||||
} else if (a->enum_ &&
|
||||
!ovsdb_datum_equals(a->enum_, b->enum_,
|
||||
ovsdb_base_type_get_enum_type(a->type))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (a->type) {
|
||||
case OVSDB_TYPE_VOID:
|
||||
return true;
|
||||
|
||||
case OVSDB_TYPE_INTEGER:
|
||||
return a->integer.min == b->integer.min
|
||||
&& a->integer.max == b->integer.max;
|
||||
|
||||
case OVSDB_TYPE_REAL:
|
||||
return a->real.min == b->real.min && a->real.max == b->real.max;
|
||||
|
||||
case OVSDB_TYPE_BOOLEAN:
|
||||
return true;
|
||||
|
||||
case OVSDB_TYPE_STRING:
|
||||
return a->string.minLen == b->string.minLen
|
||||
&& a->string.maxLen == b->string.maxLen;
|
||||
|
||||
case OVSDB_TYPE_UUID:
|
||||
/* Not comparing the table pointer here, only the table name, as this
|
||||
* function can be used to compare types from different databases, so
|
||||
* pointers will be different. */
|
||||
return a->uuid.refType == b->uuid.refType
|
||||
&& nullable_string_is_equal(a->uuid.refTableName,
|
||||
b->uuid.refTableName);
|
||||
|
||||
case OVSDB_N_TYPES:
|
||||
default:
|
||||
OVS_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ovsdb_base_type_has_constraints(const struct ovsdb_base_type *base)
|
||||
{
|
||||
@@ -568,6 +620,15 @@ ovsdb_type_is_valid(const struct ovsdb_type *type)
|
||||
&& type->n_max >= 1);
|
||||
}
|
||||
|
||||
bool
|
||||
ovsdb_type_equals(const struct ovsdb_type *a, const struct ovsdb_type *b)
|
||||
{
|
||||
return ovsdb_base_type_equals(&a->key, &b->key)
|
||||
&& ovsdb_base_type_equals(&a->value, &b->value)
|
||||
&& a->n_min == b->n_min
|
||||
&& a->n_max == b->n_max;
|
||||
}
|
||||
|
||||
static struct ovsdb_error *
|
||||
n_from_json(const struct json *json, unsigned int *n)
|
||||
{
|
||||
|
@@ -107,6 +107,8 @@ void ovsdb_base_type_clone(struct ovsdb_base_type *,
|
||||
void ovsdb_base_type_destroy(struct ovsdb_base_type *);
|
||||
|
||||
bool ovsdb_base_type_is_valid(const struct ovsdb_base_type *);
|
||||
bool ovsdb_base_type_equals(const struct ovsdb_base_type *,
|
||||
const struct ovsdb_base_type *);
|
||||
bool ovsdb_base_type_has_constraints(const struct ovsdb_base_type *);
|
||||
void ovsdb_base_type_clear_constraints(struct ovsdb_base_type *);
|
||||
const struct ovsdb_type *ovsdb_base_type_get_enum_type(enum ovsdb_atomic_type);
|
||||
@@ -157,6 +159,7 @@ void ovsdb_type_clone(struct ovsdb_type *, const struct ovsdb_type *);
|
||||
void ovsdb_type_destroy(struct ovsdb_type *);
|
||||
|
||||
bool ovsdb_type_is_valid(const struct ovsdb_type *);
|
||||
bool ovsdb_type_equals(const struct ovsdb_type *, const struct ovsdb_type *);
|
||||
|
||||
static inline bool ovsdb_type_is_scalar(const struct ovsdb_type *);
|
||||
static inline bool ovsdb_type_is_optional(const struct ovsdb_type *);
|
||||
|
Reference in New Issue
Block a user