<commit_before>package resolver

import (
	"github.com/Hranoprovod/shared"
)

// Resolver contains the resolver data
type Resolver struct {
	db       *shared.NodeList
	maxDepth int
}

// NewResolver creates new resolver
func NewResolver(db *shared.NodeList, maxDepth int) *Resolver {
	return &Resolver{db, maxDepth}
}

func (r *Resolver) Resolve() {
	for name := range *r.db {
		r.resolveNode(name, 0)
	}
}

func (r *Resolver) resolveNode(name string, level int) {
	if level >= r.maxDepth {
		return
	}

	node, exists := (*r.db)[name]
	if !exists {
		return
	}

	nel := shared.NewElements()

	for _, e := range *node.Elements {
		r.resolveNode(e.Name, level+1)
		snode, exists := (*r.db)[e.Name]
		if exists {
			nel.SumMerge(snode.Elements, e.Val)
		} else {
			var tm shared.Elements
			tm.Add(e.Name, e.Val)
			nel.SumMerge(&tm, 1)
		}
	}
	nel.Sort()
	(*r.db)[name].Elements = nel
}
<commit_msg>Added comment<commit_after>package resolver

import (
	"github.com/Hranoprovod/shared"
)

// Resolver contains the resolver data
type Resolver struct {
	db       *shared.NodeList
	maxDepth int
}

// NewResolver creates new resolver
func NewResolver(db *shared.NodeList, maxDepth int) *Resolver {
	return &Resolver{db, maxDepth}
}

// Resolve resolves the current database
func (r *Resolver) Resolve() {
	for name := range *r.db {
		r.resolveNode(name, 0)
	}
}

func (r *Resolver) resolveNode(name string, level int) {
	if level >= r.maxDepth {
		return
	}

	node, exists := (*r.db)[name]
	if !exists {
		return
	}

	nel := shared.NewElements()

	for _, e := range *node.Elements {
		r.resolveNode(e.Name, level+1)
		snode, exists := (*r.db)[e.Name]
		if exists {
			nel.SumMerge(snode.Elements, e.Val)
		} else {
			var tm shared.Elements
			tm.Add(e.Name, e.Val)
			nel.SumMerge(&tm, 1)
		}
	}
	nel.Sort()
	(*r.db)[name].Elements = nel
}

{'fraction_non_alphanumeric': 0.14589003810560697, 'fraction_numerical': 0.00326619488296135, 'mean_word_length': 3.4396135265700485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5950009', 'n_tokens_mistral': 733, 'n_tokens_neox': 692, 'n_words': 170}