#How to check if two of these datatypes are equal

10 messages · Page 1 of 1 (latest)

north leaf
#

i have these data types

pub enum Schema {
    Object(Vec<Field>),
    Array(FieldType),
}

pub struct Field {
    pub name: String,
    pub ty: FieldType,
}

pub enum FieldType {
    String,
    Integer,
    Float,
    Boolean,
    Unknown,
    Object(Vec<Field>),
    Union(Vec<FieldType>),
    Array(Box<FieldType>),
    Optional(Box<FieldType>),
}

i want to check if two Schema are equal. But the problem is, the order of the elements in the vecs doesn't matter

fierce pelican
#

Is there a reason you're using Vec and not HashSet?

north leaf
#

no reason. i thought using a Vec for small things is good.

#

and simpler

fierce pelican
#

HashSet will be simpler here because comparing two HashSets just does the unordered comparison that you want.

north leaf
#

there might be duplicates

fierce pelican
north leaf
fierce pelican
inland spruce
#

you can benchmark both if you care for the small size optimisation