* xmlXPathNodeSetSort: * @set: the node set * * Sort the node set in document order */
| 2646 | * Sort the node set in document order |
| 2647 | */ |
| 2648 | void |
| 2649 | xmlXPathNodeSetSort(xmlNodeSetPtr set) { |
| 2650 | #ifndef WITH_TIM_SORT |
| 2651 | int i, j, incr, len; |
| 2652 | xmlNodePtr tmp; |
| 2653 | #endif |
| 2654 | |
| 2655 | if (set == NULL) |
| 2656 | return; |
| 2657 | |
| 2658 | #ifndef WITH_TIM_SORT |
| 2659 | /* |
| 2660 | * Use the old Shell's sort implementation to sort the node-set |
| 2661 | * Timsort ought to be quite faster |
| 2662 | */ |
| 2663 | len = set->nodeNr; |
| 2664 | for (incr = len / 2; incr > 0; incr /= 2) { |
| 2665 | for (i = incr; i < len; i++) { |
| 2666 | j = i - incr; |
| 2667 | while (j >= 0) { |
| 2668 | #ifdef XP_OPTIMIZED_NON_ELEM_COMPARISON |
| 2669 | if (xmlXPathCmpNodesExt(set->nodeTab[j], |
| 2670 | set->nodeTab[j + incr]) == -1) |
| 2671 | #else |
| 2672 | if (xmlXPathCmpNodes(set->nodeTab[j], |
| 2673 | set->nodeTab[j + incr]) == -1) |
| 2674 | #endif |
| 2675 | { |
| 2676 | tmp = set->nodeTab[j]; |
| 2677 | set->nodeTab[j] = set->nodeTab[j + incr]; |
| 2678 | set->nodeTab[j + incr] = tmp; |
| 2679 | j -= incr; |
| 2680 | } else |
| 2681 | break; |
| 2682 | } |
| 2683 | } |
| 2684 | } |
| 2685 | #else /* WITH_TIM_SORT */ |
| 2686 | libxml_domnode_tim_sort(set->nodeTab, set->nodeNr); |
| 2687 | #endif /* WITH_TIM_SORT */ |
| 2688 | } |
| 2689 | |
| 2690 | #define XML_NODESET_DEFAULT 10 |
| 2691 | /** |
no test coverage detected