source: src/Common/Stats/Base.h @ 675716e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 675716e was 675716e, checked in by tdelisle <tdelisle@…>, 5 years ago

Instrumented PassVisitor? to print average/max depth

  • Property mode set to 100644
File size: 1.6 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Heap.h --
8//
9// Author           : Thierry Delisle
10// Created On       : Fri Mar 03 14:53:53 2019
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#pragma once
17
18#include <string>
19
20namespace Stats {
21        namespace Base {
22                class TreeImpl {
23                public:
24                        struct Top {
25                                TreeImpl * head = nullptr;
26                                TreeImpl * tail = nullptr;
27
28                                void append(TreeImpl * node) {
29                                        if(!head) { head = node; }
30                                        else      { tail->next = node;}
31                                        tail = node;
32                                }
33                        };
34
35                        virtual void print(std::ostream &) = 0;
36
37                        const std::string name;
38                        TreeImpl(const std::string & name) : name(name) {}
39
40                protected:
41                        virtual ~TreeImpl() = default;
42
43                        TreeImpl * next = nullptr;
44                        Top children;
45
46                        template<typename func_t>
47                        friend void ForAll(TreeImpl::Top & range, size_t level, func_t func, bool destroy = false);
48                };
49
50                template<typename func_t>
51                inline void ForAll(TreeImpl::Top & range, size_t level, func_t func, bool destroy) {
52                        auto it = range.head;
53                        while(it) {
54                                auto next = it->next;
55                                func(it, level);
56                                ForAll(it->children, level + 1, func);
57                                if(destroy) delete it;
58                                it = next;
59                        }
60                }
61
62                template<TreeImpl::Top & top>
63                class Tree : public TreeImpl {
64                public:
65                        Tree(const std::string & name) : TreeImpl{name} {
66                                top.append(this);
67                        }
68
69                        Tree(const std::string & name, Tree * parent) : TreeImpl{name} {
70                                parent->children.append(this);
71                        }
72                protected:
73                        virtual ~Tree() = default;
74                };
75        }
76}
Note: See TracBrowser for help on using the repository browser.