public int compare(Item a, /*@NotNull*/ Item b) { if (a == b) { return 0; } long d1 = ((NodeInfo) a).getTreeInfo().getDocumentNumber(); long d2 = ((NodeInfo) b).getTreeInfo().getDocumentNumber(); if (d1 == d2) { return ((NodeInfo) a).compareOrder((NodeInfo) b); } return Long.signum(d1 - d2); } }
public int compare(Item a, /*@NotNull*/ Item b) { if (a == b) { return 0; } long d1 = ((NodeInfo) a).getTreeInfo().getDocumentNumber(); long d2 = ((NodeInfo) b).getTreeInfo().getDocumentNumber(); if (d1 == d2) { return ((NodeInfo) a).compareOrder((NodeInfo) b); } return Long.signum(d1 - d2); } }
/** * Build the index for a particular document for a named key * * @param keySet The set of key definitions with this name * @param doc The source document in question * @param context The dynamic context * @return the index in question, as a Map mapping a key value onto a List of nodes * @throws XPathException if a dynamic error is encountered */ private synchronized KeyIndex buildIndex(KeyDefinitionSet keySet, TreeInfo doc, XPathContext context) throws XPathException { // KILROY System.err.println("Building index " + keySet.getKeyName() + " for doc " + doc.getDocumentNumber() + " in thread " + Thread.currentThread().getId()); KeyIndex index = new KeyIndex(keySet.isRangeKey()); index.buildIndex(keySet, doc, context); System.err.println("Done building index " + keySet.getKeyName() + " for doc " + doc.getDocumentNumber() + " in thread " + Thread.currentThread().getId()); return index; }
/** * Get a character string that uniquely identifies this node * * @param buffer to contain an identifier based on the document number */ public void generateId(/*@NotNull*/ FastStringBuffer buffer) { buffer.append('d'); buffer.append(Long.toString(getTreeInfo().getDocumentNumber())); }
/** * Get a character string that uniquely identifies this node * * @param buffer to contain an identifier based on the document number */ public void generateId(/*@NotNull*/ FastStringBuffer buffer) { buffer.append('d'); buffer.append(Long.toString(getTreeInfo().getDocumentNumber())); }
/** * Get the non-shared index associated with a particular key, a particular source document, * and a particular primitive item type * * @param doc the document whose index is required * @param keyFingerprint the name of the key definition * @param context the dynamic evaluation context * @return either an index (as a HashMap), or the dummy map "under construction", or null */ private synchronized KeyIndex getLocalIndex(TreeInfo doc, int keyFingerprint, XPathContext context) { Controller controller = context.getController(); IntHashMap<Map<Long, KeyIndex>> masterIndex = controller.getLocalIndexes(); Map<Long, KeyIndex> docIndexes = masterIndex.get(keyFingerprint); if (docIndexes == null) { return null; } else { return docIndexes.get(doc.getDocumentNumber()); } }
/** * Save the index associated with a particular key, a particular item type, * and a particular document. This version of the method is used for indexes that are * not reusable across transformations, because the key depends on transformation-specific * data such as global variables or parameters. * The method still need to be synchronized because several threads within a transformation * may be creating indexes for the same or different documents at the same * time. * * @param doc the document being indexed * @param keyFingerprint represents the name of the key definition * @param index the index being saved * @param context the dynamic evaluation context */ private synchronized KeyIndex putLocalIndex(TreeInfo doc, int keyFingerprint, KeyIndex index, XPathContext context) { Controller controller = context.getController(); IntHashMap<Map<Long, KeyIndex>> masterIndex = controller.getLocalIndexes(); Map<Long, KeyIndex> docIndexes = masterIndex.get(keyFingerprint); if (docIndexes == null) { docIndexes = new HashMap<>(); masterIndex.put(keyFingerprint, docIndexes); } KeyIndex result = docIndexes.get(doc.getDocumentNumber()); if (result == null || result.getStatus() != BUILT) { // Use this index in preference to one that is under construction in another thread docIndexes.put(doc.getDocumentNumber(), index); result = index; } return result; }
/** * Get the non-shared index associated with a particular key, a particular source document, * and a particular primitive item type * * @param doc the document whose index is required * @param keyFingerprint the name of the key definition * @param context the dynamic evaluation context * @return either an index (as a HashMap), or the dummy map "under construction", or null */ private synchronized KeyIndex getLocalIndex(TreeInfo doc, int keyFingerprint, XPathContext context) { Controller controller = context.getController(); IntHashMap<Map<Long, KeyIndex>> masterIndex = controller.getLocalIndexes(); Map<Long, KeyIndex> docIndexes = masterIndex.get(keyFingerprint); if (docIndexes == null) { return null; } else { return docIndexes.get(doc.getDocumentNumber()); } }
/** * Save the index associated with a particular key, a particular item type, * and a particular document. This version of the method is used for indexes that are * not reusable across transformations, because the key depends on transformation-specific * data such as global variables or parameters. * The method still need to be synchronized because several threads within a transformation * may be creating indexes for the same or different documents at the same * time. * * @param doc the document being indexed * @param keyFingerprint represents the name of the key definition * @param index the index being saved * @param context the dynamic evaluation context */ private synchronized KeyIndex putLocalIndex(TreeInfo doc, int keyFingerprint, KeyIndex index, XPathContext context) { Controller controller = context.getController(); IntHashMap<Map<Long, KeyIndex>> masterIndex = controller.getLocalIndexes(); Map<Long, KeyIndex> docIndexes = masterIndex.get(keyFingerprint); if (docIndexes == null) { docIndexes = new HashMap<>(); masterIndex.put(keyFingerprint, docIndexes); } KeyIndex result = docIndexes.get(doc.getDocumentNumber()); if (result == null || result.getStatus() != BUILT) { // Use this index in preference to one that is under construction in another thread docIndexes.put(doc.getDocumentNumber(), index); result = index; } return result; }
/** * Get a character string that uniquely identifies this node and that collates nodes * into document order * * @param node the node whose unique identifier is reuqired * @param sb a buffer to which the unique identifier will be appended * @param addDocNr true if a unique document number is to be included in the information */ public static void appendSequentialKey(/*@NotNull*/ SiblingCountingNode node, /*@NotNull*/ FastStringBuffer sb, boolean addDocNr) { if (addDocNr) { sb.append('w'); sb.append(Long.toString(node.getTreeInfo().getDocumentNumber())); } if (node.getNodeKind() != Type.DOCUMENT) { NodeInfo parent = node.getParent(); if (parent != null) { appendSequentialKey((SiblingCountingNode) parent, sb, false); } if (node.getNodeKind() == Type.ATTRIBUTE) { sb.append('A'); } } sb.append(alphaKey(node.getSiblingPosition())); }
/** * Get a character string that uniquely identifies this node and that collates nodes * into document order * * @param node the node whose unique identifier is reuqired * @param sb a buffer to which the unique identifier will be appended * @param addDocNr true if a unique document number is to be included in the information */ public static void appendSequentialKey(/*@NotNull*/ SiblingCountingNode node, /*@NotNull*/ FastStringBuffer sb, boolean addDocNr) { if (addDocNr) { sb.append('w'); sb.append(Long.toString(node.getTreeInfo().getDocumentNumber())); } if (node.getNodeKind() != Type.DOCUMENT) { NodeInfo parent = node.getParent(); if (parent != null) { appendSequentialKey((SiblingCountingNode) parent, sb, false); } if (node.getNodeKind() == Type.ATTRIBUTE) { sb.append('A'); } } sb.append(alphaKey(node.getSiblingPosition())); }