Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

Replace DiffAware to Hashable #36

@ton252

Description

@ton252

Could you explain why we need to use DiffAware protocol when Hashable do the same thing and there is a lot of helper functional out-of-the-box like Hasher etc.

For example, we have a simple struct:

struct SomeStruct<T: DiffAware, U: DiffAware> {
  var value: T
  var valuesArray: [U]
}

And if we want to conform DiffAware protocol, we need to calculate diffId something like this:

 var diffId: Int {
    let valueIds = self.values.map({ $0.diffId })
    
    var hasher = Hasher()
    hasher.combine(self.value.diffId)
    hasher.combine(valueIds)
    
    return hasher.finalize()
}

And if all the objects conformed Hashable protocol, I will not need to use map in this case and it will affect the performance.

As I remember map complexity is O(n).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions