Skip to content

It seems you can use NSHashTable instead of Set for LinkedLists/LoopDetection/Loop.swift #1

@kyzmitch

Description

@kyzmitch
func hasLoopNodeHash() -> Node? {
        var set = Set<Node>() // **Right here**
        var temp: Node? = self
        while let t = temp {
            if set.contains(t) {
                return t
            } else {
                set.insert(t)
            }
            temp = temp?.next
        }
        return nil
    }

because Its members may use pointer identity for equality and hashing. So, you don't have to implement Comparable methods like:

public static func ==(lhs: Node, rhs: Node) -> Bool {
        return lhs === rhs
    }
    
    var hashValue: Int {
        return ObjectIdentifier(self).hashValue
    }

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