From f79fd630bfa82ae7f5deca6b76c0b60deff67c79 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 22 Sep 2022 16:00:22 -0700 Subject: [PATCH] [PersistentCollections] _Node.isDisjoint: Add new fast path --- .../Node/_Node+isDisjoint.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/PersistentCollections/Node/_Node+isDisjoint.swift b/Sources/PersistentCollections/Node/_Node+isDisjoint.swift index a5a86288..3e1abb92 100644 --- a/Sources/PersistentCollections/Node/_Node+isDisjoint.swift +++ b/Sources/PersistentCollections/Node/_Node+isDisjoint.swift @@ -76,6 +76,20 @@ extension _Node { ) -> Bool { // Beware, self might be on a compressed path assert(isCollisionNode) + if other.isCollisionNode { + return read { l in + other.read { r in + let lh = l.collisionHash + let rh = r.collisionHash + guard lh == rh else { return true } + let litems = l.reverseItems + let ritems = r.reverseItems + return litems.allSatisfy { li in + !ritems.contains { ri in li.key == ri.key } + } + } + } + } return read { let items = $0.reverseItems let hash = $0.collisionHash