MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlXPathDistinctSorted

Function xmlXPathDistinctSorted

ThirdParty/libxml2/vtklibxml2/xpath.c:3586–3623  ·  view source on GitHub ↗

* xmlXPathDistinctSorted: * @nodes: a node-set, sorted by document order * * Implements the EXSLT - Sets distinct() function: * node-set set:distinct (node-set) * * Returns a subset of the nodes contained in @nodes, or @nodes if * it is empty */

Source from the content-addressed store, hash-verified

3584 * it is empty
3585 */
3586xmlNodeSetPtr
3587xmlXPathDistinctSorted (xmlNodeSetPtr nodes) {
3588 xmlNodeSetPtr ret;
3589 xmlHashTablePtr hash;
3590 int i, l;
3591 xmlChar * strval;
3592 xmlNodePtr cur;
3593
3594 if (xmlXPathNodeSetIsEmpty(nodes))
3595 return(nodes);
3596
3597 ret = xmlXPathNodeSetCreate(NULL);
3598 if (ret == NULL)
3599 return(ret);
3600 l = xmlXPathNodeSetGetLength(nodes);
3601 hash = xmlHashCreate (l);
3602 for (i = 0; i < l; i++) {
3603 cur = xmlXPathNodeSetItem(nodes, i);
3604 strval = xmlXPathCastNodeToString(cur);
3605 if (xmlHashLookup(hash, strval) == NULL) {
3606 if (xmlHashAddEntry(hash, strval, strval) < 0) {
3607 xmlFree(strval);
3608 goto error;
3609 }
3610 if (xmlXPathNodeSetAddUnique(ret, cur) < 0)
3611 goto error;
3612 } else {
3613 xmlFree(strval);
3614 }
3615 }
3616 xmlHashFree(hash, xmlHashDefaultDeallocator);
3617 return(ret);
3618
3619error:
3620 xmlHashFree(hash, xmlHashDefaultDeallocator);
3621 xmlXPathFreeNodeSet(ret);
3622 return(NULL);
3623}
3624
3625/**
3626 * xmlXPathDistinct:

Callers 1

xmlXPathDistinctFunction · 0.85

Calls 8

xmlXPathNodeSetCreateFunction · 0.85
xmlHashCreateFunction · 0.85
xmlXPathCastNodeToStringFunction · 0.85
xmlHashLookupFunction · 0.85
xmlHashAddEntryFunction · 0.85
xmlXPathNodeSetAddUniqueFunction · 0.85
xmlHashFreeFunction · 0.85
xmlXPathFreeNodeSetFunction · 0.85

Tested by

no test coverage detected