         if resultSet[key]?
           continue
         # ignore nodes in the source set
-        if xsSet[key]?
+        if xs.has key
           continue
         allChildrenIn = true
         for childValue of parent.children
-          unless xsSet[childValue]?
+          unless xs.has childValue
             allChildrenIn = false
             break
         resultSet[key] = allChildrenIn

    return results

  # find those elements whose children are all in xs
  # O(xs.length)
  Graph.prototype.whereAllChildrenIn = (xs) ->
    # dont inherit from the Object prototype such that we dont need to use hasOwnProperty
    xsSet = Object.create(null)
    # for fast lookup
    for x in xs
      xsSet[x] = true
    # dont inherit from the Object prototype such that we dont need to use hasOwnProperty
    resultSet = Object.create(null)
    for x in xs
      node = this.nodes[x]
      unless node?
        throw new Error "searching whereAllChildrenIn of `#{x}` which is not in graph"
      for key, parent of node.parents

    return elements

  # find those elements whose parents are all in xs
  Graph.prototype.whereAllParentsIn = (xs...) ->
    unless xs instanceof Set
      xs = new Set xs...
    # for fast lookup
    for x in xs
      xsSet[x] = true
    # dont inherit from the Object prototype such that we dont need to use hasOwnProperty
    resultSet = Object.create(null)
    that = this
    xs.forEach (x) ->
      node = that.nodes[x]
      unless node?
        throw new Error "searching whereAllParentsIn of `#{x}` which is not in graph"
      for key, child of node.children
