<commit_before>package core

import (
	"sync"

	"github.com/intelsdilabs/pulse/pkg/ctree"
)

type ConfigDataTree struct {
	cTree *ctree.ConfigTree
}

func NewConfigDataTree() *ConfigDataTree {
	return &ConfigDataTree{
		cTree: ctree.New(),
	}
}

func (c *ConfigDataTree) Add(ns []string, cdn *ConfigDataNode) {
	c.cTree.Add(ns, cdn)
}

func (c *ConfigDataTree) Get(ns []string) *ConfigDataNode {
	// Automatically freeze on first Get
	if !c.cTree.Frozen() {
		c.cTree.Freeze()
	}

	n := c.cTree.Get(ns)
	if n == nil {
		return nil
	} else {
		cd := n.(ConfigDataNode)
		return &cd
	}
}

func (c *ConfigDataTree) Freeze() {
	c.cTree.Freeze()
}

type ConfigDataNode struct {
	mutex sync.Mutex
	table map[string]ConfigValue
}

func NewConfigDataNode() *ConfigDataNode {
	return &ConfigDataNode{
		table: make(map[string]ConfigValue),
	}
}

func (c *ConfigDataNode) Table() map[string]ConfigValue {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	return c.table
}

func (c *ConfigDataNode) AddItem(k string, v ConfigValue) {
	// And empty is a noop
	if k == "" {
		return
	}
	c.mutex.Lock()
	defer c.mutex.Unlock()
	c.table[k] = v
}

func (c ConfigDataNode) Merge(n ctree.Node) ctree.Node {
	// Because Add only allows the ConfigDataNode type we
	// are safe to convert ctree.Node interface to ConfigDataNode
	cd := n.(*ConfigDataNode)
	t := cd.Table()
	// For the table in the passed ConfigDataNode(converted) add each item to
	// this ConfigDataNode overwritting where needed.
	for k, v := range t {
		c.AddItem(k, v)<commit_msg>Switched to pointer to sync.Mutex from value in ConfigDataNode (to prevent passing Locks by value elsewhere)<commit_after>package core

import (
	"sync"

	"github.com/intelsdilabs/pulse/pkg/ctree"
)

type ConfigDataTree struct {
	cTree *ctree.ConfigTree
}

func NewConfigDataTree() *ConfigDataTree {
	return &ConfigDataTree{
		cTree: ctree.New(),
	}
}

func (c *ConfigDataTree) Add(ns []string, cdn *ConfigDataNode) {
	c.cTree.Add(ns, cdn)
}

func (c *ConfigDataTree) Get(ns []string) *ConfigDataNode {
	// Automatically freeze on first Get
	if !c.cTree.Frozen() {
		c.cTree.Freeze()
	}

	n := c.cTree.Get(ns)
	if n == nil {
		return nil
	} else {
		cd := n.(ConfigDataNode)
		return &cd
	}
}

func (c *ConfigDataTree) Freeze() {
	c.cTree.Freeze()
}

type ConfigDataNode struct {
	mutex *sync.Mutex
	table map[string]ConfigValue
}

func NewConfigDataNode() *ConfigDataNode {
	return &ConfigDataNode{
		mutex: new(sync.Mutex),
		table: make(map[string]ConfigValue),
	}
}

func (c *ConfigDataNode) Table() map[string]ConfigValue {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	return c.table
}

func (c *ConfigDataNode) AddItem(k string, v ConfigValue) {
	// And empty is a noop
	if k == "" {
		return
	}
	c.mutex.Lock()
	defer c.mutex.Unlock()
	c.table[k] = v
}

func (c ConfigDataNode) Merge(n ctree.Node) ctree.Node {
	// Because Add only allows the ConfigDataNode type we
	// are safe to convert ctree.Node interface to ConfigDataNode
	cd := n.(*ConfigDataNode)
	t := cd.Table()
	// For the table in the passed ConfigDataNode(converted) add each item to
	// this ConfigDataNode overwritting where needed.
	for k, v := range t {
		c.AddItem(k, v)
{'fraction_non_alphanumeric': 0.1306135357368754, 'fraction_numerical': 0.0, 'mean_word_length': 3.9732704402515724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7267876', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1182, 'n_words': 316}