Finds an ancestor of a specific type, if possible.

<p>Example: (New York city target, {@link Type#COUNTRY}) returns (US country target)
346147
@Nullable public GeoTarget getCanonAncestor(GeoTarget.Type type) {
    for (GeoTarget target = this; target != null; target = target.canonParent()) {
      if (target.key.type == type) {
        return target;
      }
    }

    return null;
  }
1227437
function getAncestors(node) {
    const ancestorsStartingAtParent = [];

    for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
        ancestorsStartingAtParent.push(ancestor);
    }

    return ancestorsStartingAtParent.reverse();
}
1201635
function ancestors(first, second) {
  var path = [];

  for (var n in first.path) {
    if (first.path[n] !== second.path[n]) break;
    path.push(first.path[n]);
  }
  return path;
}
1312717
public static <T> T findAncestor(JspTag from, Class<? extends T> clazz) throws JspException {
		T parent = clazz.cast(SimpleTagSupport.findAncestorWithClass(from, clazz));
		if(parent==null) throw new LocalizedJspException(accessor, "JspTagUtils.findAncestor.notFound", getClassName(from.getClass()), getClassName(clazz));
		return parent;
	}
861813
@Override
    public boolean hasAncestor(QueryNode descendantNode, QueryNode ancestorNode) {
        return getAncestors(descendantNode).contains(ancestorNode);
    }
221566
int specialFind(int startPos, int position)
  {
          // We have to look all the way up the ancestor chain
          // to make sure we don't have an ancestor.
          int ancestor = startPos;
          while(ancestor > 0)
          {
                // Get the node whose index == ancestor
                ancestor*=slotsize;
                int chunkpos = ancestor >> lowbits;
                int slotpos = ancestor & lowmask;
                int[] chunk = chunks.elementAt(chunkpos);
                                                        
                // Get that node's parent (Note that this assumes w[1]
                // is the parent node index. That's really a DTM feature
                // rather than a ChunkedIntArray feature.)
                ancestor = chunk[slotpos + 1];

                if(ancestor == position)
                         break;
          }

          if (ancestor <= 0) 
          {
                  return position;
          }
          return -1;
  }
144270
def ancestors_objects(self):
        """"""
        ancestors_objects = []
        for ancestor in self.ancestors:
            try:
                ancestor_object = GeoZone.objects.get(id=ancestor)
            except GeoZone.DoesNotExist:
                continue
            ancestors_objects.append(ancestor_object)
        ancestors_objects.sort(key=lambda a: a.name)
        return ancestors_objects
144650
public Inode getAncestorInode() throws FileDoesNotExistException {
    int ancestorIndex = mPathComponents.length - 2;
    if (ancestorIndex < 0) {
      throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(mUri));
    }
    ancestorIndex = Math.min(ancestorIndex, mExistingInodes.size() - 1);
    return mExistingInodes.get(ancestorIndex);
  }
161130
function (scope, selector, isRoot) {
      // It may surprise you to learn this is exactly what JQuery does
      // TODO: Avoid all this wrapping and unwrapping
      return PredicateFilter.ancestors(scope, function (e) {
        return Selectors.is(e, selector);
      }, isRoot);
    }
429948
function ancestor(predicate, node) {
    while ((node = node.parent)) {
        if (predicate(node)) return true;
    }

    return false;
}
234286
function (node, pred) {
            pred = pred || func.fail;

            var ancestors = [];
            ancestor(node, function (el) {
                if (!isEditable(el)) {
                    ancestors.push(el);
                }

                return pred(el);
            });
            return ancestors;
        }
1071272
public static Predicate<Class<?>> classIsDescendantOf(Class<?> ancestor) {
        return candidate -> candidate != null && candidate != ancestor && ancestor
                .isAssignableFrom(candidate);
    }
520361
function getParent(type, id, parentType, root) {
		return _client.retrieve({
			type: type,
			id: id,
			properties: ['parent']
		})
		.then(function(obj) {
			
			if (obj.length > 0) {
				
				obj  = _.first(obj);
				type = _.get(obj, 'parent.type');
				id   = _.get(obj, 'parent.id');
				
				// if there is no parent type or id, the parent could not be found, throw an error
				if (!type || !id) {
					throw {
						errorCode: 404,
						message: 'could not find parent type'
					};
				}
				
				// if the parent is a match
				if (type === parentType) {
					
					// if a root search, keep looking for parent objects of the same type
					if (root === true) {
						return _client.retrieve({
							type: type,
							id: id,
							properties: ['parent']
						})
						.then(function(parent) {
							if (_.get(parent, 'parent.type') === parentType) {
								return getParent(type, id, parentType, root);
							}
							return {
								id: id,
								type: parentType
							};
						});
					}
					return {
						id: id,
						type: parentType
					};
				}
				
				return getParent(type, id, parentType, root);
			}
			
			throw {
				errorCode: 404,
				message: 'Object not found'
			};
		});
	}
225363
private void getAncestors(Entity entity, LdapEntry ldapEntry, AncestorControl ancesCtrl) throws WIMException {
        if (ancesCtrl == null) {
            return;
        }

        List<String> propNames = ancesCtrl.getProperties();
        int level = ancesCtrl.getLevel();
        List<String> ancesTypes = getEntityTypes(ancesCtrl);
        String[] bases = getBases(ancesCtrl, ancesTypes);

        String dn = ldapEntry.getDN();
        List<String> ancestorDns = iLdapConn.getAncestorDNs(dn, level);
        Entity parentEntity = entity;
        for (int i = 0; i < ancestorDns.size(); i++) {
            String ancesDn = ancestorDns.get(i);
            if (ancesDn.length() == 0) {
                continue;
            }
            if (LdapHelper.isUnderBases(ancesDn, bases)) {
                LdapEntry ancesEntry = iLdapConn.getEntityByIdentifier(ancesDn, null, null, ancesTypes, propNames,
                                                                       false, false);
                String ancesType = ancesEntry.getType();
                Entity ancestor = null;
                if (ancesTypes.contains(ancesType)) {
                    ancestor = createEntityFromLdapEntry(parentEntity, SchemaConstants.DO_PARENT, ancesEntry, propNames);
                } else {
                    ancestor = createEntityFromLdapEntry(parentEntity, SchemaConstants.DO_PARENT, ancesEntry, null);
                }
                parentEntity = ancestor;
            }
        }
    }
418750
@Override
    public int find(int x) {
        int curr = x;
        int currp = p[curr];
        while (curr != currp) {
            curr = currp;
            currp = p[curr];
        }
        int ancestor = curr;
        curr = x;
        while (curr != ancestor) {
            int next = p[curr];
            p[curr] = ancestor;
            curr = next;
        }

        return ancestor;
    }
775960
function getAncestor (node, root, validate) {
  while (node.parent) {
    node = node.parent
    if (validate(node)) {
      return node
    }
    if (node === root) {
      break
    }
  }
  return null
}
1254169
private int findOrInsertNodeForPrimary(long p) {
        int rootIndex = binarySearchForRootPrimaryNode(
            rootPrimaryIndexes.getBuffer(), rootPrimaryIndexes.size(), nodes.getBuffer(), p);
        if(rootIndex >= 0) {
            return rootPrimaryIndexes.elementAti(rootIndex);
        } else {
            // Start a new list of nodes with this primary.
            int index = nodes.size();
            nodes.addElement(nodeFromWeight32(p));
            rootPrimaryIndexes.insertElementAt(index, ~rootIndex);
            return index;
        }
    }