```\n    function isAdminOfHat(address _user, uint256 _hatId) public view returns (bool isAdmin) {\n        uint256 linkedTreeAdmin;\n        uint32 adminLocalHatLevel;\n        if (isLocalTopHat(_hatId)) {\n            linkedTreeAdmin = linkedTreeAdmins[getTopHatDomain(_hatId)];\n            if (linkedTreeAdmin == 0) {\n                // tree is not linked\n                return isAdmin = isWearerOfHat(_user, _hatId);\n            } else {\n                // tree is linked\n                if (isWearerOfHat(_user, linkedTreeAdmin)) {\n                    return isAdmin = true;\n                } // user wears the treeAdmin\n                else {\n                    adminLocalHatLevel = getLocalHatLevel(linkedTreeAdmin);\n                    _hatId = linkedTreeAdmin;\n                }\n            }\n        } else {\n            // if we get here, _hatId is not a tophat of any kind\n            // get the local tree level of _hatId's admin\n            adminLocalHatLevel = getLocalHatLevel(_hatId) - 1;\n        }\n\n        // search up _hatId's local address space for an admin hat that the _user wears\n        while (adminLocalHatLevel > 0) {\n            if (isWearerOfHat(_user, getAdminAtLocalLevel(_hatId, adminLocalHatLevel))) {\n                return isAdmin = true;\n            }\n            // should not underflow given stopping condition > 0\n            unchecked {\n                --adminLocalHatLevel;\n            }\n        }\n\n        // if we get here, we've reached the top of _hatId's local tree, ie the local tophat\n        // check if the user wears the local tophat\n        if (isWearerOfHat(_user, getAdminAtLocalLevel(_hatId, 0))) return isAdmin = true;\n\n        // if not, we check if it's linked to another tree\n        linkedTreeAdmin = linkedTreeAdmins[getTopHatDomain(_hatId)];\n        if (linkedTreeAdmin == 0) {\n            // tree is not linked\n            // we've already learned that user doesn't wear the local tophat, so there's nothing else to check; we return false\n            return isAdmin = false;\n        } else {\n            // tree is linked\n            // check if user is wearer of linkedTreeAdmin\n            if (isWearerOfHat(_user, linkedTreeAdmin)) return true;\n            // if not, recurse to traverse the parent tree for a hat that the user wears\n            isAdmin = isAdminOfHat(_user, linkedTreeAdmin);\n        }\n    }\n```\n