/usr/include/sdsl/structure_tree.hpp is in libsdsl-dev 2.0.3-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | /*!\file structure_tree.hpp
\brief structure_tree.hpp contains a helper class which can represent the memory structure of a class.
\author Simon Gog
*/
#ifndef INCLUDED_SDSL_STRUCTURE_TREE
#define INCLUDED_SDSL_STRUCTURE_TREE
#include "uintx_t.hpp"
#include <unordered_map>
#include <string>
#include <iostream>
#include <sstream>
#include <memory>
#include "config.hpp"
//! Namespace for the succinct data structure library
namespace sdsl
{
class structure_tree_node
{
private:
using map_type = std::unordered_map<std::string,std::unique_ptr<structure_tree_node>>;
map_type m_children;
public:
const map_type& children = m_children;
size_t size = 0;
std::string name;
std::string type;
public:
structure_tree_node(const std::string& n, const std::string& t) : name(n) , type(t) {}
structure_tree_node* add_child(const std::string& n, const std::string& t) {
auto hash = n+t;
auto child_itr = m_children.find(hash);
if (child_itr == m_children.end()) {
// add new child as we don't have one of this type yet
structure_tree_node* new_node = new structure_tree_node(n,t);
m_children[hash] = std::unique_ptr<structure_tree_node>(new_node);
return new_node;
} else {
// child of same type and name exists
return (*child_itr).second.get();
}
}
void add_size(size_t s) { size += s; }
};
class structure_tree
{
public:
static structure_tree_node* add_child(structure_tree_node* v, const std::string& name, const std::string& type) {
if (v) return v->add_child(name,type);
return nullptr;
};
static void add_size(structure_tree_node* v, uint64_t value) {
if (v) v->add_size(value);
};
};
template<format_type F>
void write_structure_tree(const structure_tree_node* v, std::ostream& out, size_t level = 0);
}
#endif
|