Finds the set of a given element, and compresses the path to the root node.

@param x
the element

@return the identifier of the set which contains the given element
502632
@Override
    public int find(int x) {
        int curr = x;
        int currp = p[curr];
        while (curr != currp) {
            curr = currp;
            currp = p[curr];
        }
        return curr;
        // TODO: use path compression/halving/...?
    }
960564
protected XmlElement findMatchedElementIn(Document document, org.dom4j.Element element) {
    org.dom4j.Attribute id = element.attribute("id");
    String idName = id.getName();
    String idValue = id.getValue();
    for (Element me : document.getRootElement().getElements()) {
      if (me instanceof XmlElement) {
        XmlElement xe = (XmlElement) me;
        for (Attribute ab : xe.getAttributes()) {
          if (StringUtils.equals(idName, ab.getName()) && StringUtils.equals(idValue, ab.getValue())) {
            return xe;
          }
        }
      }
    }
    return null;
  }
378242
public static int getXPathLocation(String dom, String xpath) {
		String dom_lower = dom.toLowerCase();
		String xpath_lower = xpath.toLowerCase();
		String[] elements = xpath_lower.split("/");
		int pos = 0;
		int temp;
		int number;
		for (String element : elements) {
			if (!element.isEmpty() && !element.startsWith("@") && !element.contains("()")) {
				if (element.contains("[")) {
					try {
						number =
								Integer.parseInt(element.substring(element.indexOf("[") + 1,
										element.indexOf("]")));
					} catch (NumberFormatException e) {
						return -1;
					}
				} else {
					number = 1;
				}
				for (int i = 0; i < number; i++) {
					// find new open element
					temp = dom_lower.indexOf("<" + stripEndSquareBrackets(element), pos);

					if (temp > -1) {
						pos = temp + 1;

						// if depth>1 then goto end of current element
						if (number > 1 && i < number - 1) {
							pos =
									getCloseElementLocation(dom_lower, pos,
											stripEndSquareBrackets(element));
						}

					}
				}
			}
		}
		return pos - 1;
	}
852099
public synchronized Set<String> keySet() {
		if(size == 0) {
			return new HashSet<String>(0);
		} else {
			try {
				XAttributeMap map = deserialize();
				return map.keySet();
			} catch (IOException e) {
				e.printStackTrace();
				return null;
			}
		}
	}
180574
public BitSet projectG1(BitSet set) {
        BitSet projection = new BitSet(getFirstGraphSize());
        CDKRNode xNode = null;

        for (int x = set.nextSetBit(0); x >= 0; x = set.nextSetBit(x + 1)) {
            xNode = getGraph().get(x);
            projection.set(xNode.getRMap().getId1());
        }
        return projection;
    }
580989
public XElement childElement(String name) {
        for (XElement e : children) {
            if (e.name.equals(name)) {
                return e;
            }
        }
        return null;
    }
925194
public Map<ElementDescriptor<?>, Object> getSet()
	{
		return mSet == null ? null : Collections.unmodifiableMap(mSet);
	}
1291352
public static NodeList getElementsB(Node node, String xString) throws XPathExpressionException {
        XPathExpression xPath = compileX(xString);
        return (NodeList) xPath.evaluate(node, XPathConstants.NODESET);
    }
298163
@Override
    public boolean add(X x) {
        if (!allowElementsWithoutIdentification)
            throw new IllegalArgumentException("It is not allowed to put Elements without Identification in this Set");

        return map.put(x, placeholder) == null;
    }
1368828
public Tree<K, V> lookup(Tree<K, V> tree, K x) {
        if (tree == null)
            return null;

        int cmp = ordering.compare(x, tree.getKey(kf));

        if (cmp < 0) return lookup(tree.getLeft(), x);
        else if (cmp > 0) return lookup(tree.getRight(), x);
        else return tree;
    }
998693
public int getLastPos(XPathContext xctxt)
  {

    int count = 0;
    AxesWalker savedWalker = wi().getLastUsedWalker();

    try
    {
      ReverseAxesWalker clone = (ReverseAxesWalker) this.clone();

      clone.setRoot(this.getRoot());

      clone.setPredicateCount(m_predicateIndex);

      clone.setPrevWalker(null);
      clone.setNextWalker(null);
      wi().setLastUsedWalker(clone);

      // Count 'em all
      // count = 1;
      int next;

      while (DTM.NULL != (next = clone.nextNode()))
      {
        count++;
      }
    }
    catch (CloneNotSupportedException cnse)
    {

      // can't happen
    }
    finally
    {
      wi().setLastUsedWalker(savedWalker);
    }

    return count;
  }
643814
public int indexOf(T x) {
    int r=Arrays.binarySearch(data,x);
    return(r>=0?r:-1);
  }
1373802
public static Node getNodeByXPath(String expression, Object source) {
		return (Node) getByXPath(expression, source, XPathConstants.NODE);
	}
731694
public static String getXPathFor(final Node aNode) {

        List<String> nodeNameList = new ArrayList<String>();

        for (Node current = aNode; current != null; current = current.getParentNode()) {

            final String currentNodeName = current.getNodeName();
            final String nameAttribute = DomHelper.getNameAttribute(current);

            if (currentNodeName.toLowerCase().endsWith("enumeration")) {

                // We should print the "value" attribute here.
                nodeNameList.add(currentNodeName + "[@value='" + getValueAttribute(current) + "']");

            } else if (nameAttribute == null) {

                // Just emit the node's name.
                nodeNameList.add(current.getNodeName());

            } else {

                // We should print the "name" attribute here.
                nodeNameList.add(current.getNodeName() + "[@name='" + nameAttribute + "']");
            }
        }

        StringBuilder builder = new StringBuilder();
        for (ListIterator<String> it = nodeNameList.listIterator(nodeNameList.size()); it.hasPrevious(); ) {
            builder.append(it.previous());
            if (it.hasPrevious()) {
                builder.append("/");
            }
        }

        return builder.toString();
    }
698434
static final String path(Element element) {
        StringBuilder sb = new StringBuilder();

        Node iterator = element;
        while (iterator.getNodeType() == Node.ELEMENT_NODE) {
            sb.insert(0, $(iterator).tag());
            sb.insert(0, "/");

            iterator = iterator.getParentNode();
        }

        return sb.toString();
    }
1237040
protected int getIndex(short x) {
    // before the binary search, we optimize for frequent cases
    if ((size == 0) || (keys[size - 1] == x)) {
      return size - 1;
    }
    // no luck we have to go through the list
    return this.binarySearch(0, size, x);
  }
83010
public boolean find(String xmlPathQuery) {
        XmlPath xmlPath = XmlPathParser.parse(xmlPathQuery);

        XmlNode node;
        while((node = pullXmlNode()) != null) {
            if(node instanceof XmlStartElement) {
                XmlStartElement startElement = (XmlStartElement) node;
                Element element = new Element(startElement.getLocalName());
                element.addAttributes(startElement.getAttributes());
                currentPath.addLast(element);
                if(xmlPath.matches(currentPath)) {
                    nodeQueue.push(node);
                    currentPath.removeLast();
                    return true;
                }
            } else if(node instanceof XmlEndElement) {
                if(currentPath.getLast() instanceof Content) {
                    currentPath.removeLast();
                }
                currentPath.removeLast();
            } else if(node instanceof XmlContent) {
                XmlContent content = (XmlContent) node;
                if(currentPath.getLast() instanceof Content) {
                    currentPath.removeLast();
                }
                currentPath.addLast(new Content(content.getText()));
            } else {
                throw new XmlReaderException("Unknown XmlNode type: " + node);
            }
        }
        return false;
    }