From 679063958752a96a8c63b983ea1ecf3a9074d4de Mon Sep 17 00:00:00 2001 From: Luca Padovani Date: Mon, 8 Nov 2004 22:07:09 +0000 Subject: [PATCH] * added a few calculations --- helm/papers/use_case/stats/stats.cc | 33 +++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/helm/papers/use_case/stats/stats.cc b/helm/papers/use_case/stats/stats.cc index 9892e12b6..85ef8ba06 100644 --- a/helm/papers/use_case/stats/stats.cc +++ b/helm/papers/use_case/stats/stats.cc @@ -1,4 +1,5 @@ +#include #include #include @@ -12,6 +13,8 @@ unsigned n_attributes; unsigned max_attributes; unsigned max_depth; unsigned max_children; +std::vector depths; +std::vector widths; bool is_blank(const std::string& s) @@ -54,13 +57,33 @@ visit(DOM::Node node, unsigned depth) n_children++; } max_children = std::max(max_children, n_children); + + if (!node.get_firstChild()) + depths.push_back(depth); + else + widths.push_back(n_children); } void print_results(const std::string& URI) { + unsigned tot_depth = 0; + for (std::vector::const_iterator p = depths.begin(); p != depths.end(); p++) + tot_depth += *p; + + unsigned tot_width = 0; + for (std::vector::const_iterator p = widths.begin(); p != widths.end(); p++) + tot_width += *p; + std::cout << "" << std::endl; - std::cout << " " << max_depth << "" << std::endl; + std::cout << " " << std::endl; + std::cout << " " << max_depth << "" << std::endl; + std::cout << " " << tot_depth / ((double) depths.size()) << "" << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << max_children << "" << std::endl; + std::cout << " " << tot_width / ((double) widths.size()) << "" << std::endl; + std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " " << n_elements << "" << std::endl; std::cout << " " << n_leaf_elements << "" << std::endl; @@ -73,15 +96,17 @@ print_results(const std::string& URI) std::cout << " " << n_attributes << "" << std::endl; std::cout << " " << max_attributes << "" << std::endl; std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << max_children << "" << std::endl; - std::cout << " " << std::endl; std::cout << "" << std::endl; } int main(int argc, char* argv[]) { + if (argc != 2) { + std::cerr << "Usage: stats " << std::endl; + return -1; + } + DOM::DOMImplementation di; DOM::Document doc = di.createDocumentFromURI(argv[1]); visit(doc, 0); -- 2.39.2