diff options
| author | steven-vd <steven@vandorp.lu> | 2026-08-16 15:00:32 +0200 |
|---|---|---|
| committer | steven-vd <steven@vandorp.lu> | 2026-08-17 09:31:42 +0200 |
| commit | ee081ca70322cd01d0642fdb1860e6bfbfb48e85 (patch) | |
| tree | 295fdba93b08b24562c6d49e971bbf3425eac50c /benchmarks/pugixml/count_highway_crossings.cpp | |
Diffstat (limited to 'benchmarks/pugixml/count_highway_crossings.cpp')
| -rw-r--r-- | benchmarks/pugixml/count_highway_crossings.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/benchmarks/pugixml/count_highway_crossings.cpp b/benchmarks/pugixml/count_highway_crossings.cpp new file mode 100644 index 0000000..76a4bd0 --- /dev/null +++ b/benchmarks/pugixml/count_highway_crossings.cpp @@ -0,0 +1,54 @@ +#include "pugixml.hpp" +#include <cstddef> +#include <cstring> + +// Returns true and increments count if `tag_node`'s first two attributes +// are (value) "highway" then "crossing", matching the original's +// position-based (not name-based) attribute check. +inline bool is_highway_crossing(pugi::xml_node tag_node) { + pugi::xml_attribute k = tag_node.first_attribute(); + if (!k) return false; + + pugi::xml_attribute v = k.next_attribute(); + if (!v) return false; + + return std::strcmp(k.value(), "highway") == 0 && + std::strcmp(v.value(), "crossing") == 0; +} + +size_t count_highway_crossings (char* buffer, size_t len) { + pugi::xml_document doc; + pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, len, pugi::parse_minimal); + if (!result) return 0; + //if (!result) { + // fprintf(stderr, "pugixml error: %s at offset %td\n", result.description(), result.offset); + //} + + size_t count = 0; + + for (pugi::xml_node node : doc.child("osm").children("node")) { + for (pugi::xml_node tag : node.children("tag")) { + if (is_highway_crossing(tag)) ++count; + } + } + + return count; +} + +size_t count_highway_crossings_cheat_and_early_out (char* buffer, size_t len) { + pugi::xml_document doc; + pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, len, pugi::parse_minimal); + if (!result) return 0; + + size_t count = 0; + + for (pugi::xml_node top : doc.child("osm").children()) { + if (std::strcmp(top.name(), "way") == 0) break; + + for (pugi::xml_node tag : top.children("tag")) { + if (is_highway_crossing(tag)) ++count; + } + } + + return count; +} |
